let angle=60;
let b=[];
let x,y,t;
let val,v2
function setup(){
createCanvas(600,600);
angleMode(DEGREES);
}
function draw(){
if (mouseX>width){
x=width
}else if(mouseX<0){
x=0.01
}else{
x=mouseX
}
val = 0.75
if (mouseY>height){
y=mouseY
}else if(mouseX<0){
y=0.01
}else{
y=mouseY
}
v2=map(x,0,width,2,100)
background(255,255,255,150);
t=frameCount/4
translate(width/2,height/2+50);
rotate(-30)
stroke(100);
strokeWeight(2);
fractal(60,-1);
}
function fractal(len,refl) {
strokeWeight(1-val)
tmp = len*refl
stroke(255, 153, 0,100)
fill(247, 210, 22,150)
push()
polygon(0,0,len,3)
pop()
push()
if (len > v2) {
push();
translate(1.5*len, 0);
rotate(angle);
fractal(len * val,refl)
pop();
push();
rotate(-angle*2)
translate(1.5*len, 0);
rotate(angle)
fractal(len * val,refl)
pop();
}
pop()
}
function polygon(x, y, radius, npoints) {
let angle = 360 / npoints;
beginShape();
for (let a = 0; a < 360; a += angle) {
let sx = x + cos(a) * radius;
let sy = y + sin(a) * radius;
vertex(sx, sy);
}
endShape(CLOSE);
}