Isometric Vases
const canvas = document.createElement`canvas`
const c = canvas.getContext`2d`
document.body.appendChild(canvas)
document.body.style.margin = 0
canvas.style.width = '100%'
canvas.style.height = '100%'
const COLS = 10
const ROWS = 10
let space;
let size;
let time = 0
const num = COLS * ROWS
const mon = []
for (let y = 0; y < COLS; y++) {
for (let x = 0; x < ROWS; x++) {
mon.push(monument())
}
}
function reset(){
time = 0
c.fillStyle = '#ccc'
c.fillRect(0, 0, canvas.width, canvas.height)
}
function resize() {
canvas.width = innerWidth * 2
canvas.height = innerHeight * 2
reset()
}
resize()
window.addEventListener('resize', resize)
function monument(x, y) {
const s = Math.random()
let cl = 0;
let damp = Math.random() / 10;
let rad = 10 + Math.random() *
Math.random() * (innerWidth / 30)
let skip = Math.random() < .5;
let o = Math.random() * 7
let shade = .01;
let radamp = 200 + Math.random() * 90
let life = 100 + Math.random() * Math.random() * Math.random() * 1200;
return (x, y) => {
if (time === 0) {
c.save()
c.strokeStyle = 'rgba(0, 0, 0, 0.2)'
c.translate(x - space / 2, y - space / 2)
c.strokeRect(0, 0, space, space)
c.restore()
}
if (skip) {
} else {
//rad += (0 - rad) / radamp
let teta = time * s * damp
let C = Math.sin(teta)
let C2 = Math.sin(time * s * damp + o);
cl = C2 * 200 + 55;
shade -= .0001;
let col = `rgba(${cl}, ${cl}, ${cl}, 1)`
if (time > life) {
col = `rgba(155, 155, 155, .4)`
skip = true
}
c.save()
c.translate(x - time * s, y)
c.fillStyle = `rgba(0, 0, 0, ${shade})`
c.beginPath()
c.arc(0, 0, rad + rad * C, 0, 7)
c.fill()
c.restore();
c.save()
c.translate(x - time * s, y - time * s)
c.fillStyle = col
c.beginPath()
c.arc(0, 0, rad + rad * C, 0, 7)
c.fill()
c.restore();
}
}
}
function draw() {
space = (innerWidth * 2) / COLS * .6;
size = COLS * space
c.save()
c.scale(1, .6)
c.translate(innerWidth, innerHeight * 2)
c.rotate(45 * Math.PI / 180)
c.translate(-size / 2, -size / 2)
let inc = 0;
for (let y = 0; y < COLS; y++) {
for (let x = 0; x < ROWS; x++) {
mon[inc++](y * space, x * space)
}
}
c.restore()
time++
requestAnimationFrame(draw)
}
draw();
Something I speed coded for genuary