none
Challenge of the Month - July 2014 RRS feed

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

    Small Challenges

    1. Write a program that moves a ball when the mouse is moved (the ball stays under the mouse).
    2. Extend the program above to leave a trail behind the moving ball.
    3. Write a TextWindow program to enter a date and then validate that it has the correct format (e.g. DD/MM/YYYY or MM/DD/YYYY).  Make sure it handles leap years!
    4. Write a program to replace all spaces in some text with '_'.
    5. Write a program to create 5 buttons in a vertical column, when each is clicked it plays a different sound or musical note.
    6. Write a program to generate random letters (a-z).

    Group Challenge

    This challenge is to create an extensible 'Paint' program with plugins.

    There are several paint type programs in Small Basic - they mostly consist of drawing on a window following a mouse when a mouse button is clicked and held down.

    The idea of this challenge is:

    1. to write the main program in such a way that it is easy for people to add their plugins.
    2. to write fun plugins.

    A plugin may be as simple as changing the line width or color, or more complicated like drawing stars or any other feature.

    The plugins should:

    1. be a single subroutine.
    2. have a name that can be obtained from the plugin, so that it can be selected.
    3. either perform drawing actions when the mouse is moved while a mouse button is down or change some property.

    Quite a bit of thought will be needed to design the program so that plugins can work well, be selectable etc.  Perhaps plugins need to also be added to a text file list of plug-ins?

    Examples of plugins could be:

    1. Change brush color.
    2. Change pen thickness.
    3. Draw random colored stars as the mouse moves.
    4. Eraser.

    The program itself should have only a very basic plugin example and it is up to other contributors to create their plug-ins meeting the required specification.

    I recommend some discussion/collaboration of ideas before coding, perhaps start from the example in the 'Introducing Small Basic' guide.

    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

    Game Challenge

    Write an 'air hockey' 2 player game.

    Community Suggestions (by Athasak)

    1. Make a unit converter. For example 1 kilogram is 1000 grams. So make a program to convert the kilogram to 1000 grams.
    2. Make a basic chat program (Example JDT558).
    3. Make a RGB (red - green - blue) menu with sliding bars that changes the background color (Example NHJ269).
    4. Make a "Scroll Down Bar", you know... a bar that scrolls down some text or shapes or images (Example ZDP541).
    5. Make a program to change pages of text when you click and drag the page to the left edge of the window (in order to see the next page) and when you click and drag the page to the right edge of the window (in order to see the previous page). It may sound kinda confusing so here is an example SFR639.


    Community Suggestions (by Nonki)

    1. Create a international version of Hello World program.
    2. Create a program to show Small Basic source.  Comment lines must be shown as green.
    3. Draw a picture of a regular triangle.

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

    Tuesday, July 1, 2014 6:01 PM
    Moderator

All replies

  • Small Challenges

    1. ZLS137
    2. JBZ860
    5. FGL119
    6. KRC805

    Group Challenge

    How to download:

    1. Click this link: athasak.blogspot.gr

    2. Press "Ctrl + F"

    3. Type in "Digital Canvas"

    4. Click the title

    5. Copy & Paste the code of this page in "Microsoft Small Basic"

    How to use:

    The program won't work properly if your resolution is smaller than 1366 x 768.

    Hotkeys:

    Press "F" to get into "Fill Screen Mode" then select a color. To exit this mode press "F" again.

    Press "C" to clear the screen.

    Press "Space" to change from white to black and the opposite.

    Press "O" to get the opposite color. Works only for the colors that have an opposite one and of course black and white.

    Press "S" to open the "Shapes" menu.

    Press "Enter" to open the "RGB" menu. The "RGB" mode doesn't work because I didn't know how to do one back then. (yeah this program is old but maybe I'll make another one :)

    Press "Escape" to close currently active menu.

    Wednesday, July 2, 2014 10:48 AM
  • Let's start to talk about Group Challenge!

    My first suggestion for this challenge is to talk about UI of this paint program.  How should we call plug-ins?  My idea is to push function keys (F1-F9).  F10 is assigned as the same as Alt key, so input focus will be lost after pushing them.  Then the menu may be as follows.

    F1:Change Brush Color | F2:Change ... 


    Nonki Takahashi

    Wednesday, July 2, 2014 5:06 PM
    Moderator
  • So each plugin will correspond to a function key.

    Perhaps, as well as the plug-in subroutine, there is a config file where some basic details of the plug-in are set, like the plug-in name and perhaps its key or some other configuration information.

    To add a plug-in, the plug-in writer would need to

    • add their subroutine to the code
    • add some code to call the subroutine (probably just an entry in an ElseIf list somewhere to call the subroutine as required when the key or button for the sub is made).
    • perhaps add to a config file to at least say what key is needed, or name for a button (and maybe other bits like it changes colors or properties 'called once' or does the drawing 'called as the mouse moves' etc).  This could be configurable in the subroutine if not in a config file.
    Wednesday, July 2, 2014 5:41 PM
    Moderator
  • Or using buttons like this:

    GraphicsWindow.FontName = "Courier New"
    GraphicsWindow.FontSize = 30
    button[1] = Controls.AddButton("■", 10, 10)    ' Change Brush Color
    button[2] = Controls.AddButton("□", 60, 10)    ' Change Pen Color
    button[3] = Controls.AddButton("━", 110, 10)  ' Chage Pen Width
    button[4] = Controls.AddButton("★", 160, 10)  ' Draw Stars
    button[5] = Controls.AddButton("◧", 210, 10)  ' Erase Canvas
    Thursday, July 3, 2014 5:32 AM
    Moderator
  • Community Suggestions (by Nonki)

    1. Import ID: FBW453

    Thursday, July 3, 2014 10:24 AM
  • This is my alpha version of game challenge: KLB414-2.

    Screen shot of a program Air Hockey 0.3a

    I need to add collision detect between puck and mallet.  How to do this is described in a TechNet Wiki article written by litdev.


    Nonki Takahashi

    Thursday, July 3, 2014 12:35 PM
    Moderator
  • Hi, I'm back! My Computer was Shutdown forever but I formated it (st like this...:D) Now I am intrseted with hockey game but Nonki made it first. But Nonki I don't like Your hockey game because movement is minimum and ball is going always same ways.!

    Thanks Everybody good night!

    Thursday, July 3, 2014 10:57 PM
  • Athasak,

    Wow!  It's complete!  I love it!

    Screen shot of a program International Hello World


    Nonki Takahashi

    Friday, July 4, 2014 4:03 AM
    Moderator
  • Second agenda about Group Challenge is the interface between main program and plug-ins.

    A plug-in should be a single subroutine.

    So, at least, mouse handlers OnMouseDown and OnMouseMove will be common ones for every plug-in.


    Nonki Takahashi

    Friday, July 4, 2014 4:23 AM
    Moderator
  • ProfessionalOfSmallBasic,

    Congratulation for the recovery of your computer.  I hope to see your hockey game.  Thanks.


    Nonki Takahashi

    Friday, July 4, 2014 4:27 AM
    Moderator
  • Thanks Nonki,

    I started my own air hockey game.

    Friday, July 4, 2014 10:42 AM
  • This is my first step of game challenge:

     import id:GBS016

    Friday, July 4, 2014 11:24 AM
  • Community Suggestions (by Nonki)

    2. Import ID: GCW421

    Saturday, July 5, 2014 2:51 PM
  • Community Suggestions (by Nonki)

    I am not sure if it is really a regular triangle, so I don't think this is a solution but here it is anyway :)

    QQK823

    Sunday, July 6, 2014 9:07 AM
  • Community Suggestions (by Nonki), 3. Draw a picture of a regular triangle

    ID: NDK700

    • Edited by Pappa LapubEditor Tuesday, July 8, 2014 8:24 PM removed underlaying link-Silverlight errors
    Sunday, July 6, 2014 6:25 PM
    Answerer
  • Pappa Lapub,

    Wow, you've created a nice control!  But, something is wrong in zooming scale... 


    Nonki Takahashi

    Monday, July 7, 2014 3:03 AM
    Moderator
  • Athasak,

    Nice try.  You are approaching to a regular triangle but not yet...  Ratio of your triangle is like below.

    triangle ratio


    Nonki Takahashi

    Monday, July 7, 2014 4:32 AM
    Moderator
  • Community Suggestions (by Nonki)

    3. Uhm... how about this?

    GFS579

    • Edited by Athasak Monday, July 7, 2014 4:22 PM
    Monday, July 7, 2014 10:00 AM
  • @ Nonki
    Of course Shapes.Zoom affects the whole shape incl. PenWidth, but i did'nt care about that for nicer optical view and triangle is regular nevertheless, although side length is not exact.
    ID: LXK869  should fit. Did'nt update 'lastSide' Var to keep the total zoom rounding error minimal over multiple In/Out zooms. But did'nt proof/compare if it is (or not) more exact after 'lastSide' update on every step.

    But for something different:
    What do think as i know, that you also script in JS?

    From JPS (former 'One Step Ahead Software'), If you look at eg. site PESX there's a JScript in the html source (line 37-101 and line 430-444) that shows a textString snake which follows the mouse in SlowMo.
    Can't see it in my browser (blocked or does'nt work on archive.org at all ?), but once the page is saved locally i can view it with:
    htmlPath = "C:\Temp\PESX.htm"
    LDControls.AddBrowser(GraphicsWindow.Width,GraphicsWindow.Height,"file:///"+ htmlPath)

    I think this would make a nice effect in the GW and i only would like to know if this is transferable to SB at all ??, as i first have to find out some JS commands i struggle with (like document.body.scrollLeft+event... and muuuuch more).

    Monday, July 7, 2014 8:44 PM
    Answerer
  • Pappa Lapub,

    What I would like to say is not so difficult.  To keep zoomed shape as regular, we need to give same scale for X and Y.

    triSide = 100
    factH = 0.5 * Math.SquareRoot(3)
    Tri = Shapes.AddTriangle(0,0, triSide,0, triSide/2,triSide*factH)
    Shapes.Move(Tri, 200, 200)
    Rel = 2
    Shapes.Zoom(Tri, Rel, Rel * factH)
    Program.Delay(2000)
    Shapes.Zoom(Tri, Rel, Rel)

    About JS, I know Japanese resources but in English except https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide .

    My Japanese JS site is http://www.nonkit.com/javascript/index.html .

    Thanks.


    Nonki Takahashi


    Tuesday, July 8, 2014 1:05 AM
    Moderator
  • GBS016 seems good start, ProfessionalOfSmallBasic.

    Nonki Takahashi

    Tuesday, July 8, 2014 1:14 AM
    Moderator
  • Is there anyone who can create sample main or sample plug-in?

    Nonki Takahashi

    Tuesday, July 8, 2014 1:16 AM
    Moderator
  • Community Suggestions (by Nonki)

    3. Uhm... how about this?

    GFS579

    Great!  I like this solution.

    Screen shot of a program to draw regular triangle coded by Athasak


    Nonki Takahashi


    Tuesday, July 8, 2014 2:36 AM
    Moderator
  • This is my sample for community suggestion 1 by Nonki: SCB458.

    Nonki Takahashi

    Tuesday, July 8, 2014 2:39 AM
    Moderator
  • Community Suggestions (by Nonki)

    2. Import ID: GCW421

    Interesting.

    color = shapes.AddText("'navajowhite'")

    should be

    color = shapes.AddText("''navajowhite''")

    or

    q = Text.GetCharacter(34)
    color = shapes.AddText(q + "navajowhite" + q)
    , I think.


    Nonki Takahashi

    Tuesday, July 8, 2014 3:01 AM
    Moderator
  • How do you return from a plug-in?  Changing color and width are easier.  If the color or width are selected, then you can return to main.  But how about drawing random color stars or eraser?  One way is displaying End (star or eraser) button.  Another way is to determine control flag such as continue.  And set it "False" in main routine.
    'Main
    While "True"
      If selected Then
        continue = "True"
        DrawStars()
      EndIf
      If something Then
        continue = "False"
      EndIf
    EndWhile
    
    'Plug-in
    Sub DrawStars
      While continue
        ' draw stars
      EndWhile
    EndSub


    Nonki Takahashi

    Tuesday, July 8, 2014 3:36 AM
    Moderator
  • This is my sample for community suggestion 2 by Nonki: CDB297.

    Nonki Takahashi

    Tuesday, July 8, 2014 4:46 AM
    Moderator
  • My solution for community suggestion 2 (Nonki), is reads a file in the program.dirrectory and writes it to the TextWindow.

                 '  readSB    Communuty suggestion Nonki july 2014     WhTurner
    c13=Text.GetCharacter(13)     'carriage return
    c39=Text.GetCharacter(39)     'single quote
    FILE= Program.Directory+"\readSB.sb"    'you can change the name here
    cnts=File.ReadContents(FILE)+c13
    pos13=text.GetIndexOf(cnts,c13)
    While pos13>0
      line=Text.GetSubText(cnts,1,pos13-1)
      posq=Text.GetIndexOf(line,c39)
      If posq>0 Then
        part1=Text.GetSubText(line,1,posq-1)
        part2=Text.GetSubTextToEnd(line,posq)
        TextWindow.Write(part1)
        TextWindow.ForegroundColor="Green"
        TextWindow.WriteLine(part2)
        TextWindow.ForegroundColor="Gray"
      Else
        TextWindow.WriteLine(line)
      EndIf
      cnts=Text.GetSubTextToEnd(cnts,pos13+2)
      pos13=text.GetIndexOf(cnts,c13)
    EndWhile
      


    Jan [ WhTurner ] The Netherlands




    Tuesday, July 8, 2014 11:38 AM
    Answerer
  • WhTurner33,

    Your program treats comments accurately.  Good job! 


    Nonki Takahashi

    Tuesday, July 8, 2014 1:05 PM
    Moderator
  • Oh man, oh man! Time for a vacation and ashtray glasses. Obviously i was thinking to take a square, resize it 2:1 and it would stay a square :-(  haha; The Final Cut: ZLD815
    Thx Nonki.
    And about the snake shapes, after some sleep and watching it's behaviour, the logic seems clear w/o need to suck deeper into JS:
    Letter(i,x) ~ MouseX + xOffset(i) after Delay(i)
    Letter(i,y) ~ MouseY after Delay(i)
    SB should offer all thats needed  (-> possible ! > ?)

    Tuesday, July 8, 2014 8:20 PM
    Answerer
  • This is my beta version of game challenge: KLB414-3 (Air Hockey 0.4b).

    I referred CollisionCheck() subroutine in litdev's article and rewrote it for my program as follows.

    • Changed variable names
    • Assumed each velocity of mullet always to be zero.

    Nonki Takahashi

    Wednesday, July 9, 2014 12:28 PM
    Moderator
  • This is my final beta for game challenge: KLB414-4 (Air Hockey 0.5b).

    A winner is the first to win 7 points.  Have fun!


    Nonki Takahashi

    Thursday, July 10, 2014 9:56 AM
    Moderator
  • About Community Suggestions (by Athasak)

    I've not challenged from these suggestions, but I like following samples.

    • Chat
    • Color Slider
    • Scroll

    Especially, I like Chat!

    Screen shot of a program Chat created by Athasak


    Nonki Takahashi

    Thursday, July 10, 2014 10:26 AM
    Moderator
  • This is my challenge for community suggestion 3 by Athasak: HWD964.

    Screen shot of a program Color Slider 0.2


    Nonki Takahashi

    Thursday, July 10, 2014 12:52 PM
    Moderator
  • I tried to write a sample main and a sample eraser together in ZSH672.

    Can you add other functions (plug-ins) for this?  Or do you have any other plan?


    Nonki Takahashi

    Thursday, July 10, 2014 2:27 PM
    Moderator
  • Well I was actually thinking to leave Microsoft Small Basic behind and move forward to another language but I am not sure about it. I would like you to give me your opinion. Please take some time and read what I have wrote and offer me your opinion. It doesn't have to be the smartest move ever, just tell me what you think :)

    I want to help!

    Thursday, July 10, 2014 4:21 PM
  • This is my sample for community suggestion 3 by Nonki:

    edge = 200
    Turtle.Turn(240)
    Turtle.PenUp()
    Turtle.Move(edge / Math.SquareRoot(3))
    Turtle.PenDown()
    Turtle.Turn(30)
    For i = 1 To 3
      Turtle.Turn(120)
      Turtle.Move(edge)
    EndFor


    Nonki Takahashi

    Friday, July 11, 2014 10:19 AM
    Moderator
  • lol.

    I know when I've been coding too much is when I don't wake up dreaming of code.

    Wednesday, July 23, 2014 1:53 AM
    Moderator
  • These are my ideas for a future challenge:

    1. Create a program which searches not used subroutines and list them from a Small Basic source file.
    2. Create a 99 Bottles of Beer program.
    3. Draw (or fill) a Parallelogram.

    Nonki Takahashi


    Thursday, July 24, 2014 7:59 AM
    Moderator
  • Small Challenge 1:

    'Move Ball & Mouse pointer in tandom
    
    ballRadius = 20
    ball = Shapes.AddEllipse(ballRadius *2, ballRadius *2)
    
    While 0=0  
      Shapes.Move(ball, GraphicsWindow.MouseX - ballRadius, GraphicsWindow.MouseY - ballRadius)
      
      Program.Delay(Math.Max(0, 20 - (Clock.ElapsedMilliseconds - start)))
      start = Clock.ElapsedMilliseconds
    EndWhile

    Saturday, July 26, 2014 5:49 PM
    Moderator
  • Here's my "Move Ball & Mouse pointer in tandem with Trailing Shadow"

    QSS694

    I used a high frame rate, fps = 80, which I don't really like using, prefer 50 fps. It just looks a bit "smoother".

    Maybe I could've predicted a fast mouseMove and then set a max distance b/w the centre of the circles and maintain the rapid illusion by adding more shadows proportional to mouseMove speed.

    Sunday, July 27, 2014 1:54 AM
    Moderator
  • Maybe could use an adaptation of the screen manager loop:

    If nextTask <> currentTask Then

    currentTask = nextTask

    I'll check it and post a sample soon :)

    Tuesday, July 29, 2014 11:46 AM
    Moderator
  • Here's my thoughts on the Group Challenge. XWM877

    I've activated the "Free" btn and "Clear" btn.

    Some ideas on Setup and Task (plug-ins) coding.

    'BUTTON EVENTS w/  MANAGER
      If buttonClicked Then
        TaskManager()
        buttonClicked = "False"
      EndIf
      
      'MOUSE TRACKING
      UpdateMousePosition()  
      CheckIfMouseIsOverCanvas()  
      
      'TASKS (one at a time)  - can include pen and menu tasks as well
      If currentTask = "Free" And Mouse.IsLeftButtonDown And mouseIsOverCanvas Then  
        DrawFreeHand()
      EndIf  
      If currentTask = "Clear" Then
        ClearCanvas()
      EndIf

    Tuesday, July 29, 2014 5:28 PM
    Moderator
  • So from above...

    The draw task plug-ins are just update your XY's and do GraphicsDrawSomething.

    Tuesday, July 29, 2014 6:03 PM
    Moderator
  • @Nonki

    quoting you from above:

    "How do you return from a plug-in?  Changing color and width are easier.  If the color or width are selected, then you can return to main.  But how about drawing random color stars or eraser?  One way is displaying End (star or eraser) button.  Another way is to determine control flag such as continue.  And set it "False" in main routine. "

    I thought about this and came up with: "by selecting one task at a time". I'm thinking this might help minimise the reliance on flag control. I've had a bit of trouble before with these flags as they create a lot of dependencies.

    I just used a default window size. Could window size be a config setting.

    Maybe other configs are penWidth, brushColor etc... Don't know? Configs could be a stretch.

    Here's a sample thought: XWM877

    I've never done paint program before, very interesting.


    Wednesday, July 30, 2014 12:19 AM
    Moderator
  • To keep it simple maybe configs could be explored after the some of the program is coded. Backward configuration?

    I think some consensus on structure could be vital for a lead
    Wednesday, July 30, 2014 12:40 AM
    Moderator
  • Jibba Jabba,

    XWM877 is very good try.  I'll write some add-ins for XWM877 and my ZSH672.


    Nonki Takahashi

    Wednesday, July 30, 2014 1:32 AM
    Moderator
  • No worries Nonki.

    My thoughts are:

    On xwm877 maybe just try a rectangle draw or straight line. All that should be needed for that is X and Y's and the GW.lineDraw(x,y, etc).

    Then maybe we start another thread and discuss any issues. Take your time. At your pace.

    If there's any early stage issues with the structure post them and we'll see if their easily resolvable.

    Maybe leave some draw task plugins for others as any problems are sorted. :)

    If anyone else has any thoughts, let us know.

    Wednesday, July 30, 2014 4:38 AM
    Moderator
  • I wrote a plug-in as QDS710 for both XWM877 and ZSH672 to change pen color.

    And I changed a little in XWM877 and publushed as XWM877-0.

    And I changed a little more in ZSH672 and published as ZSH672-0.


    Nonki Takahashi

    Wednesday, July 30, 2014 5:31 AM
    Moderator
  • @nonki, WOW

    You plugged into that big time!

    We've got all that space at the top too. Maybe some menu stuff, e.g. add pic....

    I added a very simple RectangleDraw. I could use lineDraw to get rid of the flickering.

    XWM877-1

    history:

    XWM877    XWM877-0     XWM877-1

    Wednesday, July 30, 2014 6:28 AM
    Moderator
  • Suggestions for a future challenge:

    1.) MouseLogger / MouseTracks Recorder: Click on empty opened GW multiple times while recording these clicks in the background. When finished, initiate playback to repeat all previous clicks by a Shape or Turtle (with or w/o trails or press eg. 1,2,3 or 4 to support any of the 4 possibilities). Playback should not only support correct click positions but also original speed (timespan between clicks).

    2.) ReadRegExpand: Export a registry key with 'REG_EXPAND_SZ' data to a TXT file and write a program to make it's content human readable. eg. HKEY_CLASSES_ROOT\.bmp\ShellNew should be one of the first (when searching for 'Data': @%systemroot% to find such REG_EXPAND key). Resulting output in this case should be similar to:

    ...

    "ItemName"=hex(2):@%systemroot%\system32\mspaint.exe,-59414

    ...

    3.) 2D TextEffect/Animation: Everyone knows a movie crawl where a message for ET fades out into eeeendless space or like the "(3D) TextScreenSaver" in Windows.

    Write a program with some text animation(s) eg. using Animate, Zoom, Color, Rotate, Opacity, FontProps etc. or in fullscreen (screensaver like) mode.

    Sample: VHK875 (works soLaLa online, but better in offline mode)



    Wednesday, July 30, 2014 9:43 PM
    Answerer
  • @nonki, WOW

    You plugged into that big time!

    We've got all that space at the top too. Maybe some menu stuff, e.g. add pic....

    I added a very simple RectangleDraw. I could use lineDraw to get rid of the flickering.

    XWM877-1

    history:

    XWM877    XWM877-0     XWM877-1

    RectangleDraw() works well.

    Nonki Takahashi

    Thursday, July 31, 2014 3:31 AM
    Moderator