Doing some backups, came across an old snippet of mine. Might've done this for a code challenge or something, I can't remember. No external graphics needed.
// Project: digital display
// Created: 2016-12-23
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "digital display" )
SetWindowSize( 1024, 768, 0 )
// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
SetSyncRate( 60, 0 ) // 30fps instead of 60 to save battery
UseNewDefaultFonts( 1 ) // since version 2.0.20 we can use nicer default fonts
Global _Digits as Digit[6]
Global _Dots1, _Dots2
Type Digit
background as integer
foreground as integer
EndType
createDigits()
createDots()
setClockColor(34,192,255)
setClockPosition(100,300)
`clockOn(0)
r as integer[10] = [95,5,118,117,48,121,123,69,127,109]
c = makeColor(192,192,192)
do
drawNumber("0123456789", 100, 50, MakeColor(200,0,0))
// Left click to randomize clock color
if GetRawMouseLeftPressed() then setClockColor(random(0,255),random(0,255),random(0,255))
updateClock()
`print("≡")
print(GetCurrentDir())
Render2DFront()
Sync()
loop
// get system time and update clock
function updateClock()
t$ = GetCurrentTime()
d = 1
for i = 1 to len(t$)
c$ = mid(t$, i, 1)
if c$ <> ":"
setSpriteFrame(_Digits[d].foreground, val(c$)+1)
inc d
endif
next i
endfunction
// Turn clock on or off (background still visible when off)
function clockOn(x)
for i = 1 to 6
setSpriteVisible(_Digits[i].foreground, x)
next i
endfunction
// Position the clock
function setClockPosition(x, y)
setSpritePosition(_Digits[1].background, x, y) : setSpritePosition(_Digits[1].foreground, x, y)
setSpritePosition(_Digits[2].background, x+84, y) : setSpritePosition(_Digits[2].foreground, x+84, y)
setSpritePosition(_Digits[3].background, x+210, y) : setSpritePosition(_Digits[3].foreground, x+210, y)
setSpritePosition(_Digits[4].background, x+294, y) : setSpritePosition(_Digits[4].foreground, x+294, y)
setSpritePosition(_Digits[5].background, x+420, y) : setSpritePosition(_Digits[5].foreground, x+420, y)
setSpritePosition(_Digits[6].background, x+504, y) : setSpritePosition(_Digits[6].foreground, x+504, y)
setSpritePosition(_Dots1, x+168, y)
setSpritePosition(_Dots2, x+378, y)
endfunction
// Sets color of clock
function setClockColor(r, g, b)
for i = 1 to 6
setSpriteColor(_Digits[i].background, r, g, b, 10)
setSpriteColor(_Digits[i].foreground, r, g, b, 255)
next i
setSpriteColor(_Dots1, r, g, b, 255)
setSpriteColor(_Dots2, r, g, b, 255)
endfunction
// Draws the two double dot sprites for the time clock
function createDots()
CreateMemblock(1, 11276)
setMemblockInt(1, 0, 22)
setMemblockInt(1, 4, 128)
setMemblockInt(1, 8, 32)
c = makeColor(255,255,255)
for y = 0 to 21
for x = 0 to 21
setMemblockInt(1, (x + (y+17)*22)*4+12, c)
setMemblockInt(1, (x + (y+87)*22)*4+12, c)
next x
next y
CreateImageFromMemblock(2, 1)
DeleteMemblock(1)
_dots1 = createSprite(2)
_dots2 = cloneSprite(_dots1)
endfunction
// Draw digits 0 through 9 to memblock 1
function createDigits()
// Create an image 640x128 with digits of 0 through 9 at 64,128 in size
CreateMemblock(1, 327692)
setMemblockInt(1, 0, 640)
setMemblockInt(1, 4, 128)
setMemblockInt(1, 8, 32)
// width of image
memWidth = 640
c = makecolor(255,255,255)
// The binary representation of each number determines which part of the digital
// display is drawn to make up a given number. 7 bits represent the 7 sides of the
// digital number.
global z as integer[10] = [95,5,118,117,45,121,123,69,127,109]
pos = 0
for i = 0 to 9
for y = 0 to 4
for x = 7+y to 57-y
// top
if z[i] && 64
setMemblockInt(1, (pos+x+(5-y)*memWidth)*4+12, c)
setMemblockInt(1, (pos+x+(5+y)*memWidth)*4+12, c)
endif
// middle
if z[i] && 32
setMemblockInt(1, (pos+x+(64-y)*memWidth)*4+12, c)
setMemblockInt(1, (pos+x+(64+y)*memWidth)*4+12, c)
endif
// bottom
if z[i] && 16
setMemblockInt(1, (pos+x+(123-y)*memWidth)*4+12, c)
setMemblockInt(1, (pos+x+(123+y)*memWidth)*4+12, c)
endif
next x
next y
for x = 0 to 4
for y = 8+x to 61-x
// top-left
if z[i] && 8
setMemblockInt(1, (pos+4-x+y*memWidth)*4+12, c)
setMemblockInt(1, (pos+4+x+y*memWidth)*4+12, c)
endif
// top-right
if z[i] && 4
setMemblockInt(1, (pos+59-x+y*memWidth)*4+12, c)
setMemblockInt(1, (pos+59+x+y*memWidth)*4+12, c)
endif
// bottom-left
if z[i] && 2
setMemblockInt(1, (pos+4-x+(59+y)*memWidth)*4+12, c)
setMemblockInt(1, (pos+4+x+(59+y)*memWidth)*4+12, c)
endif
// bototm-right
if z[i] && 1
setMemblockInt(1, (pos+59-x+(59+y)*memWidth)*4+12, c)
setMemblockInt(1, (pos+59+x+(59+y)*memWidth)*4+12, c)
endif
next y
next x
inc pos, 64
next i
// free memory
undim z[]
// Create the image
CreateImageFromMemblock(1, 1)
DeleteMemblock(1)
SaveImage(1, "digits.png")
//
_Digits[1].background = createSprite(1)
setSpriteAnimation(_Digits[1].background, 64, 128, 10)
setSpriteFrame(_Digits[1].background, 9)
SetSpritePosition(_Digits[1].background,100,100)
for i = 2 to 6
_Digits[i].background = cloneSprite(_Digits[1].background)
SetSpritePosition(_Digits[i].background,100+(i-1)*74,100)
next i
for i = 1 to 6
_Digits[i].foreground = cloneSprite(_Digits[1].background)
setSpriteColor(_Digits[i].foreground, 34,192,255,255)
setSpritePosition(_Digits[i].foreground, 100+(i-1)*74, 100)
setSpriteFrame(_Digits[i].foreground, random(1,10))
next i
endfunction
// n$ = Number to display (as a string)
// x,y = position
// r = color
function drawNumber(n$, tx, ty, r)
global k as integer[10] = [95,5,118,117,45,121,123,69,127,109]
c1 = MakeColor(getColorRed(r)*.1, getColorGreen(r)*.1, getColorBlue(r)*.1)
pos = tx
for j = 1 to len(n$)
i = val(mid(n$, j, 1))
for y = 0 to 4
for x = 7+y to 57-y
// top
if k[i] && 64 : c = r : else : c = c1 : endif
drawBox(pos+x, ty+5-y, pos+x+1, ty+4-y, c,c,c,c,1)
drawBox(pos+x, ty+5+y, pos+x+1, ty+6+y, c,c,c,c,1)
// middle
if k[i] && 32 : c = r : else : c = c1 : endif
drawBox(pos+x, ty+64-y, pos+x+1, ty+63-y, c,c,c,c,1)
drawBox(pos+x, ty+64+y, pos+x+1, ty+65+y, c,c,c,c,1)
// bottom
if k[i] && 16 : c = r : else : c = c1 : endif
drawBox(pos+x, ty+123-y, pos+x+1, ty+122-y, c,c,c,c,1)
drawBox(pos+x, ty+123+y, pos+x+1, ty+124+y, c,c,c,c,1)
next x
next y
for x = 0 to 4
for y = 8+x to 61-x
// top-left
if k[i] && 8 : c = r : else : c = c1 : endif
drawBox(pos+4-x, ty+y, pos+5-x, ty+y+1, c,c,c,c,1)
drawBox(pos+4+x, ty+y, pos+5-x, ty+y+1, c,c,c,c,1)
// top-right
if k[i] && 4 : c = r : else : c = c1 : endif
drawBox(pos+59-x, ty+y, pos+60-x, ty+y+1, c,c,c,c,1)
drawBox(pos+59+x, ty+y, pos+60+x, ty+y+1, c,c,c,c,1)
// bottom-left
if k[i] && 2 : c = r : else : c = c1 : endif
drawBox(pos+4-x, ty+59+y, pos+5-x, ty+60+y, c,c,c,c,1)
drawBox(pos+4+x, ty+59+y, pos+5+x, ty+60+y, c,c,c,c,1)
// bototm-right
if k[i] && 1 : c = r : else : c = c1 : endif
drawBox(pos+59-x, ty+59+y, pos+60-x, ty+60+y, c,c,c,c,1)
drawBox(pos+59+x, ty+59+y, pos+60+x, ty+60+y, c,c,c,c,1)
next y
next x
inc pos, 84
next j
endfunction