Advertisement
jalih

Analog clock in FTN95

Oct 27th, 2012
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     module clock
  2.       use mswin
  3.       implicit none
  4.  
  5.       integer :: width = 240, height = 240
  6.       character (len=2), parameter :: hours(0:11) = &
  7.         (/'03','02','01','12','11','10','09','08','07','06','05','04'/)
  8.  
  9.       contains
  10.  
  11.         integer function draw_func()
  12.           integer :: i, resize
  13.           integer :: radius
  14.           integer :: xcenter, ycenter
  15.           integer :: angsecs, angmins, anghours
  16.           integer :: s, m, h
  17.           integer :: cx, cy ! point on a circle
  18.           integer :: handx(5), handy(5)
  19.           character (len=8) :: time@, time
  20.  
  21.           resize=clearwin_info@('GRAPHICS_RESIZING')
  22.           if(resize.EQ.1) then
  23.             width = clearwin_info@('GRAPHICS_WIDTH')
  24.             height = clearwin_info@('GRAPHICS_DEPTH')
  25.           end if
  26.  
  27.           if(width.GT.height) then
  28.             radius = height
  29.           else
  30.             radius = width
  31.           end if
  32.  
  33.           radius = radius / 2 - 8
  34.  
  35.           time = time@()
  36.  
  37.           read(time(1:2),*) h
  38.           read(time(4:5),*) m
  39.           read(time(7:8),*) s
  40.  
  41.           xcenter = width/2
  42.           ycenter = height/2
  43.  
  44.           angsecs = 90 - s * 6
  45.           angmins = 90 - m * 6
  46.           anghours = 90 - (h * 5 + m / 10) * 6
  47.  
  48.           ! Draw clock frame
  49.           call draw_filled_ellipse@(xcenter,ycenter,radius,radius,rgb@(255,255,255))
  50.           call draw_ellipse@(xcenter,ycenter,radius+1,radius+1,rgb@(0,0,0))
  51.           call draw_filled_ellipse@(xcenter,ycenter,3,3,rgb@(0,0,0))
  52.  
  53.           ! Draw second and minute dots
  54.           do i = 0, 59, 1
  55.             call circlept(xcenter, ycenter, int(radius * 0.95), i * (360 / 60))
  56.             call draw_filled_ellipse@(cx,cy,1,1, rgb@(0,0,0))
  57.           end do
  58.  
  59.           ! Draw hour dots
  60.           call size_in_pixels@(14,14)
  61.           call bold_font@(1)
  62.           do i = 0, 11, 1
  63.             call circlept(xcenter, ycenter, int(radius * 0.95), i * (360 / 12))
  64.             call draw_filled_ellipse@(cx,cy,2,2, rgb@(0,0,0))
  65.             call circlept(xcenter-12, ycenter+7, int(radius * 0.80), i * (360 / 12))
  66.             call draw_characters@(hours(i),cx,cy,rgb@(0,0,0))
  67.           end do
  68.  
  69.           ! draw hands
  70.           handx(1) = xcenter; handy(1) = ycenter
  71.           call circlept(xcenter, ycenter, int(radius * 0.25), angsecs-3)
  72.           handx(2) = cx; handy(2) = cy
  73.           call circlept(xcenter, ycenter, int(radius * 0.90), angsecs)
  74.           handx(3) = cx; handy(3) = cy
  75.           call circlept(xcenter, ycenter, int(radius * 0.25), angsecs+3)
  76.           handx(4) = cx; handy(4) = cy
  77.           handx(5) = xcenter; handy(5) = ycenter
  78.           call draw_filled_polygon@(handx,handy,5,rgb@(0,0,0))          
  79.           call circlept(xcenter, ycenter, int(radius * 0.25), angmins-8)
  80.           handx(2) = cx; handy(2) = cy
  81.           call circlept(xcenter, ycenter, int(radius * 0.85), angmins)
  82.           handx(3) = cx; handy(3) = cy
  83.           call circlept(xcenter, ycenter, int(radius * 0.25), angmins+8)
  84.           handx(4) = cx; handy(4) = cy
  85.           call draw_filled_polygon@(handx,handy,5,rgb@(0,0,0))          
  86.           call circlept(xcenter, ycenter, int(radius * 0.25), anghours-10)
  87.           handx(2) = cx; handy(2) = cy
  88.           call circlept(xcenter, ycenter, int(radius * 0.65), anghours)
  89.           handx(3) = cx; handy(3) = cy
  90.           call circlept(xcenter, ycenter, int(radius * 0.25), anghours+10)
  91.           handx(4) = cx; handy(4) = cy
  92.           call draw_filled_polygon@(handx,handy,5,rgb@(0,0,0))
  93.  
  94.          
  95.           draw_func=1
  96.  
  97.           contains
  98.                  
  99.             subroutine circlept(x, y, r, deg)
  100.               integer, intent(in) :: x, y, r, deg
  101.               real :: rad
  102.          
  103.               rad = deg * 3.14159 / 180
  104.               cx = x + Cos(rad) * r
  105.               cy = y - Sin(rad) * r
  106.             end subroutine circlept
  107.            
  108.         end function draw_func
  109.  
  110.     end module clock
  111.  
  112.  
  113.     winapp
  114.       use clock
  115.       implicit none
  116.  
  117.       integer :: i
  118.  
  119.       i=winio@('%ww[no_border,no_maxbox]&')
  120.       i=winio@('%ca[FTN95 Clock]&')
  121.       i=winio@('%pv%^gr[user_resize,grey,rgb_colours]&',width,height,draw_func)
  122.       i=winio@('%dl', 1.0D0, draw_func)
  123.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement