Analog clock with sounds (iPad/iPhone)

Post Reply
User avatar
Dav
Posts: 279
Joined: Tue Dec 30, 2014 5:12 pm
My devices: iPad Mini, iPod Touch.
Location: North Carolina, USA
Contact:

Analog clock with sounds (iPad/iPhone)

Post by Dav »

This is an analog clock that rings, chimes & ticks. It should look ok in every screen resolution and will resize with screen orientation change. It came about by playing with some old qbasic code posted to our QB forum years ago, so I've mentioned the posters name in this source even though this clock is almost completely different. It did inspire me.

Adjust the m variable in code to test the sounds.

- Dav

Code: Select all


'Analog Clock with sounds
'Based on qbasic code by steven_basic
'Adapted for smart basic by Dav
'should work on iphone or ipad

'clock strikes on the hour,
'chimes every 15,30,45 minutes,
'and ticks every second.

'screen asjusts with orientation.


graphics

shadow on

draw size 10
      
p = 3.141592654 / 180

sw = screen_width()/2
sh = screen_height()/2.3-50

'current screen width
cw = screen_width()

do

   'only update every new second
   if current_second()<>sup then
      sup=current_second()

      'turn off screen writes
      refresh off

      'clear screen to bluish
      graphics clear .2,.3,.4

      'draw a big clock circle
      fill color .3,.3,.7
      fill circle sw, sh size sh
      draw color 0,1,1
      draw circle sw, sh size sh

      'draw all the seconds marks
      for m = 1 to 60
        d = (m*360/60+270) * p
        x1 = cos(d) * sh
        y1 = sin(d) * sh
        x2 = cos(d) * sh / 1.05
        y2 = sin(d) * sh / 1.05
        draw size 5
        'make quarter marks bigger
        if m=15 or m=30 or m=45 or m=60 then
          x2 = cos(d) * sh / 1.15
          y2 = sin(d) * sh / 1.15
          draw size 7
        end if

        'draw marks
        draw line x1+sw, y1+sh to x2+sw, y2+sh
      next m

      'draw second hand
      s =current_second()
      d = (s*360/60+270) * p
      x = cos(d) * sh / 1.14
      y = sin(d) * sh / 1.14
      draw color .7,.7,.7
      draw size 3 
      draw line sw, sh to sw + x, sh + y 

      draw size 10

      'draw minute hand
      m = current_minute()
      '=====================================
      'below is for testing only, to hear 
      'all the quarterly and hourly chimes. 
      'when second hand is 0 you will hear.
      'change m to 0,15,30 or 45 to test it.
      'm=0 '<<<< uncomment to test chimes.
      '=====================================
      d = (m*360/60+270) * p
      x = COS(d) * sh / 1.24
      y = SIN(d) * sh / 1.24
      draw color 1,1,1
      draw line sw, sh to sw + x, sh + y 

      'draw hour hand
      h = current_hour()
      d = (h*360/12+270+(m*60/180))*p
      x = cos(d) * sh / 1.74 
      y = sin(d) * sh / 1.74
      draw color 1,1,.9
      draw line sw, sh to sw + x, sh + y 

      'draw center circle
      draw color 0,0,0
      draw circle sw, sh size 7

      'update screen
      refresh on

      'handle ticks and chimes...

      'big chimes on the hour
      if m=0 and s = 0 then
        g$ = "14:hc5hg#4a#4wd#4hd#4a#c5wg#4hc5a#4g#wd#"
        if h >12 then h=h-12 '12 hr format
        for t = 1 to h 'one for each hour
          g$=g$&"w,14:(c3e3gc4)"
        next t
        notes set g$
        notes play
      end if

      'small chimes on 15,30&45 minutes...
      if m=15 and s=0 then
        notes set "14:hc5hg#4a#4wd#4"
        notes play
      end if
      if m=30 and s=0 then 
        notes set "14:hc5hg#4a#4wd#4hd#4a#c5wg#4"
        notes play
      end if
      if m=45 and s = 0 then
       notes set "14:hc5hg#4a#4wd#4hd#4a#c5wg#4hc5a#4g#wd#"
       notes play
      end if
           
      'else play tick every new second
      'if chimes not playing....
      if notes_time() => notes_length() then
        notes set "115:c6"
        notes play
      end if

      'if screen turned, update...
      if cw <> screen_width() then
        sw = screen_width()/2
        sh = screen_height()/2.3-50
        cw = screen_width()
      end if
  
   end if
   
until forever

end

Last edited by Dav on Tue Feb 17, 2015 1:22 pm, edited 1 time in total.

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Analog clock with sounds (iPad/iPhone)

Post by Mr. Kibernetik »

iPhone 6 screenshots:

Image

Image

User avatar
Dav
Posts: 279
Joined: Tue Dec 30, 2014 5:12 pm
My devices: iPad Mini, iPod Touch.
Location: North Carolina, USA
Contact:

Re: Analog clock with sounds (iPad/iPhone)

Post by Dav »

Thanks for the screenshots. Looks like I need to change the size for when in landscape mode on iPhone. I think this would be better:

sh = screen_height()/2.3-50

I'll edit the code with the change.

- Dav

Post Reply