locked
An analog clock in 15 lines of program ( Small Basic ) :) RRS feed

  • Question

  • Rolling on PC works well.

    1) Can be programmed in less lines of program?

    2) Unfortunately the internet does not work with Silverligh. Why? WVQ463

    3) For analog clock, which would be minimal code to work on SilverLigh with the fewest lines of program?

    Note: Sorry for my English (Used google translate)

    p="1=256;2=297;3=312;4=298;5=255;6=196;7=136;8=95;9=78;10=85;11=128;12=191;13=92;14=135;15=192;16=248;17=294;18=310;19=293;20=253;21=192;22=137;23=89;24=75;"
    For i=1 To 12
      GraphicsWindow.DrawBoundText(p[i],p[i+12],20,i)
    EndFor
    arrowH=Shapes.AddLine(100/2,100/2,100,100)  'arrow Hour
    arrowM=Shapes.AddLine(130/2,130/2,130,130)  'arrow Minute
    arrowS=Shapes.AddLine(160/2,160/2,160,160)  'arrow Second
    Shapes.Move(arrowH,400/2-100/2,400/2-100/2)  'move to center arrow Hour
    Shapes.Move(arrowM,400/2-100/2-(130-100)/2,400/2-100/2-(130-100)/2)  'move to center arrow Minute
    Shapes.Move(arrowS,400/2-100/2-(160-100)/2,400/2-100/2-(160-100)/2)  'move to center arrow Second)
    LOOP:
    Shapes.Rotate(arrowS,(Clock.Second*6)-135)  
    Shapes.Rotate(arrowM,(Clock.Minute*6)+(0.1*Clock.Second)-135)   
    Shapes.Rotate(arrowH,(30*Clock.Hour)+(0.5*Clock.Minute)-135)   
    Goto LOOP
    Thank you for your suggestions.



    jalpc


    • Edited by jalpc Tuesday, November 18, 2014 11:19 AM
    Tuesday, November 18, 2014 11:15 AM

Answers

    • Marked as answer by jalpc Tuesday, November 18, 2014 7:47 PM
    Tuesday, November 18, 2014 1:32 PM
  • 14 lines XD

    For I = 1 To 12
      GraphicsWindow.DrawText(195+Math.Cos(Math.GetRadians((I*30) - 90))*125,195+Math.Sin(Math.GetRadians((i*30) - 90))*125,i)
      EndFor
    arrowH=Shapes.AddLine(100/2,100/2,100,100)  'arrow Hour
    arrowM=Shapes.AddLine(130/2,130/2,130,130)  'arrow Minute
    arrowS=Shapes.AddLine(160/2,160/2,160,160)  'arrow Second
    Shapes.Move(arrowH,400/2-100/2,400/2-100/2)  'move to center arrow Hour
    Shapes.Move(arrowM,400/2-100/2-(130-100)/2,400/2-100/2-(130-100)/2)  'move to center arrow Minute
    Shapes.Move(arrowS,400/2-100/2-(160-100)/2,400/2-100/2-(160-100)/2)  'move to center arrow Second)
    LOOP:
    Shapes.Rotate(arrowS,(Clock.Second*6)-135)  
    Shapes.Rotate(arrowM,(Clock.Minute*6)+(0.1*Clock.Second)-135)   
    Shapes.Rotate(arrowH,(30*Clock.Hour)+(0.5*Clock.Minute)-135)   
    Goto LOOP


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    • Marked as answer by jalpc Wednesday, November 19, 2014 11:23 AM
    Wednesday, November 19, 2014 12:17 AM
    Answerer
  • 11 lines XD

    For I = 1 To 12
      GraphicsWindow.DrawText(195+Math.Cos(Math.GetRadians((I*30) - 90))*125,195+Math.Sin(Math.GetRadians((i*30) - 90))*125,i)
      EndFor
    Shapes.Move(Shapes.AddLine(100/2,100/2,100,100),400/2-100/2,400/2-100/2)  'arrow Hour
    Shapes.Move(Shapes.AddLine(130/2,130/2,130,130),400/2-100/2-(130-100)/2,400/2-100/2-(130-100)/2)  'arrow Minute
    Shapes.Move(Shapes.AddLine(160/2,160/2,160,160),400/2-100/2-(160-100)/2,400/2-100/2-(160-100)/2)  'arrow Second
    LOOP:
    Shapes.Rotate("Line3",(Clock.Second*6)-135)  
    Shapes.Rotate("Line2",(Clock.Minute*6)+(0.1*Clock.Second)-135)   
    Shapes.Rotate("Line1",(30*Clock.Hour)+(0.5*Clock.Minute)-135)   
    Goto LOOP


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    • Marked as answer by jalpc Wednesday, November 19, 2014 11:24 AM
    Wednesday, November 19, 2014 3:24 AM
    Answerer
  • 10-lines. XD

    LN="1=70;2=90;3=110;4=0;5=0;6=0;7=0;8=0;9=0;10=0;11=0;12=0"
    For i = 1 To 12
      GraphicsWindow.DrawText(295+125*Math.Sin(Math.GetRadians(i*30)),195-125*Math.Cos(Math.GetRadians(i*30)),i)
      Shapes.Move(Shapes.AddLine(0,0,0,-LN[i]),300,200)  '
    EndFor
    While "True"
      Shapes.Rotate("Line1",(30*Clock.Hour)+(0.5*Clock.Minute))
      Shapes.Rotate("Line2",(Clock.Minute*6)+(0.1*Clock.Second))
      Shapes.Rotate("Line3",(Clock.Second*6))
    EndWhile

    • Marked as answer by jalpc Wednesday, November 19, 2014 11:24 AM
    Wednesday, November 19, 2014 5:01 AM
    Answerer

All replies

    • Marked as answer by jalpc Tuesday, November 18, 2014 7:47 PM
    Tuesday, November 18, 2014 1:32 PM
  • Thank you for your help.

    I had information about the rotation of line and triangle from point 0.0, but not to work remotely in the same way.

    As I've tried to study AddRectangle (which is easier) and is in 18 lines (work on SilverLigh): MPP372

    Excuse my English.

    In Spanish:

    --------------

    Gracias por su ayuda.
    Yo tenia informacion sobre la rotacion de linea y triangulo desde punto 0,0 , pero no que no trabajara en remoto de la misma forma. 
    Mientras lo estudio lo he intentado con AddRectangle (que es mas facil) y queda en 18 lineas (trabaja bien en SilverLight).
    Perdone mi ingles.

    ------------------

    p="1=256;2=297;3=312;4=298;5=255;6=196;7=136;8=95;9=78;10=85;11=128;12=191;13=92;14=135;15=192;16=248;17=294;18=310;19=293;20=253;21=192;22=137;23=89;24=75;"
    ag="1=6;2=6;3=4;4=67;5=93;6=113;7=0;8=0;9=0;"
    For i=1 To 12
      GraphicsWindow.DrawBoundText(p[i],p[i+12],20,i)
    EndFor
    For i=1 To 3
      a[i]=Shapes.AddRectangle( ag[i], ag[i+3])
    EndFor
    LOOP:
    Program.Delay(1000)
    an[1]=(30*Clock.Hour)+(0.5*Clock.Minute) 
    an[2]=(Clock.Minute*6)+(0.1*Clock.Second)  
    an[3]=(Clock.Second*6)
    For i = 1 To 3
      Shapes.Rotate(a[i], an[i])  
      Shapes.Move(a[i],200+((ag[i+3]-ag[i]+ag[i+6])/2)*Math.Sin(Math.GetRadians(an[i]))-(ag[i]/2),200-((ag[i+3]-ag[i]+ag[i+6])/2)*Math.Cos(Math.GetRadians(an[i]))-(ag[i+3]/2))
    EndFor  
    Goto LOOP 


    jalpc


    • Edited by jalpc Tuesday, November 18, 2014 7:53 PM
    Tuesday, November 18, 2014 7:51 PM
  • 14 lines XD

    For I = 1 To 12
      GraphicsWindow.DrawText(195+Math.Cos(Math.GetRadians((I*30) - 90))*125,195+Math.Sin(Math.GetRadians((i*30) - 90))*125,i)
      EndFor
    arrowH=Shapes.AddLine(100/2,100/2,100,100)  'arrow Hour
    arrowM=Shapes.AddLine(130/2,130/2,130,130)  'arrow Minute
    arrowS=Shapes.AddLine(160/2,160/2,160,160)  'arrow Second
    Shapes.Move(arrowH,400/2-100/2,400/2-100/2)  'move to center arrow Hour
    Shapes.Move(arrowM,400/2-100/2-(130-100)/2,400/2-100/2-(130-100)/2)  'move to center arrow Minute
    Shapes.Move(arrowS,400/2-100/2-(160-100)/2,400/2-100/2-(160-100)/2)  'move to center arrow Second)
    LOOP:
    Shapes.Rotate(arrowS,(Clock.Second*6)-135)  
    Shapes.Rotate(arrowM,(Clock.Minute*6)+(0.1*Clock.Second)-135)   
    Shapes.Rotate(arrowH,(30*Clock.Hour)+(0.5*Clock.Minute)-135)   
    Goto LOOP


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    • Marked as answer by jalpc Wednesday, November 19, 2014 11:23 AM
    Wednesday, November 19, 2014 12:17 AM
    Answerer
  • 11 lines XD

    For I = 1 To 12
      GraphicsWindow.DrawText(195+Math.Cos(Math.GetRadians((I*30) - 90))*125,195+Math.Sin(Math.GetRadians((i*30) - 90))*125,i)
      EndFor
    Shapes.Move(Shapes.AddLine(100/2,100/2,100,100),400/2-100/2,400/2-100/2)  'arrow Hour
    Shapes.Move(Shapes.AddLine(130/2,130/2,130,130),400/2-100/2-(130-100)/2,400/2-100/2-(130-100)/2)  'arrow Minute
    Shapes.Move(Shapes.AddLine(160/2,160/2,160,160),400/2-100/2-(160-100)/2,400/2-100/2-(160-100)/2)  'arrow Second
    LOOP:
    Shapes.Rotate("Line3",(Clock.Second*6)-135)  
    Shapes.Rotate("Line2",(Clock.Minute*6)+(0.1*Clock.Second)-135)   
    Shapes.Rotate("Line1",(30*Clock.Hour)+(0.5*Clock.Minute)-135)   
    Goto LOOP


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    • Marked as answer by jalpc Wednesday, November 19, 2014 11:24 AM
    Wednesday, November 19, 2014 3:24 AM
    Answerer
  • 11-line analog clock for both desktop and browser: LTP201.

    Nonki Takahashi

    Wednesday, November 19, 2014 4:47 AM
  • 10-lines. XD

    LN="1=70;2=90;3=110;4=0;5=0;6=0;7=0;8=0;9=0;10=0;11=0;12=0"
    For i = 1 To 12
      GraphicsWindow.DrawText(295+125*Math.Sin(Math.GetRadians(i*30)),195-125*Math.Cos(Math.GetRadians(i*30)),i)
      Shapes.Move(Shapes.AddLine(0,0,0,-LN[i]),300,200)  '
    EndFor
    While "True"
      Shapes.Rotate("Line1",(30*Clock.Hour)+(0.5*Clock.Minute))
      Shapes.Rotate("Line2",(Clock.Minute*6)+(0.1*Clock.Second))
      Shapes.Rotate("Line3",(Clock.Second*6))
    EndWhile

    • Marked as answer by jalpc Wednesday, November 19, 2014 11:24 AM
    Wednesday, November 19, 2014 5:01 AM
    Answerer
  • Wow!!!! ...... Fantastic !!!! .... XD XD XD
    Not amused 40 years ago I programmed.
    You have got to remember my young years with the ZX-81 Spectrum and Commodore 64.
    I'm happy in my old age ......

    Thanks for your great contributions.

    In Spanish :.

    ---------------

    Fantástico !!!!
    Hace 40 años que no me divertia programando.
    Vds han conseguido que recuerde mi años jovenes con el Spectrum Zx-81 y el Commodore 64. 
    Estoy feliz en  mi vejez ......

    Gracias por sus geniales aportaciones.

    --------------


    jalpc


    • Edited by jalpc Wednesday, November 19, 2014 11:25 AM
    Wednesday, November 19, 2014 11:23 AM
  • Nice challenge above guys,

    Beat that, ...  0 lines :-}

    Friday, November 21, 2014 12:00 PM
    Answerer
  • Nice challenge above guys,

    Beat that, ...  0 lines :-}

    Aggggggggg !!!!!!!! ........ :) 


    jalpc

    Friday, November 21, 2014 1:22 PM