none
Challenge of the Month - July 2018 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.

    We may extend these challenges over into a second month if solutions and questions are still coming in.

    Graphics Challenges

    1) Write a program to change the background colour of the GraphicsWindow.  Increase the red, blue or green components by pressing the R, G, B keys.  Reduce the colour components when the Shift key is held down.

    2) White a program to draw a classic soccor ball.

    Ball | Kingston3) Write a program to load an image, then spin, zoom and fade the image using key presses.

    Maths Challenge

    Wrire a program to recursively sum the digits of a number until there is only one number.

    For example the number 1654876 is summed to 1+6+5+4+8+7+6 = 37, which is summed to 3+7 = 10, which is summed to 1+0 = 1.

    As a follow-up.  Are reduced sum of digids (1- 9) evenly distributed, equally likely or are some more common for a large number of integers?  Are there any aother patterns or comclusions that you can find?

    Game Challenge

    Write a simple World Cup penaly shoot-out program.  It could be 2 player or against the computer.

    Turtle Challenge

    Write a program where the turtle keeps moving towards the mouse position.

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

    Sunday, July 1, 2018 10:11 AM
    Moderator

All replies

  • this should be intresting the ball should not be drawn by importing or Loading image it should be drawn by[shape_init()--add_shapes()]                                               mahreen miangul
    Sunday, July 1, 2018 12:39 PM
  • 3d array of football balls pulsating: GGW720

    image for texture:

    result:

    Monday, July 2, 2018 1:56 PM
  • no need of recursion to sum numbers:

    While 1=1
      x=TextWindow.ReadNumber()
      nn=LDMath.Decimal2Base(x-1 9)
      b=text.GetSubTextToEnd( nn Text.GetLength(nn))+1
      TextWindow.WriteLine(x+": "+b)
    EndWhile

    Monday, July 2, 2018 5:48 PM
  • turtle to mouse:

    GraphicsWindow.MouseMove=mmm
    Turtle.Speed=8
    Turtle.PenUp()
    Turtle.Show()
    GraphicsWindow.Title="Turtle to mouse"
    GraphicsWindow.BackgroundColor="teal"
    While 1=1
      If mw Then
        mw="false"
        aa=LDMath.Convert2Radial(GraphicsWindow.MouseX GraphicsWindow.MouseY Turtle.x Turtle.y)
        Turtle.Angle=aa[2]-90
        Turtle.Move(aa[1]) 
      EndIf
    EndWhile
    
    Sub mmm
      mw="true"
    EndSub

    Monday, July 2, 2018 5:59 PM
  • Another turtle to mouse

    Turtle.Speed=10
    Turtle.PenUp()
    While 1=1
      Turtle.MoveTo(GraphicsWindow.MouseX,GraphicsWindow.MouseY)
    EndWhile

    Monday, July 2, 2018 6:11 PM
    Moderator
  • ball: VCK996
    Monday, July 2, 2018 8:26 PM
  • This is my first step to draw a classic soccer ball: KZJ575.

    I made these data with a 2-D CAD program (jw_cad).

    Screen shot of a program Truncated Icosahedron


    Nonki Takahashi




    Monday, July 2, 2018 8:42 PM
    Moderator
  • created some fancy balls of nonki's Truncated Icosahedron

    • LDD643

    use lmb to paint region and rmb to switch color

    Tuesday, July 3, 2018 4:15 AM
  • a nice 3d ball viewer from nonki's ball:

    • PKN809


    update: PSQ301
    • Edited by Tryhest Tuesday, July 3, 2018 11:38 AM
    Tuesday, July 3, 2018 4:35 AM
  • image differencing tool: XGS894

    image differencing is a powerful tool in graphic design, especially when creating logos, as it produces nice effects with simple overlapping of geometric forms. usage is simple:

    • move mouse to adjust circle3 position
    • use mswheel to adjust circle3 size
    • press lmb to position cirlcle3
    • press rmb to fill selected region darkblue
    • use cursor keys to nudge circle3
    • press anykey and rmb to delete region

    some examples of results:





    • Edited by Tryhest Wednesday, July 4, 2018 4:38 AM
    Wednesday, July 4, 2018 4:28 AM
  • This is my second step to draw a classic soccer ball: FKX723.

    Screen shot of a program Rotating Classic Soccer Ball


    Nonki Takahashi

    Wednesday, July 4, 2018 6:39 AM
    Moderator
  • translates the quick brown fox phrase to 18 languages:

    • GKL236

    usage: type the words of quick brown fox in any of 18 languages, select source and destination languages followed by semicolon ";"

    Wednesday, July 4, 2018 10:24 AM
  • This is my first step for the maths challenge: RXS942.

    Number? 12345
    6
    Number? 13579
    7
    Number? 56789
    8
    Number? 

    Nonki Takahashi

    Wednesday, July 4, 2018 2:14 PM
    Moderator
  • Now I make 1 challenge

    watch http://smallbasic.com/smallbasic.com/program/?SGR114


    Wednesday, July 4, 2018 7:31 PM
  • some updates: KST574

    • faster drawing
    • added umbra
    • colors changed
    • rotation speed variation

    Wednesday, July 4, 2018 8:52 PM
  •  I wrote a program to recursively sum the digits of a number in a graphics window. Code to import: QZS654

    or use this link: http://smallbasic.com/smallbasic.com/program/?QZS654

    Thursday, July 5, 2018 12:04 AM
    • RSZ837

    3d rotating football colored ball

    pan by cursors, zoom & nudge by mouse

    Friday, July 6, 2018 7:23 AM
  • Hi Simakov Misha, nice try.

    Nonki Takahashi

    Friday, July 6, 2018 11:06 AM
    Moderator
  • Hi Infrid, nice graphics version!

    Nonki Takahashi

    Friday, July 6, 2018 11:08 AM
    Moderator
  • thanks

    Friday, July 6, 2018 1:53 PM
  • This is my second step for the maths challenge.

    While "True"
      TextWindow.Write("Number? ")
      n = TextWindow.ReadNumber()
      sum = Math.Remainder(n - 1, 9) + 1
      TextWindow.WriteLine(sum)
    EndWhile


    Nonki Takahashi

    Saturday, July 7, 2018 5:27 AM
    Moderator
  • This is my solution to change the background color: WGP487.

    Nonki Takahashi

    Saturday, July 7, 2018 8:45 AM
    Moderator
  • This is my solution for the Turtle challenge: ZTN256.

    Nonki Takahashi

    Saturday, July 7, 2018 9:08 AM
    Moderator
  • turtle hexaflower: FCL097

    Sunday, July 8, 2018 12:01 PM
  • QFW203  Skecth Klassic Soccer Ball now to color it need help      
    Monday, July 9, 2018 4:02 PM
  • This is my idea for a future challenge.

    Physics Challenge

    Write a program to simulate a hand spinner.


    Nonki Takahashi

    Friday, July 20, 2018 2:24 PM
    Moderator
  • This is my idea for a future challenge.

    Physics Challenge

    Write a program to simulate a hand spinner.


    Nonki Takahashi

    Ah, like a fidget spinner? Great idea!


    Ed Price, Azure Development Customer Program Manager (Blog, Small Basic, Wiki Ninjas, Wiki)

    Answer an interesting question? Create a wiki article about it!

    Saturday, July 21, 2018 1:59 AM
    Owner
  • 3d drone flyby towers: HSG745

    adjust view angle by mouse&wheel zoom in/out

    Saturday, July 21, 2018 2:27 AM
  • the way u made it can't be coloured simply.

    only 3 possible ways:

    1. use ldcapture and ldfloodfill (but u must fill all the gaps bcs. there may be fill leaks) 
    2. draw many coloured parralel lines (and calculate each exactly position)
    3. use many filltriangle or shapes.addtriangle



    • Edited by Tryhest Saturday, July 21, 2018 2:34 AM
    Saturday, July 21, 2018 2:32 AM
  • a bit upgraded nonki's turtle:

    Timer.Interval = 35
    Timer.Tick = OnTick
    GraphicsWindow.BackgroundColor="DarkSlateGray"
    GraphicsWindow.Title="Turtle Artdraw"
    
    Sub OnTick
      GraphicsWindow.PenWidth=LDMath.Sin(tt*4)*3+4
      GraphicsWindow.PenColor=LDColours.HSLtoRGB(math.Remainder( tt 360) 1 .65)
      mm=ldMath.Convert2Radial(GraphicsWindow.MouseX GraphicsWindow.MouseY Turtle.x Turtle.y)
      r=mm[1]
      If r>0 Then
        Turtle.Angle = mm[2] - 90
        If r>10  Then
          r = 10
        EndIf
        Turtle.Move(r)
        tt=tt+2
      EndIf
    EndSub

    Saturday, July 21, 2018 2:51 AM
  • spinner base: NGH657

    click to spin faster

    Saturday, July 21, 2018 3:58 AM
  • spinner v1.0: BVZ484

    Monday, July 23, 2018 2:42 AM
  • rotating,pulsating and shape-changing cross: XVP811

    Monday, July 23, 2018 3:30 AM
  • football field of worldcup finale 2018 (cro-fra):

    •  BHD456


    • Edited by Tryhest Monday, July 23, 2018 7:17 AM
    Monday, July 23, 2018 7:16 AM
  • I'm extending this one for a month since I'm on holiday.  Feel fee to add any challenges...
    Sunday, July 29, 2018 10:00 AM
    Moderator
  • This is my first step for a fidget spinner: VRN586.

    Screen shot of a program Fidget Spinner 0.1a


    Nonki Takahashi

    Monday, July 30, 2018 1:13 AM
    Moderator
  • sokocute online:

    GraphicsWindow.Width = 924 
    GraphicsWindow.Height = 768
    korrx=-36
    Path = "http://smallbasic.com/drop/soko"
    background = ImageList.LoadImage( Path + "/sokocuteff.png")
    image["A"] = ImageList.LoadImage( Path + "/sokocute0a.png")
    image["B"] = ImageList.LoadImage( Path + "/sokocute0b.png")
    image["7"] = ImageList.LoadImage( Path + "/sokocute07.png")
    image["6"] = ImageList.LoadImage( Path + "/sokocute06.png")
    image["5"] = ImageList.LoadImage( Path + "/sokocute05.png")
    image["4"] = ImageList.LoadImage( Path + "/sokocute04.png")
    image["3"] = ImageList.LoadImage( Path + "/sokocute03.png")
    image["2"] = ImageList.LoadImage( Path + "/sokocutegg.png")
    image["1"] = ImageList.LoadImage( Path + "/sokocutess.png")
    image["0"] = ImageList.LoadImage( Path + "/sokocute00.png")
    
    GraphicsWindow.DrawImage(background, 0, 0)
    stage=0
    initlevels()
    levelload()
    
    Sub LevelLoad
      cryst = 0
      posx  = 4
      posy  = 4
      moves = 0
      
      For i = 0 To 15
        For p = 1 To Text.GetLength(block[stage][i])
          blockcode = Text.GetSubText(block[stage][i], p, 1) 
          If blockcode = "X" then 
            posy = i  
            posx = p-1
            blockcode = 0
          EndIf
            
          if blockcode = 2 then 
            ground[i][p-1] = 0
          elseif blockcode = "C" then 'crystal on gras'
            ground[i][p-1] = "A"
          elseif blockcode = "D" then 'crystal on wood'
            ground[i][p-1] = "B"        
          else 
            ground[i][p-1] = blockcode
          endif
        EndFor
      EndFor
        
      For i = 0 To 15'------------load the water first'
        For p = 1 To Text.GetLength(block[stage][i])
          blockcode = Text.GetSubText(block[stage][i], p, 1) 
          If blockcode = 3 Then
            levelshapes[i][p-1] = Shapes.AddImage(image[blockcode])  
            Shapes.move(levelshapes[i][p-1], (p-1) * 50 + korrx, (i) * 40 - 0)    
          Endif      
        EndFor  
      EndFor
      
      For i = 0 To 15
        For p = 1 To Text.GetLength(block[stage][i])
          blockcode = Text.GetSubText(block[stage][i], p, 1) 
          If blockcode = "X" then 
            posy = i  
            posx = p-1
            blockcode = 0
          elseIf blockcode = "Y" then 
            posy = i  
            posx = p-1
            blockcode = "A"     
          elseIf blockcode = "Z" then 
            posy = i  
            posx = p-1
            blockcode = "B"
          EndIf
            
          if blockcode = 2 then 
            ground[i][p-1] = 0
          elseif blockcode = "C" then 
            ground[i][p-1] = "A"
          elseif blockcode = "D" then 
            ground[i][p-1] = "B"
          else  
            ground[i][p-1] = blockcode
          endif
            
          if blockcode = "C" then
            level[i][p-1] = 2  
          elseif blockcode = "D" then
            level[i][p-1] = 2  
          else
             level[i][p-1] = blockcode      
          endif   
          If blockcode = "C" Then 'crystal on grass'
            levelshapes[i][p-1] = Shapes.AddImage(image["A"])
               Shapes.move(levelshapes[i][p-1], (p-1) * 50 + korrx, (i) * 40 - 0)   
          elseIf blockcode = "D" Then 'crystal on wood'
            levelshapes[i][p-1] = Shapes.AddImage(image["B"])
            Shapes.move(levelshapes[i][p-1], (p-1) * 50 + korrx, (i) * 40 - 0)            
         elseIf blockcode < 2  Then
            levelshapes[i][p-1] = Shapes.AddImage(image[blockcode])
            Shapes.move(levelshapes[i][p-1], (p-1) * 50 + korrx, (i) * 40 - 0) 
          ElseIf blockcode = 2 Then
            levelshapes[i][p-1] = Shapes.AddImage(image["0"])
            Shapes.move(levelshapes[i][p-1], (p-1) * 50 + korrx, (i) * 40 - 0)
          endif   
        EndFor  
      EndFor   
      
      For i = 0 To 15'---------------------------load the walls'
        For p = 1 To Text.GetLength(block[stage][i])
          blockcode = Text.GetSubText(block[stage][i], p, 1) 
          If blockcode >= 4 Then
            levelshapes[i][p-1] = Shapes.AddImage(image[blockcode])      
            Shapes.move(levelshapes[i][p-1], (p-1) * 50 + korrx, i * 40 )  
          Endif      
        EndFor  
      EndFor
      TextWindow.WriteLine("STAGE 1")
        TextWindow.WriteLine("SB online Soko v0.1")
    EndSub
    
    Sub InitLevels
    block[0][0] ="...................."
    block[0][1] ="...................."
    block[0][2] ="...................."
    block[0][3] =".....66666.........."
    block[0][4] =".....60006.........."
    block[0][5] =".....62006.........."
    block[0][6] ="...66600266........."
    block[0][7] ="...60020206........."
    block[0][8] =".6660606606AA555555."
    block[0][9] =".600060660666700115."
    block[0][10]=".60200200000X000115."
    block[0][11]=".666660666066700115."
    block[0][12]=".....60000066555555."
    block[0][13]=".....6666666........"
    block[0][14]="...................."
    block[0][15]="...................."
    EndSub




    • Edited by Tryhest Sunday, August 5, 2018 6:10 AM
    Sunday, August 5, 2018 6:08 AM
  • adapted nonki's spinners for sb-online

    GraphicsWindow.BackgroundColor="tan"
    GraphicsWindow.Title = "Fidget Spinners"
    Init()
    da = 10
    ea[1]=-30
    ea[2]=30
    While "True"
      da=da-.005
      If da<1 Then
        da=10
      EndIf
      a = a + da
      
      For sp=1 To 2
        For i = 1 To 3
          _a = (Math.GetRadians(a+ea[sp] + (i - 1) * 120))*((sp-1)*2-1)
          x = ox[sp] + r * Math.Sin(_a)
          y = oy[sp] - r * Math.Cos(_a)
          Shapes.Move(out[sp][i], x - 35, y - 35)
          Shapes.Move(in[sp][i], x - 25, y - 25)
        EndFor
      EndFor
      
      Program.Delay(10)
    EndWhile
    
    Sub Init
    TextWindow.WriteLine("2 Spinners...")
      gw = 598
      gh = 428
      GraphicsWindow.Width = gw
      GraphicsWindow.Height = gh
      ox[1] = gw / 2-60
      oy[1] = gh / 2
      ox[2] = gw / 2+105
      oy[2] = gh / 2
      color[1] = "Lime"
      color[2] = "Blue"
      For sp=1 To 2
        r = 60
        i = 0
       
        GraphicsWindow.PenWidth = 12
        
        For i = 1 To 3
         GraphicsWindow.BrushColor = "Transparent"
          a = (i - 1) * 120
          _a = Math.GetRadians(a)
          x = ox[sp] + r * Math.Sin(_a)
          y = oy[sp] - r * Math.Cos(_a)
          GraphicsWindow.PenColor = color[sp]
          out[sp][i] = Shapes.AddEllipse(70, 70)
         ' LDEffect.DropShadow(out[sp][i] "")'<---uncheck in desktop sb
          Shapes.Move(out[sp][i], x - 35, y - 35)
          GraphicsWindow.PenColor = "Black"
          GraphicsWindow.BrushColor="tan"
          in[sp][i] = Shapes.AddEllipse(48, 48)
          Shapes.Move(in[sp][i], x - 24, y - 24)
        EndFor
        
        GraphicsWindow.BrushColor = color[sp]
        GraphicsWindow.PenWidth = 0.1
        ell = Shapes.AddEllipse(70, 70)
        
        Shapes.Move(ell, ox[sp] - 35, oy[sp] - 35)
        GraphicsWindow.PenWidth = 2
        GraphicsWindow.PenColor = "DimGray"
        ell = Shapes.AddEllipse(50, 50)
        Shapes.Move(ell, ox[sp] - 25, oy[sp] - 25)
      EndFor
    EndSub

    Wednesday, August 8, 2018 4:31 AM
  • I'm extending this one for a month since I'm on holiday.  Feel fee to add any challenges...

    Graphics Challenge

    Write a program to draw your favorite insect.


    Nonki Takahashi



    Sunday, August 12, 2018 3:49 AM
    Moderator
  • branches tree smooth anim: MSB011


    for desktop with ld xtension only
    • Edited by Tryhest Monday, August 20, 2018 6:10 AM
    Monday, August 20, 2018 5:46 AM
  • sb online has some strange issuses with recursion (or maybe stack lost): NMR321



    sb online issue
    • Edited by Tryhest Monday, August 20, 2018 6:06 AM
    Monday, August 20, 2018 6:00 AM
  • turtle demos: MZC413


    • Edited by Tryhest Tuesday, August 21, 2018 4:18 AM
    Monday, August 20, 2018 9:18 PM
  • turtle cycloide: NMF255

    Tuesday, August 21, 2018 7:30 PM
  • sb online turtle pattern generator: QDB137

    postprocessing in paint.net:

    Wednesday, August 22, 2018 10:19 AM
  • whirlpools: WSB371

    Thursday, August 23, 2018 6:56 AM
  • nice sine pics: PFK482

    Thursday, August 23, 2018 8:07 PM
  • unexpected output of a simple code:

    GraphicsWindow.Width= 640
    GraphicsWindow.Height=480
    GraphicsWindow.Left= 5
    GraphicsWindow.Top = 5
    height=GraphicsWindow.Height
    width= GraphicsWindow.Width
    
    For i= 1 To 10000 
      radius= Math.GetRandomNumber(10)+4
      x = Math.GetRandomNumber(width-radius)
      y = Math.GetRandomNumber(height-radius)
      clr= GraphicsWindow.GetRandomColor()
      GraphicsWindow.BrushColor=clr 
      GraphicsWindow.FillEllipse(x, y, 2*radius,2*radius)
    EndFor
    

    Sunday, August 26, 2018 8:00 PM