How to create analog clock using Small Basic
Here is a new episode of our introduction to programming using the ultra-simple language, specifically designed to restore the idea of a fun and entertaining programming as in 80 years. Today we will discover a new feature: timers!
Small Basic
Small Basic is a language introduction to programming that emphasizes the idea of fun in programming. It is for this new Microsoft initiative aimed at encouraging more young people (7 to 77 years) to discover the joys of programming.
- Download Small Basic
- Install it by following the wizard step by step
- At launch, Small Basic automatically recognizes the language of your system and adapts accordingly. In other words, the software displays an interface and help when launched on a Windows system.
- In the following two steps, we will discover a new direction (Timer) function and the amazing publication very Web 2.0.
re: How to create analog clock using Small Basic
Using Timers
The Timers can trigger the execution of a subprogram (SUB) at regular intervals. It is very good in games to move enemies or decorative elements. This is also useful when you want to automatically refresh a display.
To implement a Timer, you must use the new keyword and TIMER functions.
- We start by defining an interval using: TIMER.INTERVAL = x (where x is a number in milliseconds). For example: "Timer.Interval = 1000" trigger an event every second.
- Then what tells the program sub-program must perform by giving it a name with TIMER.TICK = NameOfSub
This gives something like this:
...
Timer.Interval = 500
Timer.Tick = MoveTimer
...
Sub MoveTimer
'Insert the code for moving enemies
EndSub
- To pause a timer, use the command: TIMER.PAUSE ()
- To restart a suspended Timer, use the command: TIMER.RESUME ()
re: How to create analog clock using Small Basic
Delivering a clock
The following program displays an analog clock with hands for hours and minutes, and its second hand seconds.
Code:
'Beginning of program
'
xRAD = math.pi / 180
'
GraphicsWindow.Height = 200
GraphicsWindow.Width = 200
GraphicsWindow.BackgroundColor = "Black"
GraphicsWindow.Show ()
'
Timer.Interval = 1000
ShowTime Timer.Tick =
'
'End of program
'
Sub ShowTime
Sec = 6 * Clock.Second
Clock.Minute * min = 6
Heu Clock.Hour * = 30
'
GraphicsWindow.Clear ()
GraphicsWindow.PenColor = "Yellow"
GraphicsWindow.DrawEllipse (0,0,200,200)
'
X = 100 + (90 * Math.sin (xRAD * Sec))
Y = 100 - (90 * Math.Cos (xRAD * Sec))
GraphicsWindow.DrawLine (100.100, X, Y)
'
GraphicsWindow.PenColor = "Green"
X = 100 + (80 * Math.sin (xRAD * Min))
Y = 100 - (80 * Math.Cos (xRAD * Min))
GraphicsWindow.DrawLine (100.100, X, Y)
'
GraphicsWindow.PenColor = "Red"
X = 100 + (60 * Math.sin (xRAD Heu *))
Y = 100 - (60 * Math.Cos (Heu xRAD *))
GraphicsWindow.DrawLine (100.100, X, Y)
'
GraphicsWindow.PenColor = "Cyan"
GraphicsWindow.DrawBoundText (70150100, Clock.Time)
EndSub
re: How to create analog clock using Small Basic
Publish and share
Small Basic now offers a very simple way to share programs with friends.
Once your program is fully finished and completed, simply click "Publish."
Your source code is then sent to a special server that stores all Microsoft programs that are submitted. Once the server has received your program it returns a code (a sort of reference number).
You can then communicate this code to your friends.
They can then click Import and enter the code you've provided so that they can automatically download the source code and run it on their own Small Basic.
Thus, to simply download the sample clock of the previous step without having to redo:
- Start Small Basic
- Click on the Import icon
- Enter MLT668-1
- Wait a few seconds the download code in a new window.
This publication is very convenient to share programs and discover the products of other enthusiasts Small Basic.
Some examples of emergency to discover:
- Play LIGHTS OUT DanAwesome: VDK353
- Super Pong: MDJ923
- Bricks: QRQ360