none
Challenge of the Month - October 2014

    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.

    Also post feedback on the kind of challenges that you want to see more of in the future.

    Number Challenge

    Write a program to convert between Roman Numerals and numbers.

    Game Challenge

    Write a 'moon lander' type program.

    Graphical Challenge 1

    Make an animated growing tree.

    From seed to seedling to sapling to tree with branches.

    Tip: Perhaps consider using zoom and opacity with the animation.

    Graphical Challenge 2

    Make a color wheel or color cube.

    You may need to use GetPixel, SetPixel and GetColorFromRGB methods in the GraphicsWindow object.

    Can you find a faster way (not using extensions of course).

    Use this with the 'Introducing Small Basic' paint program that comes with the installation (copied below) to select brush colours.

    GraphicsWindow.MouseMove = OnMouseMove
    GraphicsWindow.MouseDown = OnMouseDown
    Sub OnMouseDown
      prevX = GraphicsWindow.MouseX
      prevY = GraphicsWindow.MouseY
    EndSub
    Sub OnMouseMove
      x = GraphicsWindow.MouseX
      y = GraphicsWindow.MouseY
      If (Mouse.IsLeftButtonDown) Then
        GraphicsWindow.DrawLine(prevX, prevY, x, y)
      EndIf
      prevX = x
      prevY = y
    EndSub

    Community Suggestion (By Nonki)

    1. Make a TODO list management program
    2. Draw (or fill) a pentagon
    3. Make a Sunrise Animation

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

    Wednesday, October 1, 2014 6:59 PM
    Moderator

All replies

  • I made Small Paint for Graphical Challenge 2: MQB393-0.

    Screen shot of a program Small Paint


    Nonki Takahashi


    Friday, October 3, 2014 5:24 AM
    Moderator
  • Nonki's Small Paint - What a top program!

    Classy UI by Nonki T

    I like because:

    • intuitive simple UI
    • it works beautifully in the browser. Strong program.
    • best scribbler I've seen

    Would love (without cluttering the UI):

    • brush size selector
    • rubber
    • background colour and pic b/ground selector
    • save image, (would be great if we could copy SB to the clipboard)

    Very Nice!


    Saturday, October 4, 2014 6:19 AM
    Moderator
  • Number Challenge

    Write a program to convert between Roman Numerals and numbers.  RPC590

    Saturday, October 4, 2014 11:12 AM
    Answerer
  • seems like conversion to Roman has issues, try 1986 and you will see.

    May be this below might work better.

    symbol="1=M;2=D;3=C;4=L;5=X;6=V;7=I"
    symbolValue="1=1000;2=500;3=100;4=50;5=10;6=5;7=1"
    Controls.ButtonClicked=onclicked
    init()

    Sub onclicked
       RomanNumber=""
       
        InputNumber= Controls.GetTextBoxText(InputValue)
       
        For i=1 To 7
          D= Math.Floor(InputNumber/symbolValue[i])
          For j= 1 to D
                RomanNumber=text.Append(RomanNumber, symbol[i])
          EndFor
         InputNumber= Math.Remainder(InputNumber,symbolValue[i])
       endfor
       t1= Text.Append(Controls.GetTextBoxText(InputValue), " ==> ")
       txt=Text.Append(t1,RomanNumber)
          GraphicsWindow.DrawText(5,150,txt)

    EndSub

    Sub init
      InputValue= Controls.AddTextBox(100,15)
      Controls.SetSize(InputValue,200,35)
      Btn1= Controls.AddButton("Convert to Roman",50,100)
     GraphicsWindow.DrawText(10,10,"Value")

    EndSub

    Monday, October 6, 2014 7:33 PM
  • Welcome, siv_1234.

    Your code is compact!  But Roman Numeral for 900:

    CM (NaochanON)
    DCCCC (siv_1234)

    NaochanON's conversion is better.

    This is my sample: BNJ520.  (from Arabic to Roman)


    Nonki Takahashi


    Tuesday, October 7, 2014 3:45 AM
    Moderator
  • seems like conversion to Roman has issues, try 1986 and you will see.

    May be this below might work better.

    This will work well.

    symbol="1=M;2=D;3=C;4=L;5=X;6=V;7=I"
    symbolValue="1=1000;2=500;3=100;4=50;5=10;6=5;7=1"
    Controls.ButtonClicked=onclicked
    init()

    Sub onclicked
      RomanNumber=""
      InputNumber= Controls.GetTextBoxText(InputValue)      '  1954
      For i=1 To 7 Step 2
        D= Math.Floor(InputNumber/symbolValue[i])           ' 1  ,  9  ,  5,  4
        If D<4 Then
          For j= 1 to D
            RomanNumber=text.Append(RomanNumber, symbol[i])
          EndFor
        ElseIf D=4 then
          RomanNumber=text.Append(RomanNumber, symbol[i]+symbol[i-1])  '400=CD  40=XL  4=IV
        ElseIf D=5 then
          RomanNumber=text.Append(RomanNumber, symbol[i-1])            ' 500=D   50=L  5=V
        ElseIf 5<D and D<9 then
          RomanNumber=RomanNumber+symbol[i-1]
          For j= 1 to D-5
            RomanNumber=text.Append(RomanNumber, symbol[i])
          EndFor
        ElseIf D=9 then
          RomanNumber=text.Append(RomanNumber, symbol[i]+symbol[i-2])  '  900= CM  90=XC  9=IX
        EndIf
        InputNumber= Math.Remainder(InputNumber,symbolValue[i])
      endfor
      t1= Text.Append(Controls.GetTextBoxText(InputValue), " ==> ")
      txt=Text.Append(t1,RomanNumber)
      GraphicsWindow.DrawText(5,150,txt)
    EndSub

    Sub init
      InputValue= Controls.AddTextBox(100,15)
      Controls.SetSize(InputValue,200,35)
      Btn1= Controls.AddButton("Convert to Roman",50,100)
      GraphicsWindow.DrawText(10,10,"Value")
    EndSub


    Tuesday, October 7, 2014 4:01 AM
    Answerer
  • @Nonki Takahashi

    Hi,

    This was my first stab at small basic. Since I didn't read about Roman numeric system, I screwed it up.

    EDIT:

    I'll see if I can come up with a better solution.

    • Edited by siv_1234 Tuesday, October 7, 2014 3:11 PM didn't test the fix yet
    Tuesday, October 7, 2014 3:05 PM
  • This is my sample for community suggestion 1 by Nonki: QXW739.

    Run this program after [Import] in Small Basic IDE.

    1 TODO=Write a blog post.;until=2014-10-09;
    
    ? h
    a    : add TODO
    d<n> : delete TODO <n>
    h    : show this help
    q    : save and exit
    1 TODO=Write a blog post.;until=2014-10-09;
    
    ? a
    TODO? Write a blog post.
    Due date(yyyy-mm-dd)? 2014-10-13
    TODO=Write a blog post.;until=2014-10-13;
    1 TODO=Write a blog post.;until=2014-10-09;
    2 TODO=Write a blog post.;until=2014-10-13;
    
    ?

    Nonki Takahashi



    Wednesday, October 8, 2014 7:32 AM
    Moderator
  • By the way, this is my sample from Roman to Arabic Numerals: CJV067.

    Nonki Takahashi

    Friday, October 10, 2014 2:58 AM
    Moderator
  • This is my first step for game challenge: DTF312.  Just an animation.  (Alpha Version)

    Screen shot of a program Luna Module 0.1a


    Nonki Takahashi

    Friday, October 10, 2014 3:05 AM
    Moderator
  • Number Challenge

    http://smallbasic.com/program/?TVJ007

    Friday, October 10, 2014 5:19 PM
  • Number Challenge

    http://smallbasic.com/program/?TVJ007

    Welcome, Miskei.
    Your code is very simple.

    And I know your Small Basic games in your site well.
    Thanks.


    Nonki Takahashi

    Saturday, October 11, 2014 12:29 AM
    Moderator
  • SLOW!!!

    Controls.TextTyped = OnTextTyped
    a="0=1000;1=900;2=500;3=400;4=100;5=90;6=50;7=40;8=10;9=9;10=5;11=4;12=1"
    r="0=M;1=CM;2=D;3=CD;4=C;5=XC;6=L;7=XL;8=X;9=IX;10=V;11=IV;12=I"
    For sz=1 to 3999
      i=0
      rn=""
      d=sz
        While (d<>0)
          While (d>=a[i])
            d=d-a[i]
            rn=rn+r[i]
          EndWhile
          i=i+1
        EndWhile
      roman[sz]=rn
      arab[rn]=sz
    EndFor  
    be=Controls.AddTextBox(0,10)
    ki=Controls.AddTextBox(200,10)
    Sub OnTextTyped
      szam=text.ConvertToUpperCase(Controls.GetTextBoxText(be))
      If szam>0 And szam<4000 Then
        Controls.SetTextBoxText(ki,roman[Controls.GetTextBoxText(be)])
        Else
          Controls.SetTextBoxText(ki,arab[Controls.GetTextBoxText(be)])
        EndIf
    EndSub


    Sunday, October 12, 2014 9:16 AM
  • This is my sample for community suggestion 3 by Nonki: KNP762.

    Screen shot of a program Sun Rise Animation 0.1


    Nonki Takahashi

    Tuesday, October 14, 2014 2:34 PM
    Moderator
  • This is my second step for game challenge : KXQ212.

    Hit up arrow key to fire.
    I feel that falling speed is too fast.  Something wrong?

    Screen shot of a program Gravity 0.1


    Nonki Takahashi



    Wednesday, October 15, 2014 9:31 AM
    Moderator
  • I found the bug!  Updated version is KXQ212-0.

    Nonki Takahashi

    Wednesday, October 15, 2014 10:18 AM
    Moderator
  • This is my third step for game challenge: KXQ212-2.

    I added velocity (speed) meter.  Please click with mouse once in remote.  Then hit up arrow key to fire. 

    Screen shot of a program Gravity 0.31


    Nonki Takahashi


    Thursday, October 16, 2014 8:37 AM
    Moderator
  • This is my fourth step for game challenge: DTF312-0.

    Added side thruster controlled by right and left arrow keys.

    Screen shot of a program Lunar Module 0.4a


    Nonki Takahashi

    Friday, October 17, 2014 3:01 AM
    Moderator
  • This is my sample for community suggestion 2 by Nonki.

    ' set graphics window size
    gw = 598
    gh = 428
    GraphicsWindow.Width = gw
    GraphicsWindow.Height = gh
    ' set parameters for regular polygon
    n = 5         ' pentagon
    x1 = gw / 2   ' center
    y1 = gh / 2
    r = 100       ' circumradius
    x2 = x1       ' top vertex
    y2 = y1 - r
    RegularPolygon()
    Sub RegularPolygon
      For i = 1 To n
        a = 2 * Math.Pi * i / n
        x3 = x1 + r * Math.Sin(a)
        y3 = y1 - r * Math.Cos(a)
        GraphicsWindow.FillTriangle(x1, y1, x2, y2, x3, y3) ' fill
        GraphicsWindow.DrawLine(x2, y2, x3, y3)             ' draw
        x2 = x3
        y2 = y3
      EndFor
    EndSub
    


    Nonki Takahashi

    Wednesday, October 22, 2014 11:53 PM
    Moderator
  • Hi Nonki, sorry but could not resist with FKF180 and WKL485 (for LDExt)   ;-)

    Thursday, October 23, 2014 7:23 PM
    Answerer
  • Hi Nonki, sorry but could not resist with FKF180 and WKL485 (for LDExt)   ;-)

    Cyclopentane and Vitruvian Man!


    Nonki Takahashi


    Friday, October 24, 2014 10:01 PM
    Moderator
  • These are my ideas for a future challenge.

    1. Match file names with wild card "*" or "?" in Program.Directory and make a list as an array.  "*" matches any characters including null and "?" matches any character.
    2. Make a polyline editor.  Edited polyline can be saved and opened as a file.
    3. Make a world clock.

    Nonki Takahashi

    Monday, October 27, 2014 11:25 AM
    Moderator
  • Here is my submission for the Lander challenge. I have been tweaking this one on and off for a while. I focused on making an accurate simulation rather than worrying about the graphics. The moon's gravity is exactly 0.25g and the max thrust of the lander is exactly that of the LEM.

    To land safely you need to be traveling slower than 2m per second.

    ImportCode: TQL943

    Enjoy!

    Tuesday, October 28, 2014 5:33 PM
    Answerer
  • Here is my submission for the Lander challenge. I have been tweaking this one on and off for a while. I focused on making an accurate simulation rather than worrying about the graphics. The moon's gravity is exactly 0.25g and the max thrust of the lander is exactly that of the LEM.

    To land safely you need to be traveling slower than 2m per second.

    ImportCode: TQL943

    Enjoy!

    Nice program, Coding Cat!  I couldn't succeed yet...
    Screen shot of a program Lunar Lander coded by Coding Cat

    Nonki Takahashi

    Thursday, October 30, 2014 4:48 AM
    Moderator
  • This is my fifth step for game challenge: DTF312-1.

    Screen shot of a program Lunar Module 0.5b


    Nonki Takahashi

    Friday, October 31, 2014 12:24 PM
    Moderator
  •  

    Game Challenge 'moon lander'   PNR896-0 (Play localy.  ) 

    Rocket.png and Fire.png are downloaded from here .

    ' https://docs.google.com/file/d/0B8mzGh2PVjd-LVp5Umw2QVJYUDg/edit   <-----  Rocket.png
    ' https://docs.google.com/file/d/0B8mzGh2PVjd-T2MwZFgycGFaRjg/edit   <-----  Fire.png

     


    • Edited by NaochanONEditor Saturday, November 1, 2014 12:55 PM code changed
    Saturday, November 1, 2014 12:39 PM
    Answerer