Lab 4

int i=0;
int j=1;
float rot = 0;

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

void draw() {
background(50, 0, 120);
frameRate(100);

point(i, i);
pushMatrix();
translate(i, i);
rotate(rot);
line(30, 20, 85, 65);
line(85, 65, 30, 110);
line(30, 20, 55, 65);
line(55, 65, 30, 110);
popMatrix();
i+=j;
if (i >=500) {
j*=-1;
}
if (i<=0) {
j*=-1;
}

pushMatrix();
rotate(rot*5);
rot += 0.1;
popMatrix();
}

lab4

I use the lines to draw the boomerang and the order”if” to let it spin within the screen. I try to fill color in it, but it did not work. And actually, I want the boomerang to spin itself, but I failed.

Leave a Reply