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

    Array Challenge

    • Write a program to split a sentence into an array of words
    • Extend the program to sort the array or words alphabetically
    • Extend the program to reverse the order of words in the array

    TextWindow Challenge

    • Write a TextWindow clock program

    Maths Challenge

    • Write a program to calculate e (base of natural logarithms) only using standard Small Basic

    Graphics Challenges

    • Write a program to flash some text for a period on the GraphicsWindow
    • Extend the program to start and stop the flashing with a mouse click
    • Write a program to scroll Flickr images across the GraphicsWindow
    • Write a program to spell your name in sign language, with animations of the hads if needed

    Sign Language | New Calendar Template Site

    Game Challenge

    • Write a ten pin bowling game

    Ford County Special Olympics Bowling Sets First Practice | Ford County ...

    Community Suggestions

    • Quilt Program (by Evelyn Rothman) LINK
    • Perhaps show a national pattern for your country or area like KUMIKO or TARTAN.
    • Driving a Golf Ball (by YLed) LINK
    • Law of momentum (by YLed) LINK



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

    Friday, February 24, 2017 6:14 PM
    Moderator

All replies

  • Maths Challenge

    • Write a program to calculate e
    e = 1
    For n=1 To  27 Step 1
      i = 1
      For x= 1 To n Step 1
        i= i * x
      endfor
      e = e + 1/i
      TextWindow.WriteLine("e iteration "+n+" = "+e)
    endfor
    TextWindow.WriteLine("-----------------------------------------------")
    TextWindow.WriteLine("ln("+e+") = "+Math.NaturalLog(e))
    TextWindow.WriteLine("-----------------------------------------------")

    Friday, February 24, 2017 10:22 PM
  • @backtothestart

    Good answer and very accurate - it can be done in 1 line.

    Friday, February 24, 2017 10:45 PM
    Moderator
  • TextWindow.WriteLine(Math.Power(10, 1/Math.NaturalLog(10)))
    Friday, February 24, 2017 11:29 PM
    Answerer
  • TextWindow.WriteLine(Math.Power(10, 1/Math.NaturalLog(10)))

    That's the one I was thinking of, basically solve 10^x = e by taking natural logs of both sides.
    Sunday, February 26, 2017 5:26 AM
    Moderator
  • Array Challenge with 2 Windows. Show RBF730.


    Best Regards Martin

    Sunday, February 26, 2017 12:04 PM
  • TextWindow.WriteLine("e= "+ Math.Power(10, 1/Math.NaturalLog(10)))


    That's the one I was thinking of, basically solve 10^x = e by taking natural logs of both sides.

    ... or Transformation of lgB (base B)
    lgB(n) = log(n)/log(B) ' using e as Base ->
    ln(n) = log(n)/log(e)  ' ... and choose n>1 eg. n = 10
    ln(10) = 1/log(e)
    log(e) = 1/ln(10)   ' EE ->
    e = 10^(1/ln(10))

    Sunday, February 26, 2017 1:03 PM
    Answerer
  • Graphics Challenges

    • Write a program to flash some text for a period on the GraphicsWindow

    program no: XGX199

    Sunday, February 26, 2017 7:45 PM
    Answerer
  •  KUMIKO sample VBJ291-0


    Saturday, March 04, 2017 3:49 AM
    Answerer
  • Maths Challenge

    • Write a program to calculate e
    e = 1
    For n=1 To  27 Step 1
      i = 1
      For x= 1 To n Step 1
        i= i * x
      endfor
      e = e + 1/i
      TextWindow.WriteLine("e iteration "+n+" = "+e)
    endfor
    TextWindow.WriteLine("-----------------------------------------------")
    TextWindow.WriteLine("ln("+e+") = "+Math.NaturalLog(e))
    TextWindow.WriteLine("-----------------------------------------------")

    Hello backtothestart.  This is my version using the same algorithm.

    ' e = Σ(n=0..∞) 1/n!
    f = 1   ' 0!
    e = 1   ' 1/0!
    For n = 1 To 27
      f = f * n
      e = e + 1 / f
    EndFor
    TextWindow.WriteLine("e=" + e)
    


    Nonki Takahashi

    Saturday, March 04, 2017 5:56 AM
    Moderator
  • KUMIKO pattern-2     TNM316

    Saturday, March 04, 2017 12:59 PM
    Answerer
  • NaochanOn ! great Kumiko , wow !!
    Saturday, March 04, 2017 2:12 PM
    Answerer
  • Community Suggestion for next month.

    Make a cipher or use a suggested cipher.

    Then attempt to crack your own custom cipher or write a program that can break ciphers.

    Saturday, March 04, 2017 4:58 PM
  • KUMIKO pattern-3      GZK639-0

    *  moving Hexagon

     Left: dL[2]=10   Right : dL[2]=40

    Sunday, March 05, 2017 6:34 AM
    Answerer
  • KUMIKO pattern-4    THS026

    Monday, March 06, 2017 12:27 PM
    Answerer
  • KUMIKO pattern-5  MZZ785 

     
    Tuesday, March 07, 2017 11:43 AM
    Answerer
  • This is my first step for the game challenge: Bowling Graphics (GRT732).

    Screen shot of a program Bowling Graphics


    Nonki Takahashi

    Wednesday, March 08, 2017 5:37 AM
    Moderator
  • This is the second step for the game challenge: Bowling Anime (GRT732-0).

    Screen shot of a program Bowling Anime 0.21


    Nonki Takahashi

    Wednesday, March 08, 2017 8:24 AM
    Moderator
  • This is the third step: GRT732-1.

    Screen shot of a program Bowling Anime 0.3


    Nonki Takahashi

    Wednesday, March 08, 2017 10:03 AM
    Moderator
  • KUMIKO pattern-6   VMH886 

    Wednesday, March 08, 2017 10:42 AM
    Answerer
  • program ID TRP429 needs editing will somebody make the program short and more simple  if possible and can somebody make the cannon hit something else than the black triangle thank you
               mahreen miangul

    Wednesday, March 08, 2017 1:44 PM
  • program ID TRP429 needs editing will somebody make the program short and more simple  if possible and can somebody make the cannon hit something else than the black triangle thank you
               mahreen miangul

    1)  make short and simple......   Refer XFJ262-5  (original program is made by you)

    (Falling snow thread https://social.msdn.microsoft.com/Forums/en-US/74033665-22e5-4ceb-a080-c7b11fd3e0ba/december-challenge-suggestion-falling-snow?forum=smallbasic)

    2) cannon hit other item...   

       change   TX=shapes.getleft(Tri[4])+230 ,TY=.....(Tri[4])+385 to other shape name and values 

       change if bx<TX+(350-230) and ......bY< TY+(445-385)  to  other shapes's values

       *  tri[4] =  Shapes.Addtriangle(350,445,230,445,350,385)   

         230 means triangle left position , 385 means triangle top position 

          (350-230) means triangle width, (445-385) means triangle height


    Thursday, March 09, 2017 1:48 AM
    Answerer
  • TextWindow Clock Program

    SNS293

    top:
    If Clock.Hour >= 12 Then
      status = "PM"
    Else
      status = "AM"
    EndIf
    CurrentTime = Clock.Hour + " : " + Clock.Minute + " : " + Clock.Second + " " + status
    Day = Clock.WeekDay + " " + Clock.Month + " / " + Clock.Day
    TextWindow.WriteLine("Date: " + day)
    TextWindow.WriteLine("Time: " + CurrentTime)
    Program.Delay(1000)
    TextWindow.Clear()
    Goto top

    Thursday, March 09, 2017 3:22 PM
  • @ Xeltion - good clear answer - try using an infinite while loop rather than Goto - works the same but considered better style - easier to read, debug and modify especially in larger code.
    Thursday, March 09, 2017 6:26 PM
    Moderator
  • This is the fourth step: GRT732-2.

    Screen shot of a program Bowling Game 0.4a


    Nonki Takahashi

    Friday, March 10, 2017 3:54 AM
    Moderator
  • hello will somebody draw S using turtle thankyou.
                                                                          mahreen miangul

    Friday, March 10, 2017 5:28 AM
  • hello will somebody draw S using turtle thankyou.
                                                                          mahreen miangul

    Hello, mahreen miangul.  How about this?

    Δ = 4
    Turtle.Speed = 10
    Turtle.Turn(180)
    For i = 1 To 270 Step Δ
      Turtle.Move(Δ)
      Turtle.Turn(-Δ)
    EndFor
    For a = 1 To 270 Step Δ
      Turtle.Move(Δ)
      Turtle.Turn(Δ)
    EndFor
    


    Nonki Takahashi

    Friday, March 10, 2017 12:07 PM
    Moderator
  • hello will somebody draw S using turtle thankyou.
                                                                          mahreen miangul

    Hello, mahreen miangul.  How about this?

    Δ = 4
    Turtle.Speed = 10
    Turtle.Turn(180)
    For i = 1 To 270 Step Δ
      Turtle.Move(Δ)
      Turtle.Turn(-Δ)
    EndFor
    For a = 1 To 270 Step Δ
      Turtle.Move(Δ)
      Turtle.Turn(Δ)
    EndFor


    Nonki Takahashi

    Hello Nonki

    it's a good idea to use special characters for variable names.
    Especially for math expressions.

    But your turtle "S" looks like a meat hook :-)
    Here is my version:

    Δ = 4
    GraphicsWindow.PenWidth=7
    Turtle.Speed = 10
    Turtle.Turn(90)
    Turtle.Move(45)
    For i = 1 To 180 Step Δ
      Turtle.Move(Δ)
      Turtle.Turn(-Δ)
    EndFor
    For a = 1 To 180 Step Δ
      Turtle.Move(Δ)
      Turtle.Turn(Δ)
    EndFor
    Turtle.Move(45)

    Friday, March 10, 2017 3:24 PM
  • hello turtle is drawing S from down to up make the turtle draw S up to down thankyou

           mahreen miangul   from mussa-maina with love   mahreen miangul

    Saturday, March 11, 2017 5:51 PM
  • hello turtle is drawing S from down to up make the turtle draw S up to down thankyou

           mahreen miangul   from mussa-maina with love   mahreen miangul

    @ mussamaina - Can you do this? - its a good challenge to develop you programming skills!

    Saturday, March 11, 2017 6:12 PM
    Moderator
  • Hi, this is the fifth version: GRT732-3.

    Screen shot of a program Bowling Game 0.5b


    Nonki Takahashi


    Sunday, March 12, 2017 9:16 AM
    Moderator
  • Drawing face by geometric objects NSM030 mahreen miangul

                                                                  mahreen miangul

    Sunday, March 12, 2017 1:16 PM
  • This is my solution for a community suggestion TARTAN: NHB574.

    Screen shot of a program Draw Tartan 0.1


    Nonki Takahashi

    Wednesday, March 15, 2017 8:41 AM
    Moderator
  • This is my solution for a community suggestion KUMIKO: DBD871.

    Screen shot of a program Draw Kumiko 0.1


    Nonki Takahashi

    Wednesday, March 15, 2017 9:07 AM
    Moderator
  •  KUMIKO pattern-7  (Ladybirds in KUMIKO)    WGK825

    Thursday, March 16, 2017 3:09 AM
    Answerer
  • hello everybody with love from mussa-maina ID MLF481

                                                                                   mahreen miangul

    Wednesday, March 22, 2017 12:30 PM
  • hello in program
    GraphicsWindow.Width=1180
    GraphicsWindow.height=420
    GraphicsWindow.top=0
    GraphicsWindow.left=0
    GraphicsWindow.BackgroundColor="blue"

    x=0
    GraphicsWindow.BrushColor="yellow"
    Image= Shapes.Addtext("mahreen miangul")
    forward()

    Sub forward
      While 1=1
    Shapes.Move(Image,x,20)
    x=x+1
    If x > 755 Then
      reverse()
      EndIf
      Program.Delay(10)
      endwhile
    EndSub

    sub reverse
      While 1=1
    Shapes.Move(Image,x,20)
    x=x-1
      If x =-55 Then
        forward()
        EndIf
        Program.Delay(10)
       endwhile
     EndSub

    the text is moving on the screen but i have put a sprite insted of the text

    ' moving Sprite on Window
    GraphicsWindow.Width=1180
    GraphicsWindow.height=420
    GraphicsWindow.top=0
    GraphicsWindow.left=0
    GraphicsWindow.BackgroundColor="blue"
    MakeSprite()
    x=0
     
    Sub MakeSprite
      ' 7 Rectangle
      GraphicsWindow.BrushColor="green"
      rec[1] =  Shapes.AddRectangle(50,8)  '<--  
      Shapes.Move(rec[1], 440,115)
      rec[2] =  Shapes.AddRectangle(50,8)  '<--  
      Shapes.Move(rec[2], 440,140)
      GraphicsWindow.brushcolor = "sienna"
      rec[3] =  Shapes.AddRectangle(60,6)  '<--  
      Shapes.Move(rec[3], 355,120)
      rec[4] =  Shapes.AddRectangle(60,6)  '<--  
      Shapes.Move(rec[4], 355,138)
      GraphicsWindow.brushcolor = "darkgoldenrod"
      rec[5] =  Shapes.AddRectangle(100,22)  '<--  
      Shapes.Move(rec[5], 400,120)
      ' 7 Ellipses
      GraphicsWindow.BrushColor="bisque"
      ell[1] =  Shapes.AddEllipse(30,20)
      Shapes.Move(ell[1], 520,90)
      ell[2] =  Shapes.AddEllipse(30,20)
      Shapes.Move(ell[2], 520,150)
       GraphicsWindow.BrushColor="purple"
      ell[3] =  Shapes.AddEllipse(70,70)
      Shapes.Move(ell[3], 500,95)
      GraphicsWindow.BrushColor="sienna"
      ell[4] =  Shapes.AddEllipse(30,10)
      Shapes.Move(ell[4], 520,120)
      GraphicsWindow.BrushColor="pink"
      ell[5] =  Shapes.AddEllipse(10,30)
      Shapes.Move(ell[5], 510,115)
      GraphicsWindow.BrushColor="cyan"
      ell[6] =  Shapes.AddEllipse(30,20)
      Shapes.Move(ell[6], 530,102)
      ell[7] =  Shapes.AddEllipse(30,20)
      Shapes.Move(ell[7], 530,128)
      ' 1 triangles
      GraphicsWindow.BrushColor="gold"
      tri[1] =  Shapes.Addtriangle(566,100,611,130,566,160)
      Shapes.Move(tri[1], 0,0)
     
    EndSub

    forward()
    Sub forward
      While 1=1
    Shapes.Move("sprite",x,20)
    x=x+1
    If x > 755 Then
      reverse()
      EndIf
      Program.Delay(10)
      endwhile
    EndSub

    sub reverse
      While 1=1
    Shapes.Move("sprite",x,20)
    x=x-1
      If x =-55 Then
        forward()
        EndIf
        Program.Delay(10)
       endwhile
     EndSub
    why is the sprite not moving

                         thankyou         mahreen miangul

    Friday, March 24, 2017 4:29 PM
  • In your second program, you try to move a shape called "sprite" , but you have NO shape called "sprite" 

    Jan [ WhTurner ] The Netherlands

    Friday, March 24, 2017 6:40 PM
    Answerer
  • hello i have added line makesprite and have made sprite what else should i do atleast you should explain in a little detail if not full detail two or three words are not explaining thankyou                                  mahreen miangul


    • Edited by mussamaina Saturday, March 25, 2017 5:14 AM spelling mistake
    Saturday, March 25, 2017 5:11 AM
  • You have to use the technique which NaochanON used in your Februari 2017 topic (posting of Febr. 26).:

    Put all the parts into ONE shape, and move that shape.


    Jan [ WhTurner ] The Netherlands

    Saturday, March 25, 2017 12:33 PM
    Answerer
  • Here is a program that does what you want:

    ' moving Sprite on Window
    GraphicsWindow.Width=1180
    GraphicsWindow.height=420
    GraphicsWindow.top=0
    GraphicsWindow.left=0
    GraphicsWindow.BackgroundColor="blue"
    MakeSprite()
    x=0
    forward()
    
    Sub MakeSprite
      ' 5 Rectangles
      GraphicsWindow.BrushColor="green"
      sprite[1] =  Shapes.AddRectangle(50,8)  '<--  
      posX[1]=440
      posY[1]=115
      Shapes.Move(sprite[1], 440,115)
      sprite[2] =  Shapes.AddRectangle(50,8)  '<--  
      posX[2]=440
      posY[2]=140
      Shapes.Move(sprite[2], 440,140)
      GraphicsWindow.brushcolor = "sienna"
      sprite[3] =  Shapes.AddRectangle(60,6)  '<--  
      posX[3]=355
      posY[3]=120
      Shapes.Move(sprite[3], 355,120)
      sprite[4] =  Shapes.AddRectangle(60,6)  '<--  
      posX[4]=355
      posY[4]=138
      Shapes.Move(sprite[4], 355,138)
      GraphicsWindow.brushcolor = "darkgoldenrod"
      sprite[5] =  Shapes.AddRectangle(100,22)  '<--  
      posX[5]=400
      posY[5]=120
      Shapes.Move(sprite[5], 400,120)
      
      ' 7 Ellipses
      GraphicsWindow.BrushColor="bisque"
      sprite[6] =  Shapes.AddEllipse(30,20)
      posX[6]=520
      posY[6]=90
      Shapes.Move(sprite[6], 520,90)
      sprite[7] =  Shapes.AddEllipse(30,20)
      posX[7]=520
      posY[7]=150
      Shapes.Move(sprite[7], 520,150)
      GraphicsWindow.BrushColor="purple"
      sprite[8] =  Shapes.AddEllipse(70,70)
      posX[8]=500
      posY[8]=95
      Shapes.Move(sprite[8], 500,95)
      GraphicsWindow.BrushColor="sienna"
      sprite[9] =  Shapes.AddEllipse(30,10)
      posX[9]=520
      posY[9]=120
      Shapes.Move(sprite[9], 520,120)
      GraphicsWindow.BrushColor="pink"
      sprite[10] =  Shapes.AddEllipse(10,30)
      posX[10]=510
      posY[10]=115
      Shapes.Move(sprite[10], 510,115)
      GraphicsWindow.BrushColor="cyan"
      sprite[11] =  Shapes.AddEllipse(30,20)
      posX[11]=530
      posY[11]=102
      Shapes.Move(sprite[11], 530,102)
      sprite[12] =  Shapes.AddEllipse(30,20)
      posX[12]=530
      posY[12]=128
      Shapes.Move(sprite[12], 530,128)
      
      ' 1 triangle
      GraphicsWindow.BrushColor="gold"
      sprite[13] =  Shapes.Addtriangle(566,100,611,130,566,160)
      posX[13]=0
      posY[13]=0
      Shapes.Move(sprite[13], 0,0)
      
    EndSub
    
    Sub forward
      While 1=1
        For i=1 To Array.GetItemCount(sprite)
          Shapes.Move(sprite[i],x+posX[i],posY[i])
        endfor
        x=x+1
        If x > 755 Then
          reverse()
        EndIf
        Program.Delay(10)
      endwhile
    EndSub
    
    sub reverse
      While 1=1
        For i=1 To Array.GetItemCount(sprite)
          Shapes.Move(sprite[i],x+posX[i],posY[i])
        endfor
        x=x-1
        If x =-355 Then
          forward()
        EndIf
        Program.Delay(10)
      endwhile
    EndSub


    Jan [ WhTurner ] The Netherlands

    Saturday, March 25, 2017 1:37 PM
    Answerer
  • hello a very good one thankyou
                                                                  mahreen miangul
    Saturday, March 25, 2017 1:49 PM
  •  KUMIKO pattern-7  (Ladybirds in KUMIKO)    WGK825

     Ladybird moving around diamond  WGK825-0

    Sunday, March 26, 2017 6:00 AM
    Answerer
  • hello and God bless you one problem solved and two comes up ' moving balloon on Window cannon fire by key F
    GraphicsWindow.Width=1180
    GraphicsWindow.height=420
    GraphicsWindow.top=0
    GraphicsWindow.left=0
    GraphicsWindow.BackgroundColor="blue"

    cannon1_x = 500
    cannon1_y = 300
    balloon1_x = 0
    balloon1_y = 20

    Makeballoon()
    x=0
    forward()
    GraphicsWindow.KeyDown = moveCannon
    GraphicsWindow.Show()

    cannon = Shapes.AddRectangle(50,100)
    Shapes.Move(cannon, cannon1_x, cannon1_y)
    Shapes.Move(balloon, balloon1_x, balloon1_y)
    GraphicsWindow.BrushColor="Black"
    Ball=Shapes.AddEllipse(40,40)
    Shapes.Move(Ball,cannon1_x+5,cannon1_y+30)
    Shapes.HideShape(Ball)
    Timer.interval=500
    Timer.tick=OnTimerTick
    Flag="True"
    moveBalloon()
    Sub MoveBalloon
      Shapes.ShowShape(Balloon)
    While "True"
      For moveBalloon = 1 To GraphicsWindow.Width-50
        Shapes.Move(balloon, moveBalloon, balloon1_y)
        Program.Delay(15)
      EndFor   

      For moveBalloon = GraphicsWindow.Width-50 To 1 Step -1
        Shapes.Move(balloon, moveBalloon, balloon1_y)
        Program.Delay(15)
      EndFor
    EndWhile
    EndSub
    Sub moveCannon
      If GraphicsWindow.LastKey = "D" Then
        Shapes.Rotate(cannon,angle+5)
        angle=angle+5

      ElseIf GraphicsWindow.LastKey = "A" Then
        Shapes.Rotate(cannon,angle-5)
        angle=angle-5
      ElseIf GraphicsWindow.LastKey="F" then
        Shapes.Animate(ball,GraphicsWindow.width/2,balloon1_y-60,600)
        Shapes.ShowShape(Ball)
    Timer.Resume()

      EndIf
    EndSub
    Sub OnTimerTick
      Timer.Pause()
      If moveballoon > (GraphicsWindow.width/2)-15 And moveballoon < (GraphicsWindow.Width/2)+15 then
      moveBalloon() 'rests balloon back to beginning
      EndIf
        Shapes.HideShape(Ball)
      Shapes.Move(Ball,cannon1_x+5,cannon1_y+30)
    EndSub

    Sub Makeballoon
      ' 5 Rectangles
      GraphicsWindow.BrushColor="green"
      balloon[1] =  Shapes.AddRectangle(50,8)  '<--  
      posX[1]=440
      posY[1]=115
      Shapes.Move(balloon[1], 440,115)
      balloon[2] =  Shapes.AddRectangle(50,8)  '<--  
      posX[2]=440
      posY[2]=140
      Shapes.Move(balloon[2], 440,140)
      GraphicsWindow.brushcolor = "sienna"
      balloon[3] =  Shapes.AddRectangle(60,6)  '<--  
      posX[3]=355
      posY[3]=120
      Shapes.Move(balloon[3], 355,120)
      balloon[4] =  Shapes.AddRectangle(60,6)  '<--  
      posX[4]=355
      posY[4]=138
      Shapes.Move(balloon[4], 355,138)
      GraphicsWindow.brushcolor = "darkgoldenrod"
      balloon[5] =  Shapes.AddRectangle(100,22)  '<--  
      posX[5]=400
      posY[5]=120
      Shapes.Move(balloon[5], 400,120)

      ' 7 Ellipses
      GraphicsWindow.BrushColor="bisque"
      balloon[6] =  Shapes.AddEllipse(30,20)
      posX[6]=520
      posY[6]=90
      Shapes.Move(balloon[6], 520,90)
      balloon[7] =  Shapes.AddEllipse(30,20)
      posX[7]=520
      posY[7]=150
      Shapes.Move(balloon[7], 520,150)
      GraphicsWindow.BrushColor="purple"
      balloon[8] =  Shapes.AddEllipse(70,70)
      posX[8]=500
      posY[8]=95
      Shapes.Move(balloon[8], 500,95)
      GraphicsWindow.BrushColor="sienna"
      balloon[9] =  Shapes.AddEllipse(30,10)
      posX[9]=520
      posY[9]=120
      Shapes.Move(balloon[9], 520,120)
      GraphicsWindow.BrushColor="pink"
      balloon[10] =  Shapes.AddEllipse(10,30)
      posX[10]=510
      posY[10]=115
      Shapes.Move(balloon[10], 510,115)
      GraphicsWindow.BrushColor="cyan"
      balloon[11] =  Shapes.AddEllipse(30,20)
      posX[11]=530
      posY[11]=102
      Shapes.Move(balloon[11], 530,102)
      balloon[12] =  Shapes.Addellipse(30,20)
      posX[12]=530
      posY[12]=128
      Shapes.Move(balloon[12], 530,128)

      ' 1 triangle
      GraphicsWindow.BrushColor="gold"
      balloon[13] =  Shapes.Addtriangle(566,100,611,130,566,160)
      posX[13]=0
      posY[13]=0
      Shapes.Move(balloon[13], 0,0)

      chrome=GraphicsWindow.getcolorfromrgb(215,219,213)
        GraphicsWindow.brushcolor=chrome
      balloon[14] =  Shapes.Addtriangle(585,405,585,420,450,390)
      posX[14]= 0
      posY[14]= 0
        GraphicsWindow.BrushColor="#000000"
      balloon[15] =  Shapes.Addtriangle(350,445,230,445,350,385)
      posX[15]= 0
      posY[15]= 0

      ' piston cylinder

      GraphicsWindow.brushcolor=chrome
      balloon[16] =  Shapes.Addrectangle(150,20)
     posX[16]= 585
      posY[16]= 405

      balloon[17] =  Shapes.Addrectangle(90,30)
      posX[17]= 360
      posY[17]= 380

    EndSub

    Sub forward
      While 1=1
        For i=1 To Array.GetItemCount(balloon)
          Shapes.Move(balloon[i],x+posX[i],posY[i])
        endfor
        x=x+1
        If x > 755 Then
          reverse()
        EndIf
        Program.Delay(10)
      endwhile
    EndSub

    sub reverse
      While 1=1
        For i=1 To Array.GetItemCount(balloon)
          Shapes.Move(balloon[i],x+posX[i],posY[i])
        endfor
        x=x-1
        If x =-355 Then
          forward()
        EndIf
        Program.Delay(10)
      endwhile
    EndSub
    animation appeared but the cannon disapeared when cannon apeares animation stops  balloon and cannon does not work at the same time                                          mahreen miangul


                           
    Tuesday, March 28, 2017 5:33 AM
  • hello and God bless you one problem solved and two comes up ' moving balloon on Window cannon fire by key F
    GraphicsWindow.Width=1180
    GraphicsWindow.height=420
    GraphicsWindow.top=0
    GraphicsWindow.left=0
    GraphicsWindow.BackgroundColor="blue"

    cannon1_x = 500
    cannon1_y = 300
    balloon1_x = 0
    balloon1_y = 20

    Makeballoon()
    x=0
    forward()  <------------


                           

     1)your program is on forward() . ( balloon moves to right or left direction . don't go next stage)

     2)Sub OnTimerTick and Sub MoveBalloon are unnecessary.

    shortened version is below.

    GraphicsWindow.KeyDown = moveCannon
    GraphicsWindow.Width=1180
    GraphicsWindow.height=420
    GraphicsWindow.top=0
    GraphicsWindow.left=0
    GraphicsWindow.BackgroundColor="blue"
    cannon1_x = 500
    cannon1_y = 300
    balloon1_x = 0
    balloon1_y = 20
    Makeballoon()
    cannon = Shapes.AddRectangle(50,100)
    Shapes.Move(cannon, cannon1_x, cannon1_y)
    Shapes.Move(balloon, balloon1_x, balloon1_y)
    GraphicsWindow.BrushColor="Black"
    Ball=Shapes.AddEllipse(40,40)
    Shapes.Move(Ball,cannon1_x+5,cannon1_y+30)
    Shapes.HideShape(Ball)
    Flag="False"
    by=2  '  ball speed Y-direction
    X=1

    While 1=1
      For i=1 To Array.GetItemCount(balloon)
        Shapes.Move(balloon[i],x+Shapes.GetLeft(balloon[i]),Shapes.Gettop(balloon[i]))
      endfor
      If Shapes.GetLeft(balloon[1]) > 1200 or Shapes.GetLeft(balloon[1])<-5 Then
        X=-X  '  reverse moving direction
      EndIf
      If flag="True" Then
        bx= angle/math.Abs(angle+0.000001)  '  ball speed X-direction // 0.000001 to avoid zero division
        Shapes.Move(ball,shapes.GetLeft(ball)+bx,shapes.Gettop(ball)-by)
        If Shapes.GetTop(ball)<-100 then   '  ball Y-position is <-100
          Shapes.HideShape(Ball)           '  ball  disappear
          Shapes.Move(Ball,cannon1_x+5,cannon1_y+30)  '  ball moves to cannon position
          Flag="False"
        EndIf
      EndIf
      Program.Delay(10)
    endwhile

    Sub moveCannon
      If flag="False" Then
        If GraphicsWindow.LastKey = "D" Then
          angle=angle+5
          Shapes.Rotate(cannon,angle)
        ElseIf GraphicsWindow.LastKey = "A" Then
          angle=angle-5
          Shapes.Rotate(cannon,angle)
        ElseIf GraphicsWindow.LastKey="F" then
          flag="True"
          Shapes.ShowShape(Ball)
        EndIf
      endif
    EndSub

    Sub Makeballoon
      ' 5 Rectangles
      GraphicsWindow.BrushColor="green"
      balloon[1] =  Shapes.AddRectangle(50,8)  '<-- 
      Shapes.Move(balloon[1], 440,115)
      balloon[2] =  Shapes.AddRectangle(50,8)  '<-- 
      Shapes.Move(balloon[2], 440,140)
      GraphicsWindow.brushcolor = "sienna"
      balloon[3] =  Shapes.AddRectangle(60,6)  '<-- 
      Shapes.Move(balloon[3], 355,120)
      balloon[4] =  Shapes.AddRectangle(60,6)  '<-- 
      Shapes.Move(balloon[4], 355,138)
      GraphicsWindow.brushcolor = "darkgoldenrod"
      balloon[5] =  Shapes.AddRectangle(100,22)  '<-- 
      Shapes.Move(balloon[5], 400,120)
      ' 7 Ellipses
      GraphicsWindow.BrushColor="bisque"
      balloon[6] =  Shapes.AddEllipse(30,20)
      Shapes.Move(balloon[6], 520,90)
      balloon[7] =  Shapes.AddEllipse(30,20)
      Shapes.Move(balloon[7], 520,150)
      GraphicsWindow.BrushColor="purple"
      balloon[8] =  Shapes.AddEllipse(70,70)
      Shapes.Move(balloon[8], 500,95)
      GraphicsWindow.BrushColor="sienna"
      balloon[9] =  Shapes.AddEllipse(30,10)
      Shapes.Move(balloon[9], 520,120)
      GraphicsWindow.BrushColor="pink"
      balloon[10] =  Shapes.AddEllipse(10,30)
      Shapes.Move(balloon[10], 510,115)
      GraphicsWindow.BrushColor="cyan"
      balloon[11] =  Shapes.AddEllipse(30,20)
      Shapes.Move(balloon[11], 530,102)
      balloon[12] =  Shapes.Addellipse(30,20)
      Shapes.Move(balloon[12], 530,128)
      ' 1 triangle
      GraphicsWindow.BrushColor="gold"
      balloon[13] =  Shapes.Addtriangle(566,100,611,130,566,160)
      Shapes.Move(balloon[13], 0,0)
      chrome=GraphicsWindow.getcolorfromrgb(215,219,213)
      GraphicsWindow.brushcolor=chrome
      balloon[14] =  Shapes.Addtriangle(585,405,585,420,450,390)
      GraphicsWindow.BrushColor="#000000"
      balloon[15] =  Shapes.Addtriangle(350,445,230,445,350,385)
      ' piston cylinder
      GraphicsWindow.brushcolor=chrome
      balloon[16] =  Shapes.Addrectangle(150,20)
      Shapes.Move(balloon[16], 585,405)
      balloon[17] =  Shapes.Addrectangle(90,30)
      Shapes.Move(balloon[17], 360,380)
    EndSub

    Tuesday, March 28, 2017 1:22 PM
    Answerer
  • The first fired ball (without turning cannon) gives an error.

    Solved by adding angle=0 before the While 1=1

    if you change the equation for bx to bx=by*Math.Tan(Math.GetRadians(angle))  the ball goes in the direction of the cannon.


    Jan [ WhTurner ] The Netherlands



    Tuesday, March 28, 2017 1:35 PM
    Answerer
  • 2 ladybugs spinning: WGK825-1
    Thursday, March 30, 2017 3:20 AM
  • inspired by mahreen to drive some roads: MGK278

    Thursday, March 30, 2017 4:03 AM
  • WGK825-2

    Lady birds move around. ver-2  

    quadrant and angle(degrees) are calculated as below.

    Sub calc
      dt="1:-1=pm\=-1\;rad\=90\;;-1:-1=pm\=1\;rad\=-90\;;-1:1=pm\=-1\;rad\=-90\;;1:1=pm\=1\;rad\=90\;;"'  quadrant 1,2,3,4
      qX=Math.Round((ddX)/(math.Abs(ddX)+0.0000001))
      qY=Math.Round((ddY)/(math.Abs(ddY)+0.0000001))
      qd=text.Append(text.Append(qX,":"),qY) '   quadrant   
      deg=math.Abs(Math.GetDegrees(Math.ArcTan((ddY)/(ddX+0.0000000001))))  '  angle //degrees  abs
      dS= dt[qd]["pm"]*deg + dt[qd]["rad"]
    EndSub



    Thursday, March 30, 2017 4:04 AM
    Answerer