
For the first part of HW 3, we were to draw some cubic bezier curves based on where the mouse is clicked on the screen. The next part involved drawing triangles with a function that accepts 3 (x,y) coordinates, my myTri method. Each time the letter r is pressed, random triangles are drawn with this method. The last part randomly chooses coordinates to draw 5 different triangles placed at random in my window, which happens when the letter t is pressed. Here is my source code:
int pointclicks;
int x1, x2, x3, x4, y1, y2, y3, y4;
int xMax = 720;
int yMax = 480;
void setup() {
size(720, 480);
background(0);
}
void draw() {
stroke(random(0, 255), random(0, 255), random(0, 255));
noFill();
}
void keyPressed() {
if(key == 't') {
triangle(random(xMax), random(yMax), random(xMax), random(yMax), random(xMax), random(yMax));
}
if(key == 'r') {
myTri();
}
}
void mousePressed() {
if(pointclicks == 0) {
x1 = mouseX;
y1 = mouseY;
point(x1, y1);
pointclicks = 1;
}
else if (pointclicks == 1) {
x2 = mouseX;
y2 = mouseY;
pointclicks = 2;
}
else if (pointclicks == 2) {
x3 = mouseX;
y3 = mouseY;
pointclicks = 3;
}
else if (pointclicks == 3) {
x4 = mouseX;
y4 = mouseY;
point(x4, y4);
bezier(x1, y1, x2, y3, x3, y3, x4, y4);
pointclicks = 0;
}
}
void myTri(){
float a = random(xMax);
float b = random(xMax);
float c = random(xMax);
float d = random(yMax);
float e = random(yMax);
float f = random(yMax);
line(a,d,b,e);
line(b,e,c,f);
line(c,f,a,d);
}

Nice Blog Evendo I Dont Understand The Code.. Hahaha
ReplyDeleteMy Blog:
NasirNanyan.Blogspot.Com