
void setup()
{
size(300, 300);
noLoop();
}
void draw()
{
drawline(100, 100, 200, 200);
quadratic(5, 120, 5, 200, 220, 220);
cubic(30, 20, 80, 5, 80, 75, 30, 75);
}
void drawline(int x0, int y0, int x1, int y1)
{
float xB, yB;
for(float t = 0; t < 1; t += .001) {
xB = (1 - t) * x0 + t * x1;
yB = (1 - t) * y0 + t * y1;
point(xB, yB);
}
}
void quadratic(int x0, int y0, int x1, int y1, int x2, int y2)
{
float xB, yB;
for(float t = 0; t < 1; t += .001) {
xB = (1 - t) * (1 - t) * x0 + 2 * (1 - t) * t * x1 + t * t * x2;
yB = (1 - t) * (1 - t) * y0 + 2 * (1 - t) * t * y1 + t * t * y2;
point(xB, yB);
}
}
void cubic(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3)
{
float xB, yB;
for(float t = 0; t < 1; t += .001) {
xB = (1-t)*(1-t)*(1-t)*x0 + 3 *(1-t)*(1-t)*t*x1 + 3*(1-t)*t*t*x2 + t*t*t*x3;
yB = (1-t)*(1-t)*(1-t)*y0 + 3 *(1-t)*(1-t)*t*y1 + 3*(1-t)*t*t*y2 + t*t*t*y3;
point(xB, yB);
}
}
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment