Created
November 11, 2019 19:22
-
-
Save jh3y/29abd5a8bee2cfd5dca1b8fb653a7490 to your computer and use it in GitHub Desktop.
Create hypnotising/psychedelic rings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* So you get 240 x 240 so you can technically do different things right? | |
* Colors? | |
*/ | |
g.clear() | |
//g.drawImage(img, 100,100); | |
class Ring { | |
constructor() { | |
this.alive = true | |
this.radius = 0 | |
} | |
} | |
const LIMIT = 50 | |
const RANDOM = 1 | |
let BUFFER = 0 | |
const BUFFER_SPREAD = 20 | |
const RADIUS_LIMIT = 240 | |
const pool = [] | |
const animate = () => { | |
if (pool.length < LIMIT && BUFFER === 0) { | |
const available = pool.filter(ring => !ring.alive) | |
const newRing = available.length ? available[0] : new Ring() | |
pool.push(newRing) | |
BUFFER = BUFFER_SPREAD | |
} | |
g.clear() | |
if (BUFFER > 0) BUFFER-- | |
for (const ring of pool) { | |
if (ring.radius > RADIUS_LIMIT) { | |
ring.radius = 0; | |
ring.alive = false; | |
} else { | |
if (RANDOM) g.setColor(Math.random() > 0.5 ? 1 : 0, Math.random() > 0.5 ? 1 : 0, Math.random() > 0.5 ? 1 : 0) | |
g.drawCircle(120, 120, ring.radius++) | |
} | |
} | |
setTimeout(animate, 1000/120) | |
} | |
animate() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment