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 & HelpSyntax Questions › moving a triangle
Page Index Toggle Pages: 1
moving a triangle (Read 691 times)
moving a triangle
Jul 27th, 2009, 3:55am
 
hi
i am new in processing but i have done some simple things with flash as2.
i found a tut on processing.org/learning which moves a rectangle from the left to the right. if i want to move a triangle or another complex form - how can i do it? i tried it with a triangle but it morphes the form. i want to move the form. maybe i think wrong. i figure that i need an  instance of a triangle which i can move seperate (somhow like in flash?). can anybody help me?
cheers goldfish

here is the simple script with the rectangle

color c = color(0);
float x = 0;
float y = 100;
float speed = 1;

void setup() {
 size(200,200);
}

void draw() {
 background(255);
 move();
 display();
}

void move() {
 x = x + speed;
 if (x > width) {
   x = 0;
 }
}

void display() {
 fill(c);
 rect(x,y,30,10);
}
Re: moving a triangle
Reply #1 - Jul 27th, 2009, 5:40am
 
you can use translate();

to move objects too

Code:

float x = 0;
float y = 100;
float speed = 1;

void setup() {
size(200,200);
}

void draw() {
background(255);
fill(100);
x = x + speed;
translate( x,0);
triangle(30, 75, 58, 20, 86, 75);
if (x > width)   x = -40;
}


if you have more objects you have to use push and popMatrix(); though
Re: moving a triangle
Reply #2 - Jul 27th, 2009, 9:39am
 
hey thanks for your script. in case of moving the triangle it works perfect. but if i take the example mirror2 from daniel shiffman (to find in examples/video capture/mirror2) and i want to replace the function rect with triangle, then it doesn't work. what can i do in this case?
thanks goldfish
Page Index Toggle Pages: 1