Just a simple example. I hope you like it...
Source available here
Simple Analog Clock in Hollywood
Re: Simple Analog Clock in Hollywood
I just updated the download link above... I Fixed some errors in my framework and added more functionality...
Now all it takes to write nice analog clock is this:
Now all it takes to write nice analog clock is this:
Code: Select all
;
; Simple Analog Clock in Hollywood
;
@APPICON { Ic16x16 = "icons/my16x16icon.png",
Ic24x24 = "icons/my24x24icon.png",
Ic32x32 = "icons/my32x32icon.png",
Ic48x48 = "icons/my48x48icon.png",
Ic128x128 = "icons/my128x128icon.png",
Ic256x256 = "icons/my256x256icon.png",
Ic512x512 = "icons/my512x512icon.png"}
@DISPLAY {Width = 200, Height = 200, Borderless = True, Title = "Hollywood Clock"}
; Include game framework
@INCLUDE "hgf/game.hws"
Const #SMALL_DOT_SIZE = 1
Const #LARGE_DOT_SIZE = 4
; Game setup
Function game.load()
EscapeQuit(True)
game:setUpdateRate(1)
time = GetTime(True)
EndFunction
; Game state "main" draw function
Function game.draw()
Cls(#WHITE)
drawClock()
EndFunction
; game state "main" update function
Function game.update(dt)
time = GetTime(True)
EndFunction
; Draw the analog clock
Function drawClock()
; Get seconds, minutes and hours.
Local hours = MidStr(time, 0, 2)
Local minutes = MidStr(time, 3, 2)
Local seconds = MidStr(time, 6, 2)
; Get the angles of the clock hands.
Local angsec = 90 - seconds * 6
Local angmin = 90 - minutes * 6
Local anghour = 90 - (hours * 5 + minutes / 10) * 6
Local cp = point:new( { x = game.buffer.r:dx()/2, y = game.buffer.r:dy()/2 } ) ; Center point
Local cr = cp.x - 8 ; Clock radius
Local shr = cp.x - 16 ; Clock's second hand radius
Local mhr = cp.x - 20 ; Clock's minute hand radius
Local hhr = cp.x - 32 ; Clock's hour hand radius
SetFillStyle(#FILLNONE)
game.buffer:drawRect(game.buffer.r, #BLACK) ; Draw outline of the window rectangle
SetFillStyle(#FILLCOLOR)
; Draw minute and second dots.
For Local i = 0 To 59
game.buffer:drawCircle(point:new( { x = cp.x - #SMALL_DOT_SIZE, y = cp.y - #SMALL_DOT_SIZE } ):circlept(cr, i * (360 / 60) ), #SMALL_DOT_SIZE, #BLACK)
Next
; Draw hour dots.
For Local i = 0 To 11
game.buffer:drawCircle(point:new( { x = cp.x - #LARGE_DOT_SIZE, y = cp.y - #LARGE_DOT_SIZE } ):circlept(cr, i * (360 / 12) ), #LARGE_DOT_SIZE, #BLACK)
Next
; Draw clock's second, minute and hour hands.
game.buffer:drawLine(cp, cp:circlept(shr, angsec), #BLACK, { Thickness = 2 } )
game.buffer:drawLine(cp, cp:circlept(mhr, angmin), #BLACK, { Thickness = 6 } )
game.buffer:drawLine(cp, cp:circlept(hhr, anghour), #BLACK, { Thickness = 8 } )
EndFunction
; Here we go!
game:go()
Re: Simple Analog Clock in Hollywood
Added a couple of more functions...
Now this works too:
Now this works too:
Code: Select all
;
; Simple Analog Clock in Hollywood
;
@APPICON { Ic16x16 = "icons/my16x16icon.png",
Ic24x24 = "icons/my24x24icon.png",
Ic32x32 = "icons/my32x32icon.png",
Ic48x48 = "icons/my48x48icon.png",
Ic128x128 = "icons/my128x128icon.png",
Ic256x256 = "icons/my256x256icon.png",
Ic512x512 = "icons/my512x512icon.png"}
@DISPLAY {Width = 200, Height = 200, Borderless = True, Title = "Hollywood Clock"}
; Include game framework
@INCLUDE "hgf/game.hws"
Const #SMALL_DOT_SIZE = 1
Const #LARGE_DOT_SIZE = 4
; Game setup
Function game.load()
EscapeQuit(True)
game:setUpdateRate(1)
time = GetTime(True)
EndFunction
; Game state "main" draw function
Function game.draw()
Cls(#WHITE)
drawClock()
EndFunction
; game state "main" update function
Function game.update(dt)
time = GetTime(True)
EndFunction
; Draw the analog clock
Function drawClock()
; Get seconds, minutes and hours.
Local hours = MidStr(time, 0, 2)
Local minutes = MidStr(time, 3, 2)
Local seconds = MidStr(time, 6, 2)
; Get the angles of the clock hands.
Local angsec = 90 - seconds * 6
Local angmin = 90 - minutes * 6
Local anghour = 90 - (hours * 5 + minutes / 10) * 6
Local cp = point:new( { x = game.buffer.r:dx()/2, y = game.buffer.r:dy()/2 } ) ; Center point
Local cr = cp.x - 8 ; Clock radius
Local shr = cp.x - 16 ; Clock's second hand radius
Local mhr = cp.x - 20 ; Clock's minute hand radius
Local hhr = cp.x - 32 ; Clock's hour hand radius
SetFillStyle(#FILLNONE)
game.buffer:drawRect(game.buffer.r, #BLACK) ; Draw outline of the window rectangle
SetFillStyle(#FILLCOLOR)
; Draw minute and second dots.
For Local i = 0 To 59
game.buffer:drawCircle(cp:subxy(#SMALL_DOT_SIZE):circlept(cr, i * (360 / 60) ), #SMALL_DOT_SIZE, #BLACK)
Next
; Draw hour dots.
For Local i = 0 To 11
game.buffer:drawCircle(cp:subxy(#LARGE_DOT_SIZE):circlept(cr, i * (360 / 12) ), #LARGE_DOT_SIZE, #BLACK)
Next
; Draw clock's second, minute and hour hands.
game.buffer:drawLine(cp, cp:circlept(shr, angsec), #BLACK, { Thickness = 2 } )
game.buffer:drawLine(cp, cp:circlept(mhr, angmin), #BLACK, { Thickness = 6 } )
game.buffer:drawLine(cp, cp:circlept(hhr, anghour), #BLACK, { Thickness = 8 } )
EndFunction
; Here we go!
game:go()
Re: Simple Analog Clock in Hollywood
Hey! Thanks so much! It´s good to learn!
- Juan Carlos
- Posts: 891
- Joined: Mon Sep 06, 2010 1:02 pm
Re: Simple Analog Clock in Hollywood
Thank you jalih for your examples, with them this forum seens a good programming forum....
P.D.: I'll like put my own examples but I'm very anarchic programming.
P.D.: I'll like put my own examples but I'm very anarchic programming.
Re: Simple Analog Clock in Hollywood
I just updated the download link...
Modifications:
- I rewrote my frameworks primitives library (primitives.hws). Now it serves as a good example on howto do Object Oriented Programming with Hollywood.
- Some small modifications and cleanups to clock.hws
Take a look and let me know, if I broke anything in the process...
Modifications:
- I rewrote my frameworks primitives library (primitives.hws). Now it serves as a good example on howto do Object Oriented Programming with Hollywood.
- Some small modifications and cleanups to clock.hws
Take a look and let me know, if I broke anything in the process...