sketch/triangle/triangle.pde

96 lines
1.5 KiB
Plaintext
Raw Permalink Normal View History

2020-03-25 05:01:04 -07:00
int numFrames = 100;
int m = 1000;
void setup(){
size(500,500,P3D);
stroke(255);
fill(255);
}
class Tri{
float x1,y1,x2,y2,x3,y3;
float theta;
}
float x1(float t){
return 0.50*width + 50*cos(TWO_PI*t);
}
float y1(float t){
return 0.5*height + 50*sin(TWO_PI*t);
}
float x2(float t){
return 0.50*width + 20*cos(2*TWO_PI*t);
}
float y2(float t){
return 0.5*height + 20*sin(2*TWO_PI*t);
}
float x3(float t) {
return 0.5*width + 120 * cos(2*TWO_PI*t);
}
float y3 (float t) {
return 0.5*height + 120 * cos(TWO_PI*t);
}
void push() {
pushMatrix();
pushStyle();
}
void pop() {
popStyle();
popMatrix();
}
int parts = 8;
int n = 20;
void drawTri(int j) {
float t = 1.0*(frameCount-1)/numFrames;
pushStyle();
strokeWeight(2);
stroke(255,100);
for(int i=0;i<=m;i++){
float tt = 1.0*i/m;
float x = lerp(x1(t),x2(t),tt);
float x2 = lerp(x2(t),x3(t),tt);
float x3 = lerp(x3(t),x1(t),tt);
float y = lerp(y1(t),y2(t),tt);
float y2 = lerp(y2(t),y3(t),tt);
float y3 = lerp(y3(t),y1(t),tt);
point(x,y);
point(x2,y2);
point(x3,y3);
}
popStyle();
}
void draw(){
float t = 1.0*(frameCount - 1)/numFrames;
background(0);
// triangle(x1(t), y1(t), x2(t), y2(t), x3(t), y3(t));
push();
translate(width/4,height/6);
for(int i=0;i<n;i++){
push();
rotate(i*TWO_PI/n);
drawTri(i);
pop();
}
pop();
if (frameCount<=numFrames){
saveFrame("fr###.png");
}
}