Answers for "dragon curve"

0

dragon curve

// p5.js

let sys = ["|", "X"], scale = 1

function setup() { createCanvas(500, 500) }

function keyPressed() { 
  sys = sys.map(c => ({X:"X+Y|+", Y:"-|X-Y"}[c] || c).split("")).flat()
  scale *= 0.75
}

function draw() {
  translate(width / 2, height / 2)
  background(0, 0, 0)
  stroke(255)
  push()
  for (const char of sys) {
    if (char == "|") { 
      line(0, 0, 0, - width/8 * scale)
      translate(0, - width/8 * scale)
    }
    rotate({"+": PI/2, "-": -PI/2}[char] || 0)
  }
  pop()
}
Posted by: Guest on June-16-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language