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))); }
Hi all, new to processing but having great fun trying out a few basic building blocks on my fist project.
the area I'm stuck with and would appreciate some pointers is I've created the following code to generate 4 colors, then assign a random color to draw 4 blobs. The code is working as I expected but I want to use each of the colors ONLY ONCE hence to have all 4 colors in a different pattern.
I suspect I need to use 'if' or 'while' to test if the first 2 are the same then if the 3rd is same as 1 or 2 etc. I've tried this to no avail so any pointer are welcome.
color cr=color(255,0,0); //defines RED
color cg=color(0,255,0); //defines GREEN
color cb=color(0,0,255); //defines BLUE
color cy=color(255,255,0); //defines YELLOW
color[] colors = { //random selects one of above colors
cr,cg,cb,cy
};
color c1=(colors[int(random(0,4))]); //assigns a random color from above to c1-4
color c2=(colors[int(random(0,4))]);
color c3=(colors[int(random(0,4))]);
color c4=(colors[int(random(0,4))]);
void setup() {
size (420,100); //screen size
}
void draw() { //draws 4 ellipses with colors above
fill (c1);
ellipse (60,height/2,80,80);
fill (c2);
ellipse (160,height/2,80,80);
fill (c3);
ellipse (260,height/2,80,80);
fill (c4);
ellipse (360,height/2,80,80);
}