how to make only *one* image rotate?

edited March 2017 in Questions about Code

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: calendar1 calendar2

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() {
size(750, 500);
bg = loadImage("bg1.png");
wheel = loadImage("colorwheel.png");
void draw() {
a = (a+1);
image(bg, 375, 250);
void wheel(int xloc, int yloc, int angle){
image(wheel, xloc, yloc);

Thank you!


  • Answer ✓

    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!


  • edited March 2017

    As for the mouse:

    Instead of mousePressed as a variable use the function mousePressed() of the same name - it registers the click only once, not multiple times (as the variable mousePresseddoes).

    In this function set a boolean imageRotates (that you define before setup()) to its opposite:

    imageRotates= ! imageRotates;

    The ! means a logical NOT.

    before rotate say

    if(imageRotates) { 

    Chrisir ;-)

  • Awesome! I didn't know that. Thanks for your help

Sign In or Register to comment.