Mouse pressed commands
in
Programming Questions
•
1 year ago
There are a few things I am trying to do... First, how can I make it so the mouse/cursor HAS TO BE located in the center of the canvas for the mousePressed commands to happen? So, in other words, not just any click works to switch the images I have loaded, but the mouse has to be in a particular spot (in this case the center of the canvas) for it to work. Second, how would I make it so when the mouse is clicked a random image is shown, as opposed to always showing up in the order I have them being loaded. Third, in addition to having the mouse being clicked and the image changing, would I be able to also have a command that is when the mouse is pressed and held down the images automatically scroll and when the mouse is released it stops scrolling. So essentially there would be the option to click once and the image changes or if the mouse is held down the images scroll (when I say scroll, I mean goes to the next image and the next image and the next image automatically, instead of doing it through individual clicks).
Sorry for the multiple questions.
Here is my code of what I have so far:
int toggle=0;
int numImages=74;
PImage[] myImages=new PImage[numImages];
void setup() {
size (800, 500);
background(0);
imageMode(CENTER);
myImages[0]= loadImage ("+1.jpg");
myImages[1]= loadImage ("About.jpg");
myImages[2]= loadImage ("AddPhoto.jpg");
myImages[3]= loadImage ("AddToCart.jpg");
myImages[4]= loadImage ("AddtoCircles.jpg");
myImages[5]= loadImage ("AmazonMenu.jpg");
myImages[6]= loadImage ("AppleMenu.jpg");
myImages[7]= loadImage ("AskQuestion.jpg");
myImages[8]= loadImage ("BuyNow.jpg");
myImages[9]= loadImage ("Cancel.jpg");
myImages[10]= loadImage ("Cart.jpg");
myImages[11]= loadImage ("Categories.jpg");
myImages[12]= loadImage ("Comedy.jpg");
myImages[13]= loadImage ("Comment.jpg");
myImages[14]= loadImage ("Compose.jpg");
myImages[15]= loadImage ("Delete.jpg");
myImages[16]= loadImage ("EditProfile_2.jpg");
myImages[17]= loadImage ("EditProfile.jpg");
myImages[18]= loadImage ("Entertainment.jpg");
myImages[19]= loadImage ("FBMenu.jpg");
myImages[20]= loadImage ("Film&Ani.jpg");
myImages[21]= loadImage ("FindUsOnFB.jpg");
myImages[22]= loadImage ("Follow.jpg");
myImages[23]= loadImage ("Friends.jpg");
myImages[24]= loadImage ("Gaming.jpg");
myImages[25]= loadImage ("GetDirection.jpg");
myImages[26]= loadImage ("Google+Nav.jpg");
myImages[27]= loadImage ("Help.jpg");
myImages[28]= loadImage ("ImOver18.jpg");
myImages[29]= loadImage ("Info.jpg");
myImages[30]= loadImage ("Insert.jpg");
myImages[31]= loadImage ("InviteFriends.jpg");
myImages[32]= loadImage ("JoinDecline.jpg");
myImages[33]= loadImage ("LearnMore.jpg");
myImages[34]= loadImage ("Like.jpg");
myImages[35]= loadImage ("Login_2.jpg");
myImages[36]= loadImage ("Login.jpg");
myImages[37]= loadImage ("Message.jpg");
myImages[38]= loadImage ("MostViewToday.jpg");
myImages[39]= loadImage ("MyPlaces.jpg");
myImages[40]= loadImage ("Navigation.jpg");
myImages[41]= loadImage ("NewFolder.jpg");
myImages[42]= loadImage ("NewOpen.jpg");
myImages[43]= loadImage ("Nonprofits&Act.jpg");
myImages[44]= loadImage ("Okay.jpg");
myImages[45]= loadImage ("Open.jpg");
myImages[46]= loadImage ("People&Blogs.jpg");
myImages[47]= loadImage ("Person.jpg");
myImages[48]= loadImage ("Pets&Animals.jpg");
myImages[49]= loadImage ("Photos.jpg");
myImages[50]= loadImage ("Print.jpg");
myImages[51]= loadImage ("RecommendedTopics.jpg");
myImages[52]= loadImage ("RecordFromWebcam.jpg");
myImages[53]= loadImage ("Save.jpg");
myImages[54]= loadImage ("Science&Tech.jpg");
myImages[55]= loadImage ("Search.jpg");
myImages[56]= loadImage ("SendMessage.jpg");
myImages[57]= loadImage ("Settings.jpg");
myImages[58]= loadImage ("ShowNow.jpg");
myImages[59]= loadImage ("SignUp.jpg");
myImages[60]= loadImage ("Sports.jpg");
myImages[61]= loadImage ("StartaHangout.jpg");
myImages[62]= loadImage ("StartPosting.jpg");
myImages[63]= loadImage ("Travel&Events.jpg");
myImages[64]= loadImage ("TwitterMenu.jpg");
myImages[65]= loadImage ("Unfollow.jpg");
myImages[66]= loadImage ("UpdateStatus.jpg");
myImages[67]= loadImage ("UploadPhotos.jpg");
myImages[68]= loadImage ("UploadVideo.jpg");
myImages[69]= loadImage ("ViewMenu.jpg");
myImages[70]= loadImage ("Wall.jpg");
myImages[71]= loadImage ("Window.jpg");
myImages[72]= loadImage ("WishList.jpg");
myImages[73]= loadImage ("YTMenu.jpg");
}
void draw() {
int i = toggle%74;
if (myImages[i]!=null) {
image(myImages[i], 400, 240);
} else {
println("Image" + i + "is reporting null, Double check this image exists.");
}
}
void mousePressed(){
toggle++;
}
End of code.
There is nothing wrong with this code, I would just like to add more specific mouse commands.
Thanks!!!! :)
1