Skip to content

Commit

Permalink
much improved countdown animation
Browse files Browse the repository at this point in the history
  • Loading branch information
psy0rz committed Sep 4, 2024
1 parent 0db13ab commit 6b44a4b
Show file tree
Hide file tree
Showing 6 changed files with 404 additions and 71 deletions.
49 changes: 26 additions & 23 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

112 changes: 70 additions & 42 deletions ledder/animations/Countdown.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import Pixel from "../Pixel.js"
import Display from "../Display.js"
import PixelBox from "../PixelBox.js"
import Scheduler from "../Scheduler.js"
import ControlGroup from "../ControlGroup.js"
import {fontSelect} from "../fonts.js"
import DrawText from "../draw/DrawText.js"
import Animator from "../Animator.js"
import Nyancat from "./Memes/Nyancat.js"
import XmasSantaReindeer from "./ReinsCollection/XmasSantaReindeer.js"

import Marquee from "./Text/Marquee.js"

function paddy(num, padlen, padchar = '0') {
var pad = new Array(1 + padlen).join(padchar)
Expand All @@ -19,69 +17,99 @@ export default class Countdown extends Animator {

async run(box: PixelBox, scheduler: Scheduler, controls: ControlGroup) {

const font = fontSelect(controls)

let targetDate = new Date('2023-12-31T23:59:59')

// let targetDate = new Date('2022-04-01T12:37:42');
let targetDate = new Date(controls.input('Target time', '2024-09-04T00:00', true).text)

const textColor = controls.color("Text color", 255, 0, 0, 1)
let cat=new Nyancat()
cat.run(box, scheduler, controls.group('cat'))
const marqueeBox=new PixelBox(box)
box.add(marqueeBox)

const countBox=new PixelBox(box)
const countBox = new PixelBox(box)
box.add(countBox)

const kerstman=new XmasSantaReindeer()
kerstman.run(box, scheduler,controls.group('xmas'))
let controlNormalColor = controls.color('Normal', 0, 255, 0)
let controlWarningColor = controls.color('Warning', 255, 0, 0)
let controlShowMs = controls.switch('Show mS', true)
let controlWarningMinutes = controls.value('Warning time (min)', 60, -60, 600)

const font = fontSelect(controls.group("Font"), 'Font', 'C64 mono')
let controlX = controls.group("Font").value('X', box.xMin, box.xMin, box.xMax)
let controlY = controls.group("Font").value('Y', box.xMin, box.yMin, box.yMax)

let blinkdir = 1 / 60
let hue = 0

let marquee=new Marquee()
marquee.run(marqueeBox, scheduler,controls.group("Marquee"))

scheduler.interval(1, () => {

//millesec
let diff = Number(targetDate) - Number(new Date())
let color


let text = ""
if (isNaN(diff)) {
text = "(invalid)"
color = controlWarningColor
} else {

if (diff <= 0) {
if (diff / 60000 < controlWarningMinutes.value)
color = controlWarningColor
else
color = controlNormalColor

textColor.a = textColor.a + blinkdir
if (textColor.a >= 1) {
blinkdir = -blinkdir
textColor.a = 1
let timeout=false
if (diff <= 0) {
diff = 0
timeout=true
}
if (textColor.a <= 0) {
blinkdir = -blinkdir
textColor.a = 0

if (timeout) {

color.a = color.a + blinkdir
if (color.a >= 1) {
blinkdir = -blinkdir
color.a = 1
}
if (color.a <= 0) {
blinkdir = -blinkdir
color.a = 0
}
}
}
else
color.a=1

// hue = (hue + 1)%361
// textColor.setHsl(hue,100,50)

// hue = (hue + 1)%361
// textColor.setHsl(hue,100,50)
diff = Math.abs(diff)
let ms = diff % 1000

diff = Math.abs(diff)
let ms = diff % 1000
//seconds
diff = ~~(diff / 1000)
let s = diff % 60

//seconds
diff = ~~(diff / 1000)
let s = diff % 60
//minutes
diff = ~~(diff / 60)
let m = diff % 60

//minutes
diff = ~~(diff / 60)
let m = diff % 60
//hours
diff = ~~(diff / 60)
let h = diff

//hours
diff = ~~(diff / 60)
let h = diff
//te groot
// h=h%10

//te groot
// h=h%10
text = `${h}:${paddy(m, 2)}:${paddy(s, 2)}`

if (controlShowMs.enabled)
text = text + `.${paddy(~~(ms / 10), 2)}`
}


let text = `${h}:${paddy(m, 2)}:${paddy(s, 2)}.${paddy(~~(ms / 10), 2)}`
countBox.clear()
countBox.add(new DrawText(0,0,font, text, controls.color()))
countBox.center(box)
countBox.add(new DrawText(controlX.value, controlY.value, font, text, color))
//countBox.center(box)


})
Expand Down
5 changes: 1 addition & 4 deletions ledder/animations/Text/Marquee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import Animator from "../../Animator.js"
import FxTwinkle from "../../fx/FxTwinkle.js"
import FxColorPattern from "../../fx/FxColorPattern.js"
import TheMatrix from "../MovieFx/TheMatrix.js"
import DrawBlur from "../../draw/DrawBlur.js"
import Color from "../../Color.js"
import {scheduler} from "node:timers/promises"



export default class Marquee extends Animator {
Expand Down Expand Up @@ -102,7 +100,6 @@ export default class Marquee extends Animator {
textBoundBox.xMin = 0

rotatorPromise = rotator.run(textPixels, textBoundBox, waitX, null)
// rotatorPromise = rotator.run(charPixels, textBbox, waitX, null)
} else {
//no scrolling
textPixels.centerH(box)
Expand Down
4 changes: 2 additions & 2 deletions ledder/fonts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ export let fonts = {
}

//helper to make it easier to let the user select a font
export function fontSelect(control:ControlGroup, name='Font', selected='C64' , heightOffset=0):Font
export function fontSelect(control:ControlGroup, name='Font', defaultFont='C64' , heightOffset=0):Font
{
let choices = []
for (const [id, font] of Object.entries(fonts)) {
choices.push({id: id, name: font.name})
}


const fontControl = control.select(name, selected, choices, true)
const fontControl = control.select(name, defaultFont, choices, true)
const heightControl = control.value(name+ ' height', heightOffset,0,100,1, true)
const widthControl = control.value(name+ ' width', heightOffset,0,100,1, true)

Expand Down
Loading

0 comments on commit 6b44a4b

Please sign in to comment.