Skip to content

Gradient gears

Made for Genuary 2025, January 22, prompt: Gradient.

A spiral of gears made out of forcefields, slowly pushing on each other

let gi

function setup() {
  createCanvas(800, 640);
  angleMode(DEGREES)
  gi = createImage(1, 2)
}
function setGradient(c1, c2) {
  gi.set(0, 0, c1)
  gi.set(0, 1, c2)
  gi.updatePixels()
  return gi
}
function gradientRect(x, y, w, h) {
  image(gi, x, y, w, h, 0, 0.5, 0.5, 1)
}
function gradientWheel(x, y, r, w, s, a) {
  push()
  translate(x, y)
  rotate(a)
  for (let i = 0; i < s; i ++) {
    rotate(360/s)
    gradientRect(0, 0, r, w)
    rotate(180)
    gradientRect(-r, -0.1, r, w)
    rotate(180)
  }
  pop()
}
function draw() {
  setGradient(color(255, 250, 160), color(255, 220, 200))
  gradientRect(0, 0, width, height/2)
  setGradient(color(255, 220, 200), color(255, 200, 250))
  gradientRect(0, height/2, width, height/2)
  let a = frameCount / 2
  translate(width/2, height/2)
  
  for (let i = 0; i < 70; i ++) {
    setGradient(color(100, 10, 50, map(i, 0, 70, 240, 30)), color(0, 0))
    gradientWheel(width/2, 0, 100, 25, 9, a)
    rotate(23)
    a = -a - 360/9/2 + 23/2 + sin(a * 3) * 1
    scale(map(i*i, 0, 70*70, 0.96, 0.9))
  }
}

(Originally seen at https://editor.p5js.org/bojidar-bg/sketches/JwePH1RpU and https://mastodon.social/@bojidar_bg/113874084075113561)

Experiments tagged p5 (24/85)

|← Experiments tagged genuary (1/2)

Experiments on this site (24/85)