Help with making mouse rollover work
in
Programming Questions
•
8 months ago
I have been struggling with this code for weeks now. Please take the time to go through my code and tell me how I can make the function display the tweet when the mouse hovers over it. So far, I have only gotten it to display only the last tweet. I think this is because the x and y values a plotted randomly and keep changing with each pass. I will want to be able to hover over all the plotted shapes and display their respective tweets. I have received help from some people in this forum, about cleaning up the code and making it better, but the fundamental issue remains unresolved. I'm running out of time! Thanks in advance.
- boolean rollover = false;
- boolean wrd = false;
- boolean wrd2 = false;
- String msg;
- ArrayList message;
- float x;
- float y;
- float d;
- float radius;
- GeoLocation loc;
- double lo;
- double la;
- float castLat;
- float castLon;
- boolean retweet;
- public boolean ss;
- User user;
- long follow;
- String city;
- String lang;
- String tz;
- long rtCount;
- String reply;
- String keywords[] = {"food"};
- String keyword1 = "sandwich";
- String keyword2 = "burgers";
- Ball myBall;
- void setup() {
- //frameRate(1);
- PFont font = loadFont ("HelveticaNeue-48.vlw");
- textFont(font, 20);
- background(#0A4A4F);
- size(1280, 720);
- noStroke();
- smooth();
- connectTwitter();
- twitter.addListener(listener);
- if (keywords.length==0) twitter.sample();
- else twitter.filter(new FilterQuery().track(keywords));
- }
- void draw() {
- myBall = new Ball(random(width), random(height - 200));
- myBall.run();
- }
- class Ball {
- float x = 0;
- float y = 0;
- float d;
- Ball(float _x, float _y) {
- x = _x;
- y = _y;
- }
- void run() {
- tweet();
- }
- void move() {
- x += 10;
- y += 10;
- }
- void tweet() {
- if (wrd) {
- fill(#E5E539, 70);
- ellipse(x, y, radius, radius);
- noStroke();
- d = dist(x, y, mouseX, mouseY);
- if (d < radius + 2) { // mouseover function
- fill(#1C1C1C);
- rect(0, height - 200, width, 200);
- fill(230);
- textSize(16);
- text(msg, 50, height - 160);
- }
- }
- if (wrd2) {
- fill(#F26453, 70);
- ellipse(x, y, radius, radius);
- noStroke();
- d = dist(x, y, mouseX, mouseY);
- if (d < radius + 2) { // mouseover function
- fill(#1C1C1C);
- rect(0, height - 200, width, 200);
- fill(230);
- textSize(16);
- text(msg, 50, height - 160);
- }
- }
- wrd = false;
- wrd2 = false;
- }
- }
- static String OAuthConsumerKey = "";
- static String OAuthConsumerSecret = "";
- static String AccessToken = "";
- static String AccessTokenSecret = "";
- TwitterStream twitter = new TwitterStreamFactory().getInstance();
- void connectTwitter() {
- twitter.setOAuthConsumer(OAuthConsumerKey, OAuthConsumerSecret);
- AccessToken accessToken = loadAccessToken();
- twitter.setOAuthAccessToken(accessToken);
- }
- private static AccessToken loadAccessToken() {
- return new AccessToken(AccessToken, AccessTokenSecret);
- }
- StatusListener listener = new StatusListener() {
- public void onStatus(Status status) {
- try {
- message = new ArrayList();
- message.add(msg);
- loc = status.getGeoLocation();
- la = (float) loc.getLatitude();
- lo = (float) loc.getLongitude();
- castLat = map((int)la, -90, 90, 0, 500);
- castLon = map((int)la, -180, 180, 0, width);
- retweet = status.isRetweet();
- follow = user.getFollowersCount();
- city = user.getLocation();
- } catch(Exception e) {}
- try {
- radius = map(status.getUser().getFollowersCount(), 0, 10000, 5, 30);
- user = status.getUser();
- lang = user.getLang();
- tz = user.getTimeZone();
- rtCount = status.getRetweetCount();
- reply = status.getInReplyToScreenName();
- ss = status.isFavorited();
- msg = trim(status.getText());
- for (int i = 0; i < message.size(); i++) {
- if (match(msg, keyword1) != null) {
- if (match(tz, "US") != null) {
- wrd = true;
- }
- }
- if (match(msg, keyword2) != null) {
- if (match(tz, "US") != null) {
- wrd2 = true;
- }
- }
- }
- } catch(Exception e){
- }
- }
- public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
- }
- public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
- }
- public void onScrubGeo(long userId, long upToStatusId) {
- System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
- }
- public void onException(Exception ex) {
- ex.printStackTrace();
- }
- };
1