Published
Edited
Jan 21, 2021
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
gif2 = FileAttachment("2021-01-21T12 16 22.840Z.gif").image()
Insert cell
Insert cell
Insert cell
p5(sketch => {
let system;
var fractals = [];
sketch.setup = function() {
var canvas2 = sketch.createCanvas(1000, 700);
var frac1 = new fractal(400, 650, 0, 120, 0);
fractals.push(frac1)
}
sketch.draw = function() {

if(sketch.frameCount % 30 == 0 ){
var N = sketch.frameCount/30
var fractals2 = fractals;
var value = Math.pow(2, N-1)
fractals2.forEach( x => {x.update()})
}
if(sketch.frameCount % 250==0){ fractals = []; fractals.push(new fractal(400, 650, 0, 120, 0))}
sketch.background(225); sketch.stroke(0); sketch.strokeWeight(4);

for(var i in fractals) fractals[i].show()
}
function fractal(x, y, theta, r, color){
var endPoint = { x: x-Math.sin(theta)*r, y: y-Math.cos(theta)*r}
if (r<12){
this.show = function() {
sketch.fill(color)
sketch.stroke(color)
sketch.line(x, y, endPoint.x, endPoint.y)
}
this.update = function(){}
} else {
this.show = function() {
sketch.fill(color)
sketch.stroke(color)
sketch.line(x, y, endPoint.x, endPoint.y)
}
this.update = function(){
console.log("update")
var f1 = new fractal(endPoint.x, endPoint.y, theta+Math.PI/8, r*0.8, color+30)
var f2 = new fractal(endPoint.x, endPoint.y, theta-Math.PI/8, r*0.8, color+30)
fractals.push(f1, f2)
}

}

}
})
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more