Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A clock
#1
i don't know when I wrote this ... found it in a folder.

Code:
set window "Clock", 400, 400, 0, 0
set redraw off


do
    t = datetime()
    set color 128, 128, 128
    cls
    set color 0, 0, 0
    rx = width(primary)/2
    ry = height(primary)/2
    draw ellipse rx, ry, rx, ry, true
    set color 255, 255, 255
    draw ellipse rx, ry, rx - 4, ry - 4, true
    set color 200, 0, 0
   
    a = rad(360*t.second/60 - 90)
    DrawThickLine(rx, ry, rx + cos(a)*(rx*0.9 - 4), ry + sin(a)*(ry*0.9 - 4), 4)
   
    set color 0, 0, 0
    a = rad(360*t.minute/60 - 90)
    DrawArrow(rx, ry, rx + cos(a)*(rx*0.8 - 4), ry + sin(a)*(ry*0.8 - 4), 12)
   
    a = rad(360*(t.hour%12)/12 - 90)
    DrawArrow(rx, ry, rx + cos(a)*(rx*0.6 - 4), ry + sin(a)*(ry*0.6 - 4), 16)
   
    draw ellipse rx, ry, 8, 8, true
   
    redraw
    fwait 1
loop

function DrawThickLine(x1, y1, x2, y2, thickness)
    dx = x2 - x1
    dy = y2 - y1
    k = 0.5*thickness/sqr(dx*dx + dy*dy)
    ddx = -dy*k
    ddy = dx*k
    p = [
        round(x1 + ddx), round(y1 + ddy),
        round(x2 + ddx), round(y2 + ddy),
        round(x2 - ddx), round(y2 - ddy),
        round(x1 - ddx), round(y1 - ddy)]
    draw poly p, true
endfunc

function DrawArrow(x1, y1, x2, y2, thickness)
    dx = x2 - x1
    dy = y2 - y1
    k = 0.5*thickness/sqr(dx*dx + dy*dy)
    ddx = -dy*k
    ddy = dx*k
    p = [
        x1, y1,
        x1*0.25 + x2*0.75 - ddx, y1*0.25 + y2*0.75 - ddy,
        x2, y2,
        x1*0.25 + x2*0.75 + ddx, y1*0.25 + y2*0.75 + ddy]
       
    draw poly p, true
endfunc
Reply
#2
Cool... An analogue clock... I can remember, decades ago, a meme involving an analogue clock and a computer program...
A young guy was boasting that he wrote a 'clock' program and was proud to show it off to his friends. The cartoon showed an image of a young guy with his computer monitor strapped to his wrist. Sorry. Your program brought back that particular memory... Never the less... a cool clock...
May your journey be free of incident.
Live long and prosper.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)