We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › simple picture animation part2 ^^
Page Index Toggle Pages: 1
simple picture animation part2 ^^ (Read 443 times)
simple picture animation part2 ^^
Apr 29th, 2010, 12:12pm
 
hey,
i tried another animation..
i have several shapes randomly translated to other positions when keypressed = true.
Now i want to make them stay in the place they were when i release the key... i tried it for the arcs and it worked, but i am not sure how to do it for every shape
the code ::::

int pixelSize=2;
PGraphics pg;
float tx,ty;
boolean t=false;

void setup() {
size(350, 505);
pg = createGraphics(160, 90, P2D);
//colorMode(HSB);
noSmooth();
//background(50, 100, 95);
//noLoop();
}

void draw() {
float xc = 25;
int timeDisplacement = millis()/30; //geschwindigkeit der animation oder :
//int timeDisplacement = frameCount;
float calculation1 = sin( radians(timeDisplacement * 0.61655617));
float calculation2 = sin( radians(timeDisplacement * -3.6352262));
pg.beginDraw();
pg.loadPixels();
for (int x = 0; x < pg.width; x++, xc += pixelSize)
{
float yc = 25;
float s1 = 128 + 128 * sin(radians(xc) * calculation1 );
for (int y = 0; y < pg.height; y++, yc += pixelSize)
{
float s2 = 128 + 128 * sin(radians(yc) * calculation2 );
float s3 = 128 + 128 * sin(radians((xc + yc + timeDisplacement * 5) / 2));
float s = (s1+ s2 + s3) / 3;
pg.pixels[x+y*pg.width] = color(s, 255 - s / 2.0, 255);
}
}
pg.updatePixels();
pg.endDraw();
// display the results
image(pg,0,0,width,height);
fill(150, 137, 76);
if (keyPressed == true) {
translate(random(-200, 150), random(-400, 100));
}
pushMatrix();
beginShape();
vertex(101, 382);
vertex(165, 335);
vertex(165, 458);
vertex(101, 458);
vertex(101, 382);
endShape();
noStroke();
popMatrix();
if (keyPressed == true) {
translate(random(-200, 150), random(-400, 100));
}
fill(0);
beginShape();
vertex(165, 335);
vertex(218, 368);
vertex(185, 368);
vertex(185, 382);
vertex(232, 382);
vertex(232, 405);
vertex(180, 405);
vertex(180, 427);
vertex(222, 427);
vertex(222, 458);
vertex(165, 458);
vertex(165, 335);
endShape();
if (keyPressed == true) {
translate(random(-35, 320), random(-450, 50));
}
fill(111, 112, 114);
beginShape();
vertex(28, 458);
vertex(42, 458);
vertex(42, 482);
vertex(28, 482);
vertex(28, 458);
endShape();
if (keyPressed == true) {
translate(random(-290, 60), random(-60, 400));
}
beginShape();
vertex(292, 20);
vertex(297, 20);
vertex(297, 105);
vertex(292, 105);
vertex(292, 20);
endShape();
if (keyPressed == true) {
translate(random(-290, 60), random(-60, 400));
}
fill(0);
beginShape();
vertex(292, 20);
vertex(297, 20);
vertex(297, 105);
vertex(292, 105);
vertex(292, 20);
endShape();
if (keyPressed == true) {
translate(random(-300, 50), random(-40, 460));
}
fill(150, 137, 76);
beginShape();
vertex(297, 39);
vertex(334, 39);
vertex(334, 41);
vertex(297, 41);
vertex(297, 39);
endShape();
if (keyPressed == true) {
translate(random(-300, 50), random(-60, 400));
}
fill(0);
beginShape();
vertex(297, 50);
vertex(319, 50);
vertex(319, 60);
vertex(297, 60);
vertex(297, 50);
endShape();
if (keyPressed == true) {
translate(random(-300, 50), random(-100, 400));
}
beginShape();
vertex(297, 100);
vertex(328, 100);
vertex(328, 105);
vertex(297, 105);
vertex(297, 100);
endShape();
if (keyPressed == true) {
translate(random(-130, 200), random(-310, 200));
}
fill(144, 32, 28);
beginShape();
vertex(165, 305);
vertex(100, 305);
vertex(100, 314);
vertex(165, 314);
vertex(165, 305);
endShape();
if (keyPressed == true) {
translate(random(-100, 150), random(-300, 20));
}
fill(0);
beginShape();
vertex(165, 289);
vertex(73, 289);
vertex(73, 294);
vertex(165, 294);
vertex(165, 289);
endShape();
fill(180, 122,30);
if (keyPressed == true) {
 tx=random(-160,200);
 ty=random(-170,190);
 t=true;
}

if (t) {
translate(tx, ty);
}

arc(165, 162, 150, 225, PI/2, PI*1.5); //linker halbkreis
fill(175,130,130,220);
arc(150, 213, 268, 238, 0, PI/2); //viertelkreis rechts unten
fill(170, 180, 170, 220);
arc(150, 213, 268, 238, TWO_PI-PI/2, TWO_PI);//viertelkreis rechts oben
fill(0);
ellipse(209, 162, 10, 10); //großer kreis
fill(76,78,78);
//ellipse(200, 156, 4, 4); //kleiner kreis
filter (BLUR, 1);
}

Page Index Toggle Pages: 1