Translate / Rotate Problem
in
Programming Questions
•
2 years ago
Hi All,
I think I know what my problem is but I'm not sure how to get round it! I hope that more (in number and experience) minds are better than one and you can give me some pointers.
I'm trying to put an image of a dashboard in the back ground and animate a needle on the clock to read a value. (these will eventually display values from sensors linked from the arduino board but for now I just have the values changing in processing.
I can code one clock absolutely fine but as I want multiple clock in the same window, I turned it into a function so I can call it multiple times... the strange thing is that while the first clock displays OK when called as a function, the entire second clock rotates around the centre of the first one.
I need to somehow reset the rotation centre for each subsequent instance of the clock.....
..... my code so far is below, the image I used for the background can be downloaded here. I hope someone can help.
I think I know what my problem is but I'm not sure how to get round it! I hope that more (in number and experience) minds are better than one and you can give me some pointers.
I'm trying to put an image of a dashboard in the back ground and animate a needle on the clock to read a value. (these will eventually display values from sensors linked from the arduino board but for now I just have the values changing in processing.
I can code one clock absolutely fine but as I want multiple clock in the same window, I turned it into a function so I can call it multiple times... the strange thing is that while the first clock displays OK when called as a function, the entire second clock rotates around the centre of the first one.
I need to somehow reset the rotation centre for each subsequent instance of the clock.....
..... my code so far is below, the image I used for the background can be downloaded here. I hope someone can help.
- PImage b;
int ang_min=-40;
int ang_max=220;
int angle1=ang_min;
float rad1;
boolean dir1=true;
void setup() {
size(1000,900);
}
void draw() {
if (angle1==ang_max) {
dir1=true;
}
if (angle1==ang_min) {
dir1=false;
}
if (dir1==false) {
angle1++;
}
else {
angle1=angle1-2;
}
rad1=radians(angle1);
clock(rad1,0,0);
clock(rad1,0,0);
// clock(rad1,200,600);
}
void clock(float rad, int xpos, int ypos) {
b = loadImage("clock_bg.jpg");
image(b, xpos, ypos, 600, 300);
translate((xpos+300),(ypos+(150-12)));
stroke(255,0,0);
strokeWeight(3);
rotate(rad);
line(0,0,-65,0);
stroke(0);
fill(0);
ellipse(0,0,10,10);
translate(((0-xpos)+300),((0-ypos)+(150-12)));
}
1