none
Challenge of the Month - February 2019 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.

    Graphics Challenge

    First write a program to draw a line on the GraphicsWindow following the mouse.

    Below is a starter:

    GraphicsWindow.Show()
    xLast = GraphicsWindow.MouseX
    yLast = GraphicsWindow.MouseY
     
    While ("True")
      x = GraphicsWindow.MouseX
      y = GraphicsWindow.MouseY
      GraphicsWindow.DrawLine(x,y,xLast,yLast)
      xLast = x
      yLast = y
    EndWhile

    Then make the program color the line depending on which quadrant the mouse is in.

    Then make mirror images of the mouse movement to draw lines in each quadrant.

    Maths Challenge

    Write a program that will join up some random points to draw an irregular convex polygon (no side lines cross each other).

    Irregular Polygons | Brilliant Math & Science Wiki

    Banner Challenge

    Make a smoothly scrolling text banner for the GraphicsWindow.

    Try using different font styles, colours, transparency and other effects to make the scrolling effect as fun as possible.

    Consider using Shapes or Controls, with Move or Animate.

    Buttons Challenge

    Make a button that moves randomly within the GraphicsWindow.

    Try to make the movement smooth and pop up a message when the user manages to click the button.

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

    Friday, February 1, 2019 6:38 PM
    Moderator

All replies

  • Here's my solution for the first 2 parts of the graphics challenge.  I'm still thinking through how to do the 3rd part.

    PBW834

    Saturday, February 2, 2019 12:54 AM
  • Here is my Flowchart for the Banner Challenge:
    Saturday, February 2, 2019 11:31 AM
  • Here is my solution for the Banner Challenge: LKS836

    I'm still working on it, & will make it a bit fancier.

    I struggled with the If statement on lines 39 through 45. If anyone can explain to me why lines 40 & 43 don't change the variable c respectively and I had to add lines 41 and 44 to fix.
    Thanks for any advice! xD
    _______________

    iPotato

    Saturday, February 2, 2019 11:35 AM
  • Here's my solution for the Banner Challenge: RKJ527

    Saturday, February 2, 2019 1:50 PM
  • Here's my solution for the Button's Challenge:  XBP650

    If anyone wants to expand on it, you could easily turn it into a simple game by adding a time element. (e.g. if the player doesn't click the button in 10 seconds it's game over).

    Saturday, February 2, 2019 10:57 PM
  • Here's a partial solution to the Maths Challenge: KRM874

    At this point there's nothing to prevent the lines from crossing each other.  There's also a bug with the loop that draws the lines. The loop is randomized and sometimes runs out of available options to draw a line, causing an infinite loop.

    Any suggestions on where to go from here would be appreciated.



    • Edited by Schmical Sunday, February 3, 2019 1:02 AM fixed broken link
    Sunday, February 3, 2019 12:52 AM
  • program ID HJS943 when the Aircraft is hit or when the car is shot there is no sound on both the occasion  neither any writing
    appear on the window while i have put the codes for both in the code program need help, NaochanON use to guide me every
    4th or 5th day i have learned 60% of my small basic code programming from him. he has not answered my blogs in months now.
    Nonki is helping me now and then, but not often with thanks                                                        mahreen miangul
    Sunday, February 3, 2019 4:59 AM
  • program ID HJS943 when the Aircraft is hit or when the car is shot there is no sound on both the occasion  neither any writing
    appear on the window while i have put the codes for both in the code program need help, NaochanON use to guide me every
    4th or 5th day i have learned 60% of my small basic code programming from him. he has not answered my blogs in months now.
    Nonki is helping me now and then, but not often with thanks                                                        mahreen miangul

    Hi Mussamaina,

    The collision detection is working for when the car hits the aircraft, however the collision box is offset from the aircraft (slightly down and to the right)

    Sunday, February 3, 2019 6:11 AM
  • Hi Schemical, my idea is...

    • calculate mean point of the given points.
    • calculate angles of lines from the mean point to the given points.
    • sort the given points with their calculated angles.
    • then connect the given points in sorted order.

    I'm not sure this logic works fine...


    Nonki Takahashi

    Sunday, February 3, 2019 2:32 PM
    Moderator
  • Here is my solution for the Banner Challenge: LKS836

    I'm still working on it, & will make it a bit fancier.

    I struggled with the If statement on lines 39 through 45. If anyone can explain to me why lines 40 & 43 don't change the variable c respectively and I had to add lines 41 and 44 to fix.
    Thanks for any advice! xD
    _______________

    iPotato

    Hi iPotato, lines 40 & 43 just replace the caption of the button Item.  The variable c and the button Item are not associated for the PC.  The variable c means the status of the button Item only for programmers.  Make sense?


    Nonki Takahashi

    Sunday, February 3, 2019 2:54 PM
    Moderator
  • Hi Schemical and Nonki,

    I put Nonki's idea into KRM874 and published it as KRM874-0

    I had at first some problems with the sorting of the x- asnd y-arrays into the sequence of the calculated angles, but found a somewhat clumsy solution. I runned the  program quite a number of times without problems. Even with 100 dots there is a solution (see figure)


    Jan [ WhTurner ] The Netherlands

    Tuesday, February 5, 2019 2:30 PM
    Answerer
  • My solution to the graphics challenge is JDB939.
    Wednesday, February 6, 2019 3:22 AM
  • Hi Schemical and Nonki,

    I put Nonki's idea into KRM874 and published it as KRM874-0

    I had at first some problems with the sorting of the x- asnd y-arrays into the sequence of the calculated angles, but found a somewhat clumsy solution. I runned the  program quite a number of times without problems. Even with 100 dots there is a solution (see figure)


    Jan [ WhTurner ] The Netherlands

    added some ldeffects and repeating: KFG235

    Wednesday, February 6, 2019 4:48 PM
  • This is cool... as an extra challenge maybe right-click mouse to solve the traveling salesman on the same point set? :D
    Wednesday, February 6, 2019 11:16 PM
  • textmode puzzle game: WWQ951

    Thursday, February 7, 2019 4:12 PM
  • sb online issue: VTT889

    Thursday, February 7, 2019 5:04 PM
  • Add Animate Move Rotate SetOpacity Z00m ID GGG213
                                                                                                      mahreen miangul

    Friday, February 8, 2019 4:44 PM
  • textmode puzzle game: WWQ951

    • update: CRR554
    • keyboard handler
    • typografic borders
    • empty space


    Friday, February 8, 2019 7:02 PM
  • Hi,

    This is my solution for the Math challenge : CKH484-0

    ------------KEYS-------------------

    W - Connects to the first x1, y1 (for completing the shape)

    T - Get the code or updates the code

    ----------------------------------------

    Additional Feature : Can convert your drawing (polygon shapes) to Small Basic Code (Use "T" Key)

    Demonstration video : https://www.youtube.com/watch?v=8NxPgaqVCNc

    Samples

    Image not available :(

    Generated Code:

    'Generated By Polygon Tool
    Shapes.AddLine(137,84,255,89)
    Shapes.AddLine(255,89,255,127)
    Shapes.AddLine(255,127,163,122)
    Shapes.AddLine(163,122,158,165)
    Shapes.AddLine(158,165,247,158)
    Shapes.AddLine(247,158,246,201)
    Shapes.AddLine(246,201,246,232)
    Shapes.AddLine(246,232,145,236)
    Shapes.AddLine(145,236,138,205)
    Shapes.AddLine(138,205,202,204)
    Shapes.AddLine(202,204,207,178)
    Shapes.AddLine(207,178,134,182)
    Shapes.AddLine(137,84,134,182)
    Shapes.AddLine(279,84,287,227)
    Shapes.AddLine(287,227,394,212)
    Shapes.AddLine(394,212,386,178)
    Shapes.AddLine(386,178,358,160)
    Shapes.AddLine(358,160,332,149)
    Shapes.AddLine(332,149,357,122)
    Shapes.AddLine(357,122,374,110)
    Shapes.AddLine(374,110,373,78)
    Shapes.AddLine(373,78,364,70)
    Shapes.AddLine(279,84,364,70)
    Shapes.AddLine(295,93,295,126)
    Shapes.AddLine(295,126,306,131)
    Shapes.AddLine(306,131,330,121)
    Shapes.AddLine(330,121,350,106)
    Shapes.AddLine(350,106,356,90)
    Shapes.AddLine(356,90,334,89)
    Shapes.AddLine(334,89,308,93)
    Shapes.AddLine(295,93,308,93)
    Shapes.AddLine(302,163,298,199)
    Shapes.AddLine(298,199,308,204)
    Shapes.AddLine(308,204,329,202)
    Shapes.AddLine(329,202,365,200)
    Shapes.AddLine(365,200,368,185)
    Shapes.AddLine(368,185,338,175)
    Shapes.AddLine(302,163,338,175)
    Shapes.AddLine(83,33,109,292)
    Shapes.AddLine(109,292,425,255)
    Shapes.AddLine(425,255,408,3)
    Shapes.AddLine(83,33,408,3)

    Thanks.


    Roshan - 8th Grade Student (Age 13) - Learning Python, Machine Learning and C#

    Saturday, February 9, 2019 4:19 AM
  • Hi,

    This is my solution for the Math challenge : CKH484-0

    ------------KEYS-------------------

    W - Connects to the first x1, y1 (for completing the shape)

    T - Get the code or updates the code

    ----------------------------------------

    Additional Feature : Can convert your drawing (polygon shapes) to Small Basic Code (Use "T" Key)

    Demonstration video : https://www.youtube.com/watch?v=8NxPgaqVCNc

    Samples

    Image not available :(

    Generated Code:

    'Generated By Polygon Tool
    Shapes.AddLine(137,84,255,89)
    Shapes.AddLine(255,89,255,127)
    Shapes.AddLine(255,127,163,122)
    Shapes.AddLine(163,122,158,165)
    Shapes.AddLine(158,165,247,158)
    Shapes.AddLine(247,158,246,201)
    Shapes.AddLine(246,201,246,232)
    Shapes.AddLine(246,232,145,236)
    Shapes.AddLine(145,236,138,205)
    Shapes.AddLine(138,205,202,204)
    Shapes.AddLine(202,204,207,178)
    Shapes.AddLine(207,178,134,182)
    Shapes.AddLine(137,84,134,182)
    Shapes.AddLine(279,84,287,227)
    Shapes.AddLine(287,227,394,212)
    Shapes.AddLine(394,212,386,178)
    Shapes.AddLine(386,178,358,160)
    Shapes.AddLine(358,160,332,149)
    Shapes.AddLine(332,149,357,122)
    Shapes.AddLine(357,122,374,110)
    Shapes.AddLine(374,110,373,78)
    Shapes.AddLine(373,78,364,70)
    Shapes.AddLine(279,84,364,70)
    Shapes.AddLine(295,93,295,126)
    Shapes.AddLine(295,126,306,131)
    Shapes.AddLine(306,131,330,121)
    Shapes.AddLine(330,121,350,106)
    Shapes.AddLine(350,106,356,90)
    Shapes.AddLine(356,90,334,89)
    Shapes.AddLine(334,89,308,93)
    Shapes.AddLine(295,93,308,93)
    Shapes.AddLine(302,163,298,199)
    Shapes.AddLine(298,199,308,204)
    Shapes.AddLine(308,204,329,202)
    Shapes.AddLine(329,202,365,200)
    Shapes.AddLine(365,200,368,185)
    Shapes.AddLine(368,185,338,175)
    Shapes.AddLine(302,163,338,175)
    Shapes.AddLine(83,33,109,292)
    Shapes.AddLine(109,292,425,255)
    Shapes.AddLine(425,255,408,3)
    Shapes.AddLine(83,33,408,3)

    Thanks.


    Roshan - 8th Grade Student (Age 13) - Learning Python, Machine Learning and C#

    to create polygons u have to use ld xtension bcs custom polygons aren't supported in standard sb

    just create array of points where a[n][1]=xn and a[n][2]=yn

    then just use ss=LDShapes.AddPolygon(a)

    to set z-order of shapes use LDShapes.Zindex(ss zz) where greater zz means later drawing, so the object will overlap the underlaying ones 

    • Edited by Tryhest Friday, February 15, 2019 4:01 AM
    Friday, February 15, 2019 3:56 AM
  • ants draw:

    suitable for sb online but slow to draw

    fieldsize =100
    x =fieldsize /2
    y =fieldsize /2
    d =0
    s3=5
    cll[0]="white"
    cll[1]="darkblue"
    for f=1 to 2000'<---increase in sb desktop to get bigger pic'
    If field[x][y]=0 Then
      field[x][y]=1
      d =d-1
    Else
      field[x][y]=0
      d =d+1
    EndIf
    
    GraphicsWindow.BrushColor=cll[field[x][y]]
    GraphicsWindow.FillRectangle (x *s3,y *s3, s3, s3)
    d =Math.Remainder(d+4, 4)
    
    If d= 0 Then
      y =y+1
    ElseIf d= 1 Then
      x =x+1
    ElseIf d= 2 Then
      y =y-1
    ElseIf d= 3 Then
      x =x-1
    EndIf
    
    endfor


    • Edited by Tryhest Tuesday, February 19, 2019 6:40 AM
    Tuesday, February 19, 2019 6:40 AM
  • result after 11000 repeats: (sb desktop only)

    Tuesday, February 19, 2019 6:45 AM
  • WBD475


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Wednesday, February 20, 2019 2:54 AM
    Answerer
  • spiral of beizer's stars: VBW773

    Wednesday, February 20, 2019 4:31 AM
  • sb-online edition: XWM990



    still doesn't work for superbasic-v2 :(
    • Edited by Tryhest Wednesday, February 20, 2019 5:27 AM
    Wednesday, February 20, 2019 5:10 AM
  • I wont to publish a shape(image) on the net and import it for use later for my small basic code program i need a easy way i would be grateful for help                                                                      mahreen miangul

    Wednesday, February 20, 2019 11:50 AM
  • u can publish image here as attachment (9 images x post)

    user must download it and reference locally.

    other approach is much more complex bcs it needs understanding of html and javascript

    Wednesday, February 20, 2019 3:39 PM
  • nice but please explain with example if possible thankyou                                          mahreen miangul
    Thursday, February 21, 2019 4:30 AM
  • example: a new iconset for sb editor

    try it here (ldxtension required): NCJ956


    usage: rightclick on image, save it on ur hdd, then reference to saved image on line 1 of upper program
    • Edited by Tryhest Thursday, February 21, 2019 7:45 AM
    Thursday, February 21, 2019 7:43 AM
  • example NCJ956 should be explained without extension first teach me image publish and import then extensions one at a time                                                                                                               mahreen miangul
    Friday, February 22, 2019 3:29 AM
  • sb quick browser:

    stt="small basic"
    setup()
    
    Sub setup
      nn=LDSearch.Getweb(stt)
      mm=LDText.Split(nn ";")
      GraphicsWindow.BackgroundColor="teal"
      GraphicsWindow.BrushColor="darkblue"
      GraphicsWindow.FontBold="false"
      GraphicsWindow.FontSize=15
      GraphicsWindow.FontItalic="true"
      GraphicsWindow.FontName="calibri"
      LDUtilities.ShowNoShapeErrors="false"
      LDUtilities.ShowErrors="false"
      ss=controls.AddTextBox(40 1)
      sb=Controls.AddButton("Go" 1 1)
      Controls.ButtonClicked=bcc
      GraphicsWindow.BrushColor="lime" 
      For f=1 To Array.GetItemCount(mm)
        hh=LDText.Split(mm[f] "=")
        tt=Shapes.AddText(f+"| "+hh[2])
        Shapes.Move(tt 10 f*16+22)
        LDDialogs.ToolTip(tt hh[1])
        ww[tt]=hh[1]
        if f=1 Then
          w0=hh[1]
          EndIf
        Controls.HideControl(bb[tt])
        LDShapes.ZIndex(bb[tt],-1)
        LDShapes.SetShapeEvent(tt)
        LDShapes.ZIndex(tt 10)
      EndFor
      LDShapes.ShapeEvent=sss
      bb=LDControls.AddBrowser(1185 800 w0)
      Controls.Move(bb 350 0)
    EndSub
    
    Sub bcc
      stt=Controls.GetTextBoxText(ss)
        GraphicsWindow.Clear()
      setup()
    EndSub
    
    Sub sss
      ls=LDShapes.LastEventShape
      GraphicsWindow.Title=ww[ls]
      If  LDShapes.LastEventType="MouseDown" Then
        LDControls.BrowserSetURL(bb ww[ls])
      EndIf
    EndSub



    • Edited by Tryhest Thursday, February 28, 2019 5:04 AM
    Thursday, February 28, 2019 5:02 AM
  • sierpinski carpet:

    O=3
    S=Math.Power(3, o)
    GraphicsWindow.BrushColor="blue"
    GraphicsWindow.BackgroundColor="tan"
    For I=0 To S-1
      For J=0 To S-1
        X=J
        Y=I
        subb()
        IF C THEN
          ss=Shapes.AddRectangle(10, 10)
          Shapes.Move(ss, j*10+10, i*10+10)
        EndIf
      EndFor
    EndFor
    
    Sub subb
      C="false"
      l130:
      IF X-Math.Floor (X/3)*3=1 then 
      if Y-Math.Floor (Y/3)*3=1 THEN
        Goto RETUR
        endif
      EndIf
      
      X=Math.Floor (X/3)
      Y=Math.Floor (Y/3)
      IF X>0 THEN
        Goto l130
      EndIf
      if y>0 then
       goto l130
      endif
      C="true"
      RETUR:
    EndSub
     

    works on:

    • sb desktop(any)
    • sb online 0.91

    unfortunately now can't work (dunno why?) on

    • sb online 1.0
    • sb azure v2

    Wednesday, March 6, 2019 3:18 AM
  • workaround for new sb-online v2

     O=3
    S=9
    GraphicsWindow.BrushColor="blue"
    GraphicsWindow.BackgroundColor="tan"
    ji=-1
    For I=0 To S-1
      jj=-1
      ji=ji+1
      For J=0 To S-1
        X=J
        Y=I
        jj=jj+1
     
        subb()
        IF C THEN
           ss=Shapes.AddTriangle(jj*10+10, ji*10+10,jj*10+20, ji*10+10,jj*10+20, ji*10+20)
         EndIf
      EndFor
    EndFor
    
    Sub subb
      C="false"
      l130:
      IF X-Math.Floor (X/3)*3=1 then 
      if Y-Math.Floor (Y/3)*3=1 THEN
        Goto RETUR
        endif
      EndIf
      
      X=Math.Floor (X/3)
      Y=Math.Floor (Y/3)
      IF X>0 THEN
        Goto l130
      EndIf
      if y>0 then
       goto l130
      endif
      C="true"
      RETUR:
    EndSub

    as far can see sb v2 has issuses with for vars as many others

    reduced to triangles and just size 2, not 3

    also math.power doesn't work((

      
    • Edited by Tryhest Wednesday, March 6, 2019 3:45 AM
    Wednesday, March 6, 2019 3:44 AM
  • result on older sb1.0

    just add another

    Shapes.AddTriangle(jj*10+10, ji*10+10,jj*10+10, ji*10+20,jj*10+20, ji*10+20)

    takes a bit longer but it does it all.

    http://superbasic.azurewebsites.net/#/editor 

     
    Wednesday, March 6, 2019 3:57 AM
  • localhost sb online result:

    Wednesday, March 6, 2019 4:23 AM
  • as for today 6.3.19 sb has many issues and versions with many problems:

    • sb desktop 1.2+ld xtension + sb prime is the best edition (95% satisfaction)
    • sb desktop 1.3  is only for w10 store, without xtesions (70% satisf.)
    • sb online v0.91 is for best compatibility experience with sb desktop
    • sb online v1 lacks many features but still works ok (50% satisf)
    • sb online v2 has nice ide but many issuses and problems (40% satisf)
    • sb localhost lacks many features but has speed and stability(45% satisf.)
    Wednesday, March 6, 2019 4:31 AM