Square dance-off
A silly experiment based around generating random rhythms.
let c
let r = Array(50).fill().map((_, i) => i < 25)
function setup() {
c = createCanvas(windowWidth, windowHeight);
background(220)
r = shuffle(r)
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight)
background(220)
}
let x = 0
let y = 0
let tx = 150
let ty = 150
let n = 0
function draw() {
colorMode(RGB)
background(220, 10)
for (let i = 0; i < 2; i ++) {
push()
translate(width/2, height/2)
rotate(PI + (n * 0.005))
scale(1.02)
image(c, -width/2, -height/2)
pop()
colorMode(HSL)
fill(((frameCount * 10 + random(13)) * (i - 0.5)%360 + 360)%360, 100, 60)
rect(x, y, 40, 40)
}
x += (tx - x) * 0.3
y += (ty - y) * 0.3
if (frameCount % r.length == 0) {
tx = random(width/2.5) + random(width/2.5)
ty = random(height/2.5) + random(height/2.5)
}
if (r[frameCount % r.length]) {
n ++
} else if (n > 0) {
n --
}
}(Originally seen at https://editor.p5js.org/bojidar-bg/sketches/ilbfW6e2n)
Browse more articles?
← Prismatic gem Experiments tagged p5 (38/85) Gear face →
← Prismatic gem Experiments on this site (38/85) Gear face →