digital clock with sevensegment display, colored

Post Reply
osscp
Posts: 2
Joined: Sun May 03, 2015 9:41 pm
My devices: ipad air

digital clock with sevensegment display, colored

Post by osscp »

It is possible, to change the color of the digital clock via sliders
By old school spagetti code programmer osscp , enjoy !

Code: Select all

' simple clock with sevensegment digits by osscp
' version 0.8 / 2015-05
' use in wide screen mode
' tested on ipad air



' proportions of the segments
REM R offset x
REM D thickness
REM L length
REM not really scalable at the moment

' color of the segments
segmentcolor_red=0.9    REM global
segmentcolor_green=0.1  REM global
segmentcolor_blue=0.5   REM global 


'c'
DEF segmentA(x,y, R,D,L)
s7x1=x+R+D
s7y1=y-(R+D+L+D+L)
s7x2=x+R+D+L
s7y2=y-(R+D+L+D+L+D)
FILL COLOR .segmentcolor_red,.segmentcolor_green,.segmentcolor_blue
FILL RECT s7x1,s7y1 TO s7x2,s7y2
END DEF

DEF segmentB(x,y, R,D,L)
s6x1=x+R
s6y1=y-(R+D+L+D)
s6x2=x+R+D
s6y2=y-(R+D+L+D+L)
FILL COLOR .segmentcolor_red,.segmentcolor_green,.segmentcolor_blue
FILL RECT s6x1,s6y1 TO s6x2,s6y2
END DEF

DEF segmentC(x,y, R,D,L)
s3x1=x+R
s3y1=y-(R+D)
s3x2=x+R+D
s3y2=y-(R+D+L)
FILL COLOR .segmentcolor_red,.segmentcolor_green,.segmentcolor_blue
FILL RECT s3x1,s3y1 TO s3x2,s3y2
END DEF


DEF segmentD(x,y, R,D,L)
s1x1=x+R+D
s1y1=y-R
s1x2=x+(R+D+L)
s1y2=y-(R+D)
FILL COLOR .segmentcolor_red,.segmentcolor_green,.segmentcolor_blue
FILL RECT s1x1,s1y1 TO s1x2,s1y2
END DEF

DEF segmentE(x,y, R,D,L)
s2x1=x+R+D+L
s2y1=y-(R+D)
s2x2=x+R+D+L+D
s2y2=y-(R+D+L)
FILL COLOR .segmentcolor_red,.segmentcolor_green,.segmentcolor_blue
FILL RECT s2x1,s2y1 TO s2x2,s2y2
END DEF

DEF segmentF(x,y, R,D,L)
s5x1=x+R+D+L
s5y1=y-(R+D+L+D)
s5x2=x+R+D+L+D
s5y2=y-(R+D+L+D+L)
FILL COLOR .segmentcolor_red,.segmentcolor_green,.segmentcolor_blue
FILL RECT s5x1,s5y1 TO s5x2,s5y2
END DEF


DEF segmentG(x,y, R,D,L)
s4x1=x+R+D
s4y1=y-(R+D+L)
s4x2=x+R+D+L
s4y2=y-(R+D+L+D)
FILL COLOR .segmentcolor_red,.segmentcolor_green,.segmentcolor_blue
FILL RECT s4x1,s4y1 TO s4x2,s4y2
END DEF


'y'

DEF digit(x,y,v) REM v=value
R=20 REM OFFSET from black background
D=10 REM thickness
L=40 REM hight
FILL COLOR 0.1,0.1,0.1  REM background color
FILL RECT x-1,y-1 TO x+100, y-140
IF v=2 OR v=3 OR v=5 OR v=0 OR v=7 OR v=8 OR v=9 THEN segmentA(x,y, R,D,L)
IF v=4 OR v=4 OR v=5 OR v=6 OR v=0 OR v=8 OR v=9 THEN segmentB(x,y, R,D,L)
IF v=2 OR v=6 OR v=0 OR v=8 THEN segmentC(x,y, R,D,L)
IF v=2 OR v=3 OR v=5 OR v=6 OR v=0 OR v=9 OR v=8 THEN segmentD(x,y, R,D,L)
IF v=1 OR v=3 OR v=4 OR v=5 OR v=6 OR v=7 OR v=0 OR v=8 OR v=9 THEN segmentE(x,y, R,D,L)
IF v=1 OR v=2 OR v=3 OR v=4 OR v=7 OR v=0 OR v=8 OR v=9 THEN segmentF(x,y, R,D,L)
IF v=2 OR v=3 OR v=4 OR v=5 OR v=6 OR v=8 OR v=9 THEN segmentG(x,y, R,D,L)
REM punkt(x,y, R,D,L)
END DEF


''
REM Main
GRAPHICS

GRAPHICS CLEAR 0.1,0.1,0.1

REM init slider part
x=200 ! y=400
OPTION ANGLE DEGREES
SLIDER "red"   VALUE 0.1 AT x,y+40  SIZE 300 ANGLE 0
SLIDER "green" VALUE 0.9 AT x,y+80  SIZE 300 ANGLE 0
SLIDER "blue"  VALUE 0.9 AT x,y+120 SIZE 300 ANGLE 0
segmentcolor_red=SLIDER_VALUE("red")
segmentcolor_green=SLIDER_VALUE("green")
segmentcolor_blue=SLIDER_VALUE ("blue")
FILL COLOR 0,0,0
FILL RECT x+400, y+40 TO x+480, y+140

REM init clock part
x=160
y=400
FOR k=0 TO 5
digit(x,y,0)
IF k=1 OR k=3 THEN x=x+20
x=x+88
NEXT k


LOOP:

stundenzehner=   FLOOR  (CURRENT_HOUR()/10)
stundeneiner=    CURRENT_HOUR()- stundenzehner *10

minutenzehner=   FLOOR (CURRENT_MINUTE()/10)
minuteneiner=    CURRENT_MINUTE()- minutenzehner *10

sekundenzehner=  FLOOR (CURRENT_SECOND()/10)


digit(160,y,stundenzehner)
digit(248,y,stundeneiner)
digit(356,y,minutenzehner)
digit(444,y,minuteneiner)
digit(552,y,sekundenzehner)

FOR sekundeneiner =0 TO 9
digit(640,y,sekundeneiner)
PAUSE 1  

REM every 1 sec slider color will change for preview
IF SLIDER_CHANGED ("red")   THEN segmentcolor_red  =SLIDER_VALUE("red")
IF SLIDER_CHANGED ("green") THEN segmentcolor_green=SLIDER_VALUE("green")
IF SLIDER_CHANGED ("blue")  THEN segmentcolor_blue =SLIDER_VALUE("blue")
FILL COLOR segmentcolor_red,segmentcolor_green,segmentcolor_blue
FILL RECT 200+420, 400+60 TO 200+460, 400+120

NEXT sekundeneiner

REM every 10 sec clock color will change

GOTO LOOP

Attachments
image.jpg
image.jpg (130.12 KiB) Viewed 3058 times

Post Reply