Skip to content

Lissajous scanner

It's apparently possible to draw a Lissajous curve row by row!

Lissajous curves are draw into the canvas as series of points; once a curve is finished, a new one starts drawing

function setup() {
  createCanvas(450, 450);
  noSmooth()
  background(220);
}

let a = 3, b = 3, x = 0, d = 0

function draw() {
  x += 2
  if (x > 400) {
    x = 0
    a = round(random(1, 10))
    b = round(random(1, 10))
    d = round(random(1, 4))
    print(a, b, d)
  }
  translate(25, 25)
  if (d == 1) {
    applyMatrix(0, 1, 1, 0, 0, 0)
  } else if (d == 2) {
    applyMatrix(-1, 0, 0, 1, 400, 0)
  } else if (d == 3) {
    applyMatrix(0, -1, 1, 0, 0, 400)
  }
  stroke(220)
  strokeWeight(2)
  line(x, 0, x, 400)
  stroke(0)
  let t = (asin((x - 200) / 200)) * a
  for(let i = 0; i < b * 2; i ++) {
    point(x, 200+sin((t+PI * i) / b)*200)
  }
}

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

Experiments tagged p5 (40/85)

Experiments on this site (40/85)