int points;
int x0, y0, x1, y1, x2, y2, x3, y3;
void setup(){
size(400,400);
background(0);
}
void draw(){
noFill();
stroke(255,0,0);
}
void mousePressed(){
if(points == 0){
x0 = mouseX;
y0 = mouseY;
point(x0,y0);
println(x0 + "x0" + y0 + "y0");
points = 1;
}else if(points == 1){
x1 = mouseX;
y1 = mouseY;
points = 2;
}else if(points == 2){
x2 = mouseX;
y2 = mouseY;
points = 3;
}else if(points == 3){
x3 = mouseX;
y3 = mouseY;
stroke(255,0,0);
bezier(x0,y0,x1,y1,x2,y2,x3,y3);
points = 0;
}
}

I'm not able to get the applet to load onto here, so I just posted the picture itself of tons of bezier curves.
For the second part I had to create a function that accepts 3 points and draws a triangles of random size/ with random points. Here is the code and a picture for that as well:
int x0,y0,x1,y1,x2,y2;
void setup(){
size(720,480);
background(0,100,100);
}
void draw() {
noFill();
stroke(0,255,255);
}
void keyPressed(){
x0 = int(random(720));
y0 = int(random(480));
x1 = int(random(720));
y1 = int(random(480));
x2 = int(random(720));
y2 = int(random(480));
if(key == 't'){
drawTriangle(x0,y0,x1,y1,x2,y2);
}
}
void drawTriangle(int x0, int y0, int x1, int y1, int x2, int y2){
line(x0,y0,x1,y1);
line(x1,y1,x2,y2);
line(x2,y2,x0,y0);
}

Finally for the third part, I am supposed to draw a rectangle with size 360 X 240 in the center of a 720 X 480 screen with 5 random triangles drawn and clipped down to just residing in the rectangle. I've been working on this yesterday and have gotten somewhere but it isn't exactly correct. But I will post that later on this week.
My proposal will come during the Super Bowl while I'm watching it tonight...

No comments:
Post a Comment