Creative Coding Auto-Painting
Object.getOwnPropertyNames(Math).map(i => (this[i] = Math[i]))
;((
width = innerWidth * 2,
height = innerHeight * 2,
cnv = document.body.appendChild(
Object.assign(document.createElement('canvas'), {
width,
height
})
),
c = cnv.getContext('2d'),
r = (n = 1) => Math.random() * n,
NUM = 50,
f = () => ({
ax: r(width),
ay: r(height),
x: 0,
y: 0,
T: r(9),
R: r(innerWidth * 0.8) + 40,
t: r(6),
C: round(r(255)),
m: r(5) + 1
}),
cs,
sn,
dx,
dy,
ns = [...Array(NUM)].map(f)
) => {
Object.assign(cnv.style, {
transformOrigin: '0 0',
transform: 'scale(.5)'
})
Object.assign(document.body.style, {
margin: 0,
padding: 0
})
const clear = () => {
c.fillStyle = '#666668'
c.fillRect(0, 0, width, height)
c.globalAlpha = 0.5
}
onresize = () => {
width = cnv.width = innerWidth * 2
height = cnv.height = innerHeight * 2
clear()
}
clear()
setInterval(() => {
for (i = 0; i < 30; i++) {
ns.map((n, i) => {
with (n) {
x = ax + R * cos(t)
y = ay + R * sin(t) * pow(sin(t * 0.5), m)
c.fillStyle = `rgba(${C},${C},${C},.02)`
;(cs = cos(T)), (sn = sin(T)), (dx = x - ax), (dy = y - ay)
c.fillRect(cs * dx - sn * dy + ax, sn * dx + cs * dy + ay, 50, 50)
t += 0.1
R -= 0.01
if (R < 5) ns[i] = f()
}
})
}
}, 16)
})()
Speed coded semi-golfed canvas texture. Best if viewed in fullscreen.