sticky
Challenge of the Month - January 2017

    General discussion

  • 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.

    Keyboard Challenges

    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

    Small Challenges

    • 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.

    Physics Challenge

    • 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

    Community Suggestions

    • Meteor shower Quadrantids (by YLed) LINK

    Do you have an idea for a future challenge? Please post it here!

    Sunday, January 01, 2017 6:58 PM
    Moderator

All replies

  • mahreen miangul
          Cycle ID WZL194 Doggy ID NFS704 ID KWL554 Lion ID WHX921 Sprites ID PVW118

                                          mussa-maina

    Tuesday, January 03, 2017 4:15 AM
  • mussamaina, I love your keyboard challenges.  Thanks!

    Nonki Takahashi

    Tuesday, January 03, 2017 5:01 AM
    Moderator
  • I present to you my planetarium amateur version 1.0
    As 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)

                                         

    (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 days   
      Venus: 224.7 days 
     Earth: 365,24 days
     Moon: 27.3 days
     Mars: 686,97 days
     Jupiter: 11.86 years.

     Saturn: 29,457 years

    program no: CZT922




    • Edited by YLedEditor Tuesday, January 03, 2017 1:59 PM orthographs, and colors add
    Tuesday, January 03, 2017 1:51 PM
    Answerer
  • 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).

    Tuesday, January 03, 2017 3:44 PM
    Moderator
  • @Litdev

    Fantastic explanation of how to use Newton's gravitational law in a program.!!

    Thanks ! i will try your approach :)

    Tuesday, January 03, 2017 5:26 PM
    Answerer
  • leo's house update: kwl554-0

    Wednesday, January 04, 2017 8:29 AM
  • @litdev

    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,

    thanks!

    program: BBT384

    Wednesday, January 04, 2017 5:11 PM
    Answerer
  • @YLed,

    This looks mostly right:

    1] θ should be updated by v

    θ=θ+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:

    v=1/r/Math.SquareRoot(r)

    4] Centre the earh and sun on coordinates with

    Shapes.Move(sun, Cx-F-10,Cy-10)

    Shapes.Move(earth,x-5,y-5)

    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.

    Wednesday, January 04, 2017 7:55 PM
    Moderator
  • Hi litdev !

    wonderful your program JLL862

    With all that, i'm going to do something good !


    • Edited by YLedEditor Saturday, January 14, 2017 3:15 PM mars opposition too difficult to compute i tried 10 days without sucess
    Wednesday, January 04, 2017 10:58 PM
    Answerer
  •       mahreen miangul Animation ID HXP150 mussa-maina
    Thursday, January 05, 2017 3:58 PM
  •       mahreen miangul Animation ID HXP150 mussa-maina

                          ' mahreen miangul
    ' Animation JanUrary 2017
    GraphicsWindow.Width = 1080
    GraphicsWindow.height = 420
    GraphicsWindow.BackgroundColor = "rosybrown"

    'Data table
    draw[1] = "X=405;Y=150;W=20;H=70;color=green;tag=1"
    draw[2] = "X=425;Y=150;W=20;H=70;color=green;tag=2"
    draw[3] = "X=410;Y=110;W=30;H=70;color=green;tag=3"
    draw[4] = "X=410;Y=190;W=10;H=70;color=green;tag=eye"
    draw[5] = "X=430;Y=190;W=10;H=70;color=green;tag=mouth"
    draw[6] = "X=410;Y=190;W=30;H=25;color=green;tag=6"
    draw[7] = "X=415;Y=120;W=10;H=10;color=blue;tag=7"
    draw[8] = "X=425;Y=120;W=10;H=10;color=blue;tag=8"
    draw[9] = "X=420;Y=122;W=5;H=5;color=white;tag=eye"
    draw[10] = "X=430;Y=122;W=5;H=5;color=white;tag=eye"
    draw[11] = "X=425;Y=133;W=5;H=15;color=yellow;tag=11"
    draw[12] = "X=420;Y=151;W=15;H=5;color=orange;tag=mouth"


    'Draw outline
    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"])
      Program.Delay(300)
    EndFor

    '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)
      Program.Delay(500)
    EndFor

    'Animate shapes - eyes and mouth
    dZ = 0.1
    zoom = 1
    While 0=0
      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)
        EndIf
      EndFor
      If zoom = 0 Or zoom = 1 Then
        dZ = -dZ
      EndIf
      Program.Delay(100)
    EndWhile


    Thursday, January 05, 2017 4:05 PM
  • la linea + dog+ leo's house MLP507
    Friday, January 06, 2017 8:31 AM
  • plays silent night w random pics from flickr w effect snow: GFF236

    Saturday, January 07, 2017 8:39 AM
  • First step on Golf: CHW085

    Second step on golf: CHW085-0

    *Improved gameplay (fps)

    *There is a problem with ball's velocity and collision detection system 



    Sunday, January 08, 2017 1:16 PM
  •  Animation of Building ID TFX886

                 from mussa-maina with love
          mahreen miangul

    Friday, January 13, 2017 5:35 AM
  • Mars, Earth, Jupiter orbits with Newton Law

    1)display velocity of each planets.

    2)ellipse orbits

    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
    Saturday, January 14, 2017 2:43 PM
    Answerer
  • Make Turtle Write MIANGUL
                                                   ID DHK491       mahreen miangul

                                                                 with love from mussa-maina

    Saturday, January 14, 2017 5:39 PM
  • challenge: Write a program to work like a simple musical instrument using keyboard keys to play notes

    here is my solution: MMC531

    touch your computer keyboard letter A and it will produce note C

    letter allowed:  A,W,S,E,D,F,T,G,Y,H,U,J,K

    Saturday, January 14, 2017 8:36 PM
    Answerer
  • Yled, 

    When I run your program for 100 Jupiter-years, Earth is far into year  1181 !


    Jan [ WhTurner ] The Netherlands

    Sunday, January 15, 2017 2:26 PM
    Answerer
  • @whturner

    Hi !

    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
    Sunday, January 15, 2017 3:35 PM
    Answerer
  • updated a bit and corrected N letter:DHK491-0


    • Edited by Tryhest Sunday, January 15, 2017 7:23 PM
    Sunday, January 15, 2017 7:22 PM
  • 3 scenes anim: CJG174


    • Edited by Tryhest Sunday, January 15, 2017 10:01 PM
    Sunday, January 15, 2017 9:59 PM