Author Topic: One page clock  (Read 6303 times)

0 Members and 1 Guest are viewing this topic.

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
One page clock
« on: January 19, 2020, 01:48:18 am »
Code: QB64: [Select]
  1. DIM segxy(7, 4), seglit$(9) '                                   One page clock!  (Let's get SMALL! - Steve Martin)
  2. FOR i = 1 TO 7: READ g$: FOR j = 1 TO 4: READ segxy(i, j): NEXT j: NEXT i
  3. FOR i = 0 TO 9: READ g$, seglit$(i): NEXT i
  4. RANDOMIZE TIMER: bx1 = 44: bx2 = 600: by1 = 155: by2 = 330: xi = RND * 7 + 1: yi = RND * 7 + 1
  5.     t$ = TIME$: x0 = 68: CLS
  6.     FOR i = 1 TO 6
  7.         n = VAL(MID$(t$, VAL(MID$("124578", i, 1)), 1)) '       pick off time digit
  8.         FOR j = 1 TO LEN(seglit$(n)) '                          1 = b&c, etc.
  9.             sn = ASC(MID$(seglit$(n), j, 1)) - 96 '             a=1,b=2, etc.
  10.             x1 = x0 + 8 + segxy(sn, 1) * 40: y1 = 300 + segxy(sn, 2) * 60
  11.             x2 = x0 + 8 + segxy(sn, 3) * 40: y2 = 300 + segxy(sn, 4) * 60
  12.             FOR k = -10 TO 10
  13.                 IF y1 = y2 THEN '                               horizontal segment
  14.                     LINE (x1 + ABS(k) + 1, y1 + k)-(x2 - ABS(k) - 1, y2 + k), _RGB32(1, 1, b)
  15.                 ELSE
  16.                     LINE (x1 + k, y1 + ABS(k) + 1)-(x2 + k, y2 - ABS(k) - 1), _RGB32(1, 1, b)
  17.                 END IF
  18.             NEXT k
  19.         NEXT j
  20.         x0 = x0 + 74 - (i = 2) * 40 - (i = 4) * 40 '            additional increment to jump colons
  21.     NEXT i
  22.     DO: _LIMIT 10 '                                             majority time in this loop
  23.         xx = xx + xi: IF (xx < 1) OR (xx > 99) THEN xi = -xi
  24.         yy = yy + yi: IF (yy < 1) OR (yy > 99) THEN yi = -yi
  25.         xr! = (xx + 20) / 800: yr! = (yy + 20) / 800
  26.         FOR y = by1 TO by2
  27.             FOR x = bx1 TO bx2
  28.                 c = SQR(ABS(x * x * SIN(x * xr!) + y * y * COS(y * yr!))) MOD 150 + 100
  29.                 IF _GREEN(POINT(x, y)) <> 1 THEN PSET (x, y), _RGB32(0, c, c)
  30.             NEXT x
  31.         NEXT y
  32.         _DISPLAY: i$ = INKEY$
  33.     LOOP UNTIL (t$ <> TIME$) OR (LEN(i$) > 0)
  34. LOOP UNTIL i$ = CHR$(27)
  35. DATA a,0,-2,1,-2,b,1,-2,1,-1,c,1,-1,1,0,d,0,0,1,0,e,0,-1,0,0,f,0,-2,0,-1,g,0,-1,1,-1
  36. DATA 0,abcdef,1,bc,2,abged,3,abgcd,4,fgbc,5,acdfg,6,acdefg,7,abc,8,abcdefg,9,abcdfg
It works better if you plug it in.

Offline dajan

  • Newbie
  • Posts: 41
    • View Profile
Re: One page clock
« Reply #1 on: January 19, 2020, 06:35:02 am »
Cool lava clock, thanks.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: One page clock
« Reply #2 on: January 19, 2020, 07:07:18 am »
... and with proper 7-segment display with so few lines of code.  Very nice.
« Last Edit: January 19, 2020, 07:49:31 am by Qwerkey »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: One page clock
« Reply #3 on: January 19, 2020, 12:24:35 pm »
Yes, nice job on segments and condensed code. :)

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: One page clock
« Reply #4 on: January 19, 2020, 01:31:13 pm »
I keep messing with the colors.  This is much nicer.  Some of you might find even better color combos.
A different version has the lava alternating between the digits and background (hence var b). 

Code: QB64: [Select]
  1. DIM segxy(7, 4), seglit$(9) '                                   one page!  (Let's get SMALL! - Steve Martin)
  2. FOR i = 1 TO 7: READ g$: FOR j = 1 TO 4: READ segxy(i, j): NEXT j: NEXT i
  3. FOR i = 0 TO 9: READ g$, seglit$(i): NEXT i
  4. RANDOMIZE TIMER: bx1 = 44: bx2 = 600: by1 = 155: by2 = 330: xi = RND * 7 + 1: yi = RND * 7 + 1
  5.     t$ = TIME$: x0 = 68: CLS
  6.     FOR i = 1 TO 6
  7.         n = VAL(MID$(t$, VAL(MID$("124578", i, 1)), 1)) '       pick off time digit
  8.         FOR j = 1 TO LEN(seglit$(n)) '                          1 = b&c, etc.
  9.             sn = ASC(MID$(seglit$(n), j, 1)) - 96 '             a=1,b=2, etc.
  10.             x1 = x0 + 8 + segxy(sn, 1) * 40: y1 = 300 + segxy(sn, 2) * 60
  11.             x2 = x0 + 8 + segxy(sn, 3) * 40: y2 = 300 + segxy(sn, 4) * 60
  12.             FOR k = -10 TO 10
  13.                 IF y1 = y2 THEN '                               horizontal segment
  14.                     LINE (x1 + ABS(k) + 1, y1 + k)-(x2 - ABS(k) - 1, y2 + k), _RGB32(1, 1, b)
  15.                 ELSE
  16.                     LINE (x1 + k, y1 + ABS(k) + 1)-(x2 + k, y2 - ABS(k) - 1), _RGB32(1, 1, b)
  17.                 END IF
  18.             NEXT k
  19.         NEXT j
  20.         x0 = x0 + 74 - (i = 2) * 40 - (i = 4) * 40 '            additional increment to jump colons
  21.     NEXT i
  22.     DO: _LIMIT 10 '                                             majority time in this loop
  23.         xx = xx + xi: IF (xx < 1) OR (xx > 99) THEN xi = -xi
  24.         yy = yy + yi: IF (yy < 1) OR (yy > 99) THEN yi = -yi
  25.         xr! = (xx + 20) / 800: yr! = (yy + 20) / 800
  26.         FOR y = by1 TO by2
  27.             FOR x = bx1 TO bx2
  28.                 c = SQR(ABS(x * x * SIN(x * xr!) + y * y * COS(y * yr!))) MOD 222 + 32: d = (d + 1) MOD 8
  29.                 IF _GREEN(POINT(x, y)) <> 1 THEN PSET (x, y), _RGB32(c \ (d + 1), c \ (d + 1), c)
  30.             NEXT x
  31.         NEXT y
  32.         _DISPLAY: i$ = INKEY$
  33.     LOOP UNTIL (t$ <> TIME$) OR (LEN(i$) > 0)
  34. LOOP UNTIL i$ = CHR$(27)
  35. DATA a,0,-2,1,-2,b,1,-2,1,-1,c,1,-1,1,0,d,0,0,1,0,e,0,-1,0,0,f,0,-2,0,-1,g,0,-1,1,-1
  36. DATA 0,abcdef,1,bc,2,abged,3,abgcd,4,fgbc,5,acdfg,6,acdefg,7,abc,8,abcdefg,9,abcdfg
It works better if you plug it in.

Offline dajan

  • Newbie
  • Posts: 41
    • View Profile
Re: One page clock
« Reply #5 on: January 19, 2020, 01:57:17 pm »
Wow, that looks almost like CRT display grain simulation.

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: One page clock
« Reply #6 on: January 20, 2020, 12:30:56 am »
Aye, I have weird taste.  The hurdy-gurdy is a fine musical instrument.
It works better if you plug it in.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: One page clock
« Reply #7 on: January 20, 2020, 03:14:16 pm »
I have to admit I found this a fun challenge! Here is a version I came up with today:
Code: QB64: [Select]
  1. _TITLE "Segmented Digital Clock" 'b+ 2020-01-20
  2. CONST xmax = 850, ymax = 200, sq = 25, k = &HFF000000
  3. CONST dat = "1110111000001101111100011111100101110111011101101001001111111111011011"
  4. SCREEN _NEWIMAGE(xmax, ymax, 32)
  5. last = 3599
  6. 1 CLS
  7. last = (last + 1) MOD 20 '<<<<<<<<<<<<<  pick any interval you want (10 * n secs of length)  or comment out 2nd mode
  8. IF last = 0 THEN r = RND * RND: g = RND * RND: b = RND * RND: mode = 1 - mode
  9. FOR x = 0 TO xmax 'background graphics 2 modes
  10.     IF mode THEN LINE (x, 0)-STEP(0, ymax), _RGB32(127 + 127 * SIN(r * (x + last)), 127 + 127 * SIN(g * (x + last)), 127 + 127 * SIN(b * (x + last)))
  11.     IF mode = 0 THEN
  12.         FOR y = 0 TO ymax
  13.             PSET (x, y), _RGB32(127 + 127 * SIN(.1 * r * x * y + last), 127 + 127 * SIN(.155 * g * x * y + last), 127 + 127 * SIN(2 * b * x * y + last))
  14.         NEXT
  15.     END IF
  16. FOR n = 1 TO 8 'clock digits over background
  17.     IF MID$(TIME$, n, 1) = ":" THEN
  18.         LINE ((n - 1) * 4 * sq + 2 * sq, sq + sq)-STEP(sq, sq), k, BF: LINE ((n - 1) * 4 * sq + 2 * sq, sq + 4 * sq)-STEP(sq, sq), k, BF
  19.     ELSE
  20.         drawC (n - 1) * 4 * sq + sq, sq, MID$(dat$, VAL(MID$(TIME$, n, 1)) * 7 + 1, 7)
  21.     END IF
  22. SUB drawC (x, y, c$)
  23.     FOR m = 1 TO 7
  24.         IF VAL(MID$(c$, m, 1)) THEN
  25.             SELECT CASE m
  26.             CASE 1: LINE (x, y)-STEP(sq, 3 * sq), k, BF: CASE 2: LINE (x, y + 2 * sq)-STEP(sq, 4 * sq), k, BF
  27.             CASE 3: LINE (x, y)-STEP(3 * sq, sq), k, BF: CASE 4: LINE (x, y + 2 * sq)-STEP(3 * sq, sq), k, BF
  28.             CASE 5: LINE (x, y + 5 * sq)-STEP(3 * sq, sq), k, BF: CASE 6: LINE (x + 2 * sq, y)-STEP(sq, 3 * sq), k, BF
  29.             CASE 7: LINE (x + 2 * sq, y + 2 * sq)-STEP(sq, 4 * sq), k, BF: END SELECT
  30.         END IF
  31.     NEXT
  32.  

With 35 lines, yeah I double parked ;-)), I had room to have two modes of background graphics

Update: messed around with numbers in mode 0
clock mode 1.PNG
* clock mode 1.PNG (Filesize: 13.89 KB, Dimensions: 852x233, Views: 174)
clock mode 2.PNG
* clock mode 2.PNG (Filesize: 409.52 KB, Dimensions: 854x229, Views: 193)
clock modified mode 0.PNG
* clock modified mode 0.PNG (Filesize: 392.52 KB, Dimensions: 854x233, Views: 201)
« Last Edit: January 20, 2020, 03:39:50 pm by bplus »

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: One page clock
« Reply #8 on: January 20, 2020, 05:49:54 pm »
Very nice, bplus, and educational.  I didn't know _LIMIT could be used in ordinary GOTO type loops.   Of
course your backgrounds are way cooler too.    34 LINES!   With 50 lines I bet you could take over Cuba.
It works better if you plug it in.

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: One page clock
« Reply #9 on: January 20, 2020, 08:52:28 pm »
Combining the best math of Bplus with proper segments, and making it all small.  The icon line is optional. 
Shucks, so is the DEFINT, but maybe it helps the CPU run cooler.   Alt-Enter to make fullscreen.

Code: QB64: [Select]
  1. _TITLE "Clock"
  2. DEFINT A-Z
  3. DIM segxy(7, 4), seglit$(9)
  4. sw = 350: sh = 100: c& = _RGB32(1, 1, 1)
  5. SCREEN _NEWIMAGE(sw, sh, 32)
  6. f$ = "clockx.png": img& = _LOADIMAGE(f$): _ICON img&
  7. _ALLOWFLLSCREEN _SQUAREPIXELS
  8. FOR i = 1 TO 7: READ g$: FOR j = 1 TO 4: READ segxy(i, j): NEXT j: NEXT i
  9. FOR i = 0 TO 9: READ g$, seglit$(i): NEXT i
  10.     t$ = TIME$: showcolon! = TIMER + .5
  11.     DO: _LIMIT 10
  12.         z = (z + 1) MOD 50: IF z = 1 THEN r! = RND: g! = RND: b! = RND
  13.         FOR y = 0 TO sh: FOR x = 0 TO sw
  14.                 xy = (x - sw \ 2) * (y - sh \ 2)
  15.                 PSET (x, y), _RGB32(255 * SIN(.1 * r! * xy + z), 255 * SIN(.155 * g! * xy + z), 255 * SIN(2 * b! * xy + z))
  16.         NEXT x: NEXT y
  17.         x0 = 12
  18.         FOR i = 1 TO 6
  19.             n = VAL(MID$(t$, VAL(MID$("124578", i, 1)), 1))
  20.             FOR j = 1 TO LEN(seglit$(n))
  21.                 sn = ASC(MID$(seglit$(n), j, 1)) - 96
  22.                 x1 = x0 + segxy(sn, 1) * 32: y1 = 87 + segxy(sn, 2) * 38
  23.                 x2 = x0 + segxy(sn, 3) * 32: y2 = 87 + segxy(sn, 4) * 38
  24.                 FOR k = -6 TO 6
  25.                     IF y1 = y2 THEN
  26.                         LINE (x1 + ABS(k) + 1, y1 + k)-(x2 - ABS(k) - 1, y2 + k), c&
  27.                     ELSE
  28.                         LINE (x1 + k, y1 + ABS(k) + 1)-(x2 + k, y2 - ABS(k) - 1), c&
  29.                     END IF
  30.                 NEXT k
  31.             NEXT j
  32.             x0 = x0 + 50 - (i = 2) * 20 - (i = 4) * 20
  33.         NEXT i
  34.         IF TIMER < showcolon! THEN
  35.             FOR i = 0 TO 1
  36.                 x = 112 + i * 118: y = 36: yt = 20
  37.                 LINE (x, y + y0)-STEP(6, 6), c&, BF
  38.                 LINE (x, y + yt)-STEP(6, 6), c&, BF
  39.             NEXT i
  40.         END IF
  41.         _DISPLAY
  42.         i$ = INKEY$: IF i$ = CHR$(27) THEN SYSTEM
  43.     LOOP UNTIL t$ <> TIME$
  44. DATA a,0,-2,1,-2,b,1,-2,1,-1,c,1,-1,1,0,d,0,0,1,0,e,0,-1,0,0,f,0,-2,0,-1,g,0,-1,1,-1
  45. DATA 0,abcdef,1,bc,2,abged,3,abgcd,4,fgbc,5,acdfg,6,acdefg,7,abc,8,abcdefg,9,abcdfg
clockx.png
* clockx.png (Filesize: 11.62 KB, Dimensions: 512x512, Views: 171)
It works better if you plug it in.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: One page clock
« Reply #10 on: January 20, 2020, 10:10:25 pm »
Hi Richard,

What version of QB64 allows line 8?

I must say _FULLSCREEN is crazy! :)

FellippeHeitor

  • Guest
Re: One page clock
« Reply #11 on: January 20, 2020, 10:15:47 pm »
That's a typo. He surely meant
Code: QB64: [Select]

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: One page clock
« Reply #12 on: January 20, 2020, 10:32:25 pm »
Thanks Fellippe, I guess my eyes didn't pickup the missing u.

Oh I guess that brings out some of the color patterns better. :)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: One page clock
« Reply #13 on: January 20, 2020, 11:40:49 pm »
Richard here is lava background effect you might be striving for?

Code: QB64: [Select]
  1. _TITLE "Digital Plasmatic Clock   press spacebar for new coloring set" ' b+ 2020-01-20 translated and modified from SmallBASIC
  2. 'Plasma Magnifico - updated 2015-11-26 for Android
  3. 'This program creates a plasma surface, which looks oily or silky.
  4.  
  5. CONST xmax = 850, ymax = 200, sq = 25
  6. CONST dat = "1110111000001101111100011111100101110111011101101001001111111111011011"
  7.  
  8. TYPE xy
  9.     x AS SINGLE
  10.     y AS SINGLE
  11.     dx AS SINGLE
  12.     dy AS SINGLE
  13. SCREEN _NEWIMAGE(xmax, ymax, 32)
  14. _SCREENMOVE 300, 40
  15.  
  16. DIM c(360) AS _UNSIGNED LONG, p(6) AS xy, f(6)
  17. restart:
  18. r = RND: g = RND: b = RND: i = 0
  19. FOR n = 1 TO 5
  20.     r1 = r: g1 = g: b1 = b
  21.     DO: r = RND: LOOP UNTIL ABS(r - r1) > .2
  22.     DO: g = RND: LOOP UNTIL ABS(g - g1) > .2
  23.     DO: b = RND: LOOP UNTIL ABS(g - g1) > .2
  24.     FOR m = 0 TO 17: m1 = 17 - m
  25.         f1 = (m * r) / 18: f2 = (m * g) / 18: f3 = (m * b) / 18: c(i) = rgbf(f1, f2, f3): i = i + 1
  26.     NEXT
  27.     FOR m = 0 TO 17: m1 = 17 - m
  28.         f1 = (m + m1 * r) / 18: f2 = (m + m1 * g) / 18: f3 = (m + m1 * b) / 18: c(i) = rgbf(f1, f2, f3): i = i + 1
  29.     NEXT
  30.     FOR m = 0 TO 17: m1 = 17 - m
  31.         f1 = (m1 + m * r) / 18: f2 = (m1 + m * g) / 18: f3 = (m1 + m * b) / 18: c(i) = rgbf(f1, f2, f3): i = i + 1
  32.     NEXT
  33.     FOR m = 0 TO 17: m1 = 17 - m
  34.         f1 = (m1 * r) / 18: f2 = (m1 * g) / 18: f3 = (m1 * b) / 18: c(i) = rgbf(f1, f2, f3): i = i + 1
  35.     NEXT
  36.  
  37. FOR n = 0 TO 5
  38.     p(n).x = RND * xmax: p(n).y = RND * ymax: p(n).dx = RND * 2 - 1: p(n).dy = RND * 2 - 1
  39.     f(n) = RND * .1
  40.  
  41. WHILE _KEYDOWN(27) = 0
  42.     IF INKEY$ = " " THEN GOTO restart
  43.     FOR i = 0 TO 5
  44.         p(i).x = p(i).x + p(i).dx
  45.         IF p(i).x > xmax OR p(i).x < 0 THEN p(i).dx = -p(i).dx
  46.         p(i).y = p(i).y + p(i).dy
  47.         IF p(i).y > ymax OR p(i).y < 0 THEN p(i).dy = -p(i).dy
  48.     NEXT
  49.     FOR y = 0 TO ymax - 1 STEP 2
  50.         FOR x = 0 TO xmax - 1 STEP 2
  51.             d = 0
  52.             FOR n = 0 TO 5
  53.                 dx = x - p(n).x: dy = y - p(n).y
  54.                 k = SQR(dx * dx + dy * dy)
  55.                 d = d + (SIN(k * f(n)) + 1) / 2
  56.             NEXT n: d = d * 60
  57.             LINE (x, y)-STEP(2, 2), c(d), BF
  58.         NEXT
  59.     NEXT
  60.     FOR j = 1 TO 3
  61.         IF j = 1 THEN
  62.             c~& = &HFFFFFFFF: offset = -2
  63.         ELSEIF j = 2 THEN
  64.             c~& = &HFF555555: offset = 2
  65.         ELSE
  66.             c~& = &HFFAAAAAA: offset = 0
  67.         END IF
  68.         FOR n = 1 TO 8 'clock digits over background
  69.             IF MID$(TIME$, n, 1) = ":" THEN
  70.                 LINE ((n - 1) * 4 * sq + 2 * sq + offset, sq + sq + offset)-STEP(sq, sq), c~&, BF
  71.                 LINE ((n - 1) * 4 * sq + 2 * sq + offset, sq + 4 * sq + offset)-STEP(sq, sq), c~&, BF
  72.             ELSE
  73.                 drawC (n - 1) * 4 * sq + sq + offset, sq + offset, MID$(dat$, VAL(MID$(TIME$, n, 1)) * 7 + 1, 7), c~&
  74.             END IF
  75.         NEXT
  76.     NEXT
  77.     _DISPLAY
  78.  
  79. FUNCTION rgbf~& (n1, n2, n3)
  80.     rgbf~& = _RGB32(n1 * 255, n2 * 255, n3 * 255)
  81.  
  82. SUB drawC (x, y, c$, c AS _UNSIGNED LONG)
  83.     FOR m = 1 TO 7
  84.         IF VAL(MID$(c$, m, 1)) THEN
  85.             SELECT CASE m
  86.                 CASE 1: LINE (x, y)-STEP(sq, 3 * sq), c, BF
  87.                 CASE 2: LINE (x, y + 2 * sq)-STEP(sq, 4 * sq), c, BF
  88.                 CASE 3: LINE (x, y)-STEP(3 * sq, sq), c, BF
  89.                 CASE 4: LINE (x, y + 2 * sq)-STEP(3 * sq, sq), c, BF
  90.                 CASE 5: LINE (x, y + 5 * sq)-STEP(3 * sq, sq), c, BF
  91.                 CASE 6: LINE (x + 2 * sq, y)-STEP(sq, 3 * sq), c, BF
  92.                 CASE 7: LINE (x + 2 * sq, y + 2 * sq)-STEP(sq, 4 * sq), c, BF
  93.             END SELECT
  94.         END IF
  95.     NEXT
  96.  
  97.  

Not so condensed and I bet it would look great with your digits!

Digital Plasmatic Clock.PNG
* Digital Plasmatic Clock.PNG (Filesize: 59.07 KB, Dimensions: 857x232, Views: 163)
« Last Edit: January 20, 2020, 11:46:50 pm by bplus »

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: One page clock
« Reply #14 on: January 21, 2020, 02:20:18 am »
Oh wow, that plasma is.......mesmerizing, like LSD at age 14.

No, I wasn't striving for that effect, but I sure like it.   I notice you highlighted the digits too.

Short code can be fun.  Unless it calls a GL library, which means it's math far beyond me.

« Last Edit: January 21, 2020, 02:24:43 am by Richard Frost »
It works better if you plug it in.