We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey there! I'm writing some pretty simple code as the basis for a small interactive game. So far I'm just working on getting the background to function properly. What I am trying to do is have the "wheel" image (the color wheel) rotate every time the mouse is clicked. HOWEVER the way it is written right now the wheel does not rotate at all, and instead the "bg" image above it, which I want to remain static, is the one the rotates. Here are some pictures of what that looks like, with questions and code below:
So I have a few questions:
1) How do I write it so that the wheel image is the one that rotates?
2) Why does the bg image that is incorrectly rotating rotating from the (0,0) position instead of the center, when I specified imageMode(CENTER)?
3) How would you recommend making the image rotate once per click, instead of whenever the mouse is pressed?
Here's my code:
PImage bg;
PImage wheel;
float x = width;
float y = height;
int a = 0;
void setup() {
background(255);
size(750, 500);
imageMode(CENTER);
bg = loadImage("bg1.png");
wheel = loadImage("colorwheel.png");
}
void draw() {
background(255);
if(mousePressed){
a = (a+1);
}
wheel(750,0,a);
image(bg, 375, 250);
}
void wheel(int xloc, int yloc, int angle){
image(wheel, xloc, yloc);
rotate(angle);
}
Thank you!
Answers
You can isolate rotations by using pushMatrix and popMatrix enclosing the section
Also, rotate must take place before you draw the shape , before image
Perfect! Thank you! I completely forgot about push and pop. It's been great brushing up on everything again
Glad to hear!
;-)
As for the mouse:
Instead of
mousePressed
as a variable use the functionmousePressed()
of the same name - it registers the click only once, not multiple times (as the variablemousePressed
does).In this function set a boolean
imageRotates
(that you define beforesetup()
) to its opposite:The
!
means a logical NOT.before rotate say
Chrisir ;-)
Awesome! I didn't know that. Thanks for your help
;-)