Sunday, February 15, 2009
triangle
ZG
int width = 200;
int height = 200;
float[][] rotateMatrix = new float[2][2];
void setup()
{
size (width,height);
noLoop();
}
void draw()
{
int x0, y0, x1, y1, x2, y2;
x0 = int(random(width));
y0 = int(random(height));
x1 = int(random(width));
y1 = int(random(height));
x2 = int(random(width));
y2 = int(random(height));
for (float i =0; i <>
{
float rotateAngle = i * PI;
rotation(x0, y0, x1, y1, x2, y2, rotateAngle);
}
}
void rotation(int x0, int y0, int x1, int y1, int x2, int y2, float rotateAngle)
{
buildMatrix(rotateAngle);
float[][] trianglePoints = {{x0, y0}, {x1, y1}, {x2, y2}};
triangle(trianglePoints[0][0],trianglePoints[0][1],trianglePoints[1][0],trianglePoints[1][1],trianglePoints[2][0],trianglePoints[2][1]);
trianglePoints = multiply(trianglePoints, rotateMatrix);
triangle(trianglePoints[0][0],trianglePoints[0][1],trianglePoints[1][0],trianglePoints[1][1],trianglePoints[2][0],trianglePoints[2][1]);
}
float[][] multiply(float[][]a, float[][]b)
{
float[][]c = new float[a.length][b[0].length];
for (int i = 0; i <>
for (int j = 0; j <>
for (int k = 0; k <>
c[i][j] += a[i][k] * b[k][j];
}
}
}
return c;
}
void buildMatrix(float rotateAngle)
{
rotateMatrix[0][0] = cos(rotateAngle);
rotateMatrix[0][1] = sin(rotateAngle);
rotateMatrix[1][0] = -sin(rotateAngle);
rotateMatrix[1][1] = cos(rotateAngle);
}
Friday, February 6, 2009
Project
I have not really though about what kind of project that i want to do. The things that I saw that I though might be cool were the spiky-ball-craziness thing from the processing side. I would like to try to do something in node box since I now have a Mac.
Sunday, February 1, 2009
Cubic Click
int x0, y0, x1, y1, x2, y2, x3, y3;
int count = 0;
void setup()
{
size(400,400);
}
void draw()
{
}
void mousePressed()
{
if (count == 0)
{
x0 = mouseX;
y0 = mouseY;
point(x0, y0);
count++;
}
else if (count == 1)
{
x1= mouseX;
y1 = mouseY;
count++;
}
else if (count == 2)
{
x2 = mouseX;
y2 = mouseY;
count++;
}
else
{
x3 = mouseX;
y3 = mouseY;
CubicCurv(x0, y0, x1, y1, x2, y2, x3, y3);
count = 0;
}
}
void CubicCurv(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3)
{
float x, y;
for(float t = 0 ; t <>
{
x= (1-t)*(1-t)*(1-t)*x0 + 3 *(1-t)*(1-t)*t*x1+ 3*(1-t)*(1-t)*t*t*x2 + t*t*t*x3;
y= (1-t)*(1-t)*(1-t)*y0 + 3 *(1-t)*(1-t)*t*y1+ 3*(1-t)*(1-t)*t*t*y2 + t*t*t*y3;
point(x,y);
}
}
5 triangles
void setup()
{
size(500,500);
noLoop();
}
void draw()
{
for (int i = 0 ; i<>
{
drawTriangle(int(random(500)), int(random(500)), int(random(500)), int(random(500)), int(random(500)), int(random(500)));
}
}
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);
}
Subscribe to:
Posts (Atom)