These challenges are intended for people who are learning to program for the first time or for those returning to programming who want to start using Small Basic. Some will be easy, some will be hard - but they will all make you think, and more importantly be GREAT FUN!
Please post your solutions / partial solutions / questions / feedback etc. into this thread that will remain 'sticky' for the month. The only rule is that your solution must use standard Small Basic methods (no extensions).
It would be good if people could post their problems with these challenges so that a discussion can start so that everyone can learn from each other.
We may extend these challenges over into a second month if solutions and questions are still coming in.
Suggested last month by mussamaina, some challenges using keyboard keys:
- Write a program to move a sprite on the GraphicsWindow using arrow keys. Try to make it as smooth and responsive as possible.
- Extend the program to make the sprite jump when the space key is pressed.
- Extend the program to drag and drop the sprite using the mouse when left mouse button is down.
- Write a program to make the GraphicsWindow behave like the TextWindow so you can emulate as many of the TextWindow commands as possible, like WriteLine, Read etc.
- Write a program to work like a simple musical instrument using keyboard keys to play notes
- Write a Turtle program to draw a triangle, square, pentagon and circle.
- Write a program to count down from 100 in 1 second intervals.
- Write a program to add 10 numbers entered by a user.
- Write a program to draw a hand.
- Write a program to randomly position, color, size and rotate 100 squares in the GraphicsWindow.
- Write a program to display the planets moving round the sun - try to get the orbit times roughly correct.
- Add the moon orbiting the earth.
- Add some comets with elliptical orbits around the sun - they move faster when near the sun.
Elliptical orbits were first described by Johannes Kepler and later explained by Isaac Newton.
TextWindow Game Challenge
- Write a TextWindow based adventure game. The important part will be to plan out the game first, like what the player needs to find along the way to progress.
GraphicsWindow Game Challenge
- Write a simple golf putting game like http://thesimplearcade.com/play/mini-putt.html.
- Perhaps several coders could collabrate to add new holes or even write the game so that it is easy to add levels.
- Meteor shower Quadrantids (by YLed) LINK
Do you have an idea for a future challenge? Please post it here!
- Edited by litdevModerator Sunday, January 01, 2017 10:25 PM typo
I present to you my planetarium amateur version 1.0As I am an amateur astronomer, my program is amateur.The orbital period of each planets is correct. This gives an idea of the relative translational speed of the planets relative to the Earth.There are Mercury, Venus, Earth with the Moon, Mars, Jupiter and Saturn.
The size of the planets are not scale for the need of the demonstration. The distances between the planets and the Sun are not to scale, because Jupiter and Saturn would have been outside of the screen.A counter. left increases, each complete revolution of Earth (1 year), the beginning is 2017. Also, for the purposes of the demo, the planets start all aligned.
Colors use in this demo: Mercury (white), Venus (light magenta), Earth (blue), Moon ( white ), Mars ( red) , Jupiter and Saturn ( yellow ochre)According to Kepler's laws of planetary motion :(1) The orbit of a planet is year ellipse with the Sun at one of the two foci.(2) A line segment joining a planet and the Sun sweeps out equal areas during equal intervals of time.(3) The square of the orbital period of a planet is proportional to the cube of the semi-major axis of its orbit.
For the time being, I used circles and constant speeds, but I work on a version that would be based on the Kepler's laws.Here is the orbital periods used in the program, according to Wikipedia:Mercury: 88 daysVenus: 224.7 daysEarth: 365,24 daysMoon: 27.3 daysMars: 686,97 daysJupiter: 11.86 years.
Saturn: 29,457 years
program no: CZT922
- Edited by YLedEditor Tuesday, January 03, 2017 1:59 PM orthographs, and colors add
YLed great animation.
Newtons gravity law (gravity force = centrifugal force)
G.M.m/r2 = m.v2/r
- G is gravitational constant
- M is mass of sun
- m is planet mass
- r is distance between them
- v is planet velocity
So G.M = v2.r and is independent of the planet mass!
Therefore v = sqrt(G.M/r), since G.M is constant v is propotional to1/sqrt(r)
To prove Keplers laws you need some calculus, also invented by Newton.
To do an asteroid motion, all we need is equation of an ellipse (one focii at the sun) and modify the speed according to 1/sqrt(r), r is distance to sun.
The center (C) is at (Cx,Cy) and the major (CA) and minor (CB) distances are a and b.
The sun is at (Cx-F,Cy), where F = sqrt(a.a - b.b)
Any coordinate on the orbit (x,y) has coordinates (Cx+a.Cos(θ), Cy+b.Sin(θ)), where θ is a rotation angle in radians.
One last thing, we can get the correct speed effect by updating θ proportionally by 1/(r.sqrt(r)) each time step, since:
distance to move = v.dt = r.dθ, hence dθ = (v/r).dt and is therefore proportional to 1/r/sqrt(r).
- Edited by litdevModerator Tuesday, January 03, 2017 4:55 PM
Hi ,Following your approach, using the gravitational force equation and the equation of the centrifugal force, I made this little program that I would like you to check the formulas and the Small Basic construction.
It's the Earth orbiting the Sun. Well some I exaggerated the eccentricity of the elllipse for the purpose of the demonstration. The Sun is at one of the foci of the ellipse. But above all, I wish you checked how I integrated the formula for correct speed effect by updating θ proportionally by 1/(r.sqrt(r)) of the Earth in my program,
This looks mostly right:
1] θ should be updated by v
2] r is not the sun-earch distance, perhaps this:
dx = Cx-F-x
dy = Cy-y
r=Math.SquareRoot(dx*dx+dy*dy) ' update r distance sun-earth orbit
3] v should be:
4] Centre the earh and sun on coordinates with
With these maybe change the scaling (multipier to v)
My mods to your program, BBT384-0
Any one I made to test, JLL862 - hard to get scales right and still see anything, so the moon orbits are wrong and this is not our solar system - just a random set of planets.
mahreen miangul Animation ID HXP150 mussa-maina
' mahreen miangul
' Animation JanUrary 2017
GraphicsWindow.Width = 1080
GraphicsWindow.height = 420
GraphicsWindow.BackgroundColor = "rosybrown"
draw = "X=405;Y=150;W=20;H=70;color=green;tag=1"
draw = "X=425;Y=150;W=20;H=70;color=green;tag=2"
draw = "X=410;Y=110;W=30;H=70;color=green;tag=3"
draw = "X=410;Y=190;W=10;H=70;color=green;tag=eye"
draw = "X=430;Y=190;W=10;H=70;color=green;tag=mouth"
draw = "X=410;Y=190;W=30;H=25;color=green;tag=6"
draw = "X=415;Y=120;W=10;H=10;color=blue;tag=7"
draw = "X=425;Y=120;W=10;H=10;color=blue;tag=8"
draw = "X=420;Y=122;W=5;H=5;color=white;tag=eye"
draw = "X=430;Y=122;W=5;H=5;color=white;tag=eye"
draw = "X=425;Y=133;W=5;H=15;color=yellow;tag=11"
draw = "X=420;Y=151;W=15;H=5;color=orange;tag=mouth"
For i = 1 To Array.GetItemCount(draw)
GraphicsWindow.PenColor = draw[i]["color"]
GraphicsWindow.DrawEllipse(draw[i]["X"], draw[i]["Y"], draw[i]["W"], draw[i]["H"])
'Add and Animate shapes for solid color
GraphicsWindow.PenWidth = 0
For i = 1 To Array.GetItemCount(draw)
GraphicsWindow.BrushColor = draw[i]["color"]
shp[i] = Shapes.AddEllipse(draw[i]["W"], draw[i]["H"])
Shapes.Animate(shp[i], draw[i]["X"], draw[i]["Y"], 500)
'Animate shapes - eyes and mouth
dZ = 0.1
zoom = 1
zoom = zoom - dZ
For i = 1 To Array.GetItemCount(draw)
If Array.ContainsValue(draw[i] "eye") Then
Shapes.Zoom(shp[i] 1 zoom)
ElseIf Array.ContainsValue(draw[i] "mouth") Then
Shapes.Zoom(shp[i] zoom zoom)
If zoom = 0 Or zoom = 1 Then
dZ = -dZ
Mars, Earth, Jupiter orbits with Newton Law
1)display velocity of each planets.
3)with years counter for each planets, not accurate for Jupiter ? can't find why !
for 11.86 Earth years we should have 1 year or 1 orbit for Jupiter, in this demo it is 12.25+something.?
maybe because i used the ' Semi-major axis 5.202 60 AU value for all planets ?
any idea ???
4) in accordance with the law of Kepler, planets increasing of speed at the approach of the Sun
program no: RNH977
- Edited by YLedEditor Saturday, January 14, 2017 3:01 PM
Yes so it is nearly accurate,
1 Jupiter year = 11,86 Earth year according to : how-long-is-a-year-on-jupiter
so 100 Jupiter years = 1186 Earth years
1181 years, there is 5 years of error, i' am searching why, maybe the ellipse of Jupiter is not at the correct pixels.
for Earth it is 1 AU distance from the Sun, i set the ellipse to 100 pixels ( ratio 1:100)
for Jupiter it is ' Semi-major axis 5.20260 AU so i set the ellipse to 520 pixels.
maybe the .0260 decimal increases the margin of error ?
- Edited by YLedEditor Sunday, January 15, 2017 3:44 PM