Skip to content

Instantly share code, notes, and snippets.

@jasoncoon
Created February 18, 2024 17:22
Show Gist options
  • Save jasoncoon/227ef0e18e5de42a331e48162df8e785 to your computer and use it in GitHub Desktop.
Save jasoncoon/227ef0e18e5de42a331e48162df8e785 to your computer and use it in GitHub Desktop.
Pixelblaze Triple Helix Hourglass ⏳⌛️
// Pixelblaze Triple Helix Hourglass
// by Jason Coon, Evil Genius Labs: evilgeniuslabs.org
// This work is licensed under a Creative Commons (4.0 International License):
// Attribution—Noncommercial—Share Alike: https://creativecommons.org/licenses/by-nc-sa/4.0
var pixels = array(pixelCount)
export var maxLevel = 0.25
export var friction = 128
// export function sliderFriction(v) {
// friction = clamp(v * 1024, 1, 1024)
// }
// export function showNumberFriction() {
// return friction
// }
// export function sliderMaxLevel(v) {
// maxLevel = v / 2
// }
// export function showNumberMaxLevel() {
// return maxLevel
// }
export var topLevel = maxLevel / 2
export var bottomLevel = maxLevel / 2
export var vInc = 1.0 / friction
export var upsideDown
export var falling
export var accelerometer
export function beforeRender(delta) {
t1 = time(0.01)
var az = accelerometer[2]
// if az > 0 right side up
// if az < 0 upside down
upsideDown = az < 0
topLevel -= az / friction
bottomLevel += az / friction
topLevel = clamp(topLevel, 0, maxLevel)
bottomLevel = clamp(bottomLevel, 0, maxLevel)
falling = topLevel !== 0 && bottomLevel !== 0
mapPixels((index, x, y, z) => {
var v = pixels[index]
if (falling) {
if (upsideDown) { // upside down
if (z >= 0.5 && z < (1 - topLevel)) {
v = wave(t1 - z * 16) * 0.4
}
}
else { // rightside up
if (z <= 0.5 && z > bottomLevel) {
v = wave(t1 + z * 16) * 0.4
}
}
}
if (upsideDown) {
if(z > (1 - maxLevel) && z > (1 - topLevel)) {
// "bottom" pile
v += vInc
}
else if (z < 0.5 && z > 0.5 - bottomLevel) {
// "top" pile, avove the mid level, waiting to fall
v += vInc
}
else {
v -= vInc
}
} else { // rightside up
if (z < maxLevel && z < bottomLevel) {
// "bottom" pile
v += vInc
}
else if (z > 0.5 && z < 0.5 + topLevel) {
// "top" pile, avove the mid level, waiting to fall
v += vInc
}
else {
v -= vInc
}
}
v = clamp(v, 0, 1)
pixels[index] = v
})
}
export function render3D(index, x, y, z) {
// middle indicator
// if (z >= 0.5 && z <= 0.5) {
// return hsv(0, 1, 0.5)
// }
var v = pixels[index]
return hsv(0.2, 0.25, v * v)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment