xxxxxxxxxx
88
const lerp_ = (a, b, t) => (t * parseFloat(b)) + ((1 - t) * parseFloat(a))
const wrap = (n) => n - Math.floor(n)
const addMinute = (time) => new Date(time.getTime() + 60 * 1000)
const addHour = (time) => new Date(time.getTime() + 60 * 60 * 1000)
function setup() {
createCanvas((windowWidth), (windowHeight))
}
function decToBinaryFloats(dec) {
let bin = (dec)
.toString(2)
.padStart(6, "0")
.split("")
.map(c => parseFloat(c))
return bin
}
function windowResized() {
createCanvas((windowWidth), (windowHeight))
}
function drawBlocks(x, y, now, future, theta, size, spacing) {
let width = 0
for (let i = 0; i < now.length; i++) {
const f = lerp_(now[i], future[i], theta)
const brightness = 255;// 240 * (f**2) + 15
noStroke()
stroke(12)
fill(brightness)
rect(x, height - (f * height), size, (f*height))
x += size + spacing
width += size + spacing
}
return width
}
function drawTime(x, y, theta_m, theta_h, now_h, future_h, now_m, future_m, size) {
let width = 0
const spacing = 0
width += drawBlocks(x, y, now_h, future_h, theta_h, size, spacing)
x += width
width += drawBlocks(x, y, now_m, future_m, theta_m, size, spacing)
return width
}
let draw_width = 0
function draw() {
background(0)
const now = new Date()
const future = addMinute(now)
const future_h = addHour(now)
const fractional = now.getMilliseconds() / 1000
const seconds = now.getSeconds() + fractional
const theta_m = seconds / 60
const theta_h = (now.getMinutes() + (seconds/60)) / 60
const now_minutes = decToBinaryFloats(now.getMinutes())
const now_hours = decToBinaryFloats(now.getHours())
const future_minutes = decToBinaryFloats(future.getMinutes())
const future_hours = decToBinaryFloats(future_h.getHours())
let x = 0
const size = width/12
drawTime(x, 0, theta_m, theta_h, now_hours, future_hours, now_minutes, future_minutes, size)
// const debug_hours = future.getHours().toString(2).padStart(6, "0")
// const debug_mins = future.getMinutes().toString(2).padStart(6, "0")
}