Skip to content

Rotating fractal

A fractal of squares that rotate; each square vertex replaced by a copy of the shape

function setup() {
  createCanvas(400, 400);
  angleMode(DEGREES)
  mouseX = width / 2
}

let t = 0
let i = 0

function draw() {
  t += 10
  i = 0
  background(220);
  translate(200, 200)
  noFill()
  f(260)
}

function f(r) {
  
  if (r < 2) {
    if (i++ == 0) {
      stroke(255, 0, 0)
    } else {
      stroke(0)
    }
    circle(0, 0, r)
    return
  }
  for (let i = 0; i < 4; i ++) {
    push()
    rotate(t/r*20 + i * 360 / 4)
    translate(r * 0.5, 0)
    if (i%2) {
      scale(-1, 1)
    }
    f(r * 0.42)
    pop()
  }
}

(Originally seen at https://editor.p5js.org/bojidar-bg/sketches/J8uSukUGS)

Experiments tagged p5 (18/85)

Experiments tagged fractal (2/3)

Experiments on this site (18/85)