# Challenge of the Month - December 2015

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

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

Small Challenges

• Write a program to draw a tree in the GraphicsWindow.
• Write a program to input and sum 5 numbers input by a user.
• Write a program to spell check the words in a sentense (use the Dictionary object).
• Write a program to play a few lines from your national anthem (use the Sound.PlayMusic method).

Maths Challenges - Project Euler

We had some of these challenges several years ago, but here are the first 5 again.  The full set (some very hard) can be found https://projecteuler.net/archives.

• 1] Multiples of 3 and 5

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9.  The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.

• 2] Even Fibonacci numbers

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

• 3] Largest prime factor

The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?

• 4] Largest palindrome product

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.

Find the largest palindrome made from the product of two 3-digit numbers.

• 5] Smallest multiple

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.

What is the smallest positive number that is divisible with no remainder "evenly divisible" by all of the numbers from 1 to 20?

Community Suggestion (By JetFire3201)

• Could we do a stickman running animation challenge?
• Suggestion - Create an animated stickman that can run and jump with animated limbs reacting to key presses.

Community Suggestions (By Zock77)

This is a facinating, but pretty tough challenge by Zock77.

• Check this out!  It is so cool!

• Suggestion - Perhaps create a simple Artificial Neural Net (ANN) program that can be trained to a simple task like approximating an equation curve.

More Challenges

• Find the square root without using Math.SquareRoot (or any Math object methods if you can).
• Draw an ellipse using lines. (easy)
• Or for something more challenging: Make a filled ellipse without using ellipse methods.
• Write a program to find the GCF (Greatest Common Factor) of two numbers.

Community Suggestions (By Jibba Jabba)

We have a whole set of progressive graphical challenges by Jibba Jabba.  Complete these and you will be right up there!

Use a Main loop for these and try nuzzling them into game loop structure.

Basic Motion

1. Make a square shape move from left to right of screen at a constant speed.
2. Using arrays, place 2 more shapes on top of this shape and have them move in tandem.

1. Make a circular shape move from the top to bottom of the GW at a constant speed.
2. Now make this shape move on the same path from a standing start under the influence of gravity
3. Now add friction/drag to this.

1. Make a shape move horizontally across the screen bouncing off the edges with constant speed.
2. Make a shape bounce from top to bottom from a standing start under the influence of gravity.
3. Now add friction to this. Eventually the shape should stop.

1. Make a shape move randomly all over the screen at a constant speed.
2. Maybe apply some acceleration to this.

1. Make a shape move in a circular path around a stationary shape placed in the centre.
2. Add a satellite to this orbiting body.
3. Have a go at changing the orbit to an elliptical path
4. Add a continuous random barrage of asteroids that respond to any collisions

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

• Make a step up game where a ball bounces up a set of steps. User can move the ball left and right.
• Make a calculator.  For a nice GUI check out Nonki's website.
• Make some interesting Backgrounds. There was a recent blog on this by Nonki.
• Also make some interesting gradient backgrounds, can use RGB, random or constant fills for this. The backgrounds don't have to be full window. If you make them extensible they can become part of your own code library.

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

• For advanced collision model some random balls colliding into each other.

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

• Edited by Tuesday, December 1, 2015 8:59 PM extra Zock challenge added
Monday, November 30, 2015 9:05 PM

### All replies

• My first program for the AI program.

I am pretty sure I did this wrong, so if Litdev or Nonki or someone could look it over thad be great.

```GraphicsWindow.Height = 475
GraphicsWindow.Width = 650
GraphicsWindow.BrushColor = "Black"

Target[1] = 23
Target[2] = 30

InputValue[1] = 80
InputValue[2] = 24
InputValue[3] = 60

NumberGenomes = 50
GenerationNum = 1
MinError = 1000000

Shapes.Move(FitnessText,100,380)
Shapes.Move(MaxFitnessText,100,400)
Shapes.Move(GenerationText,100,420)
Shapes.Move(GenomeText,100,440)

For i = 1 To 3
For u = 1 To 3
SynapseWeight[i][u][1] = Math.GetRandomNumber(10)/10
EndFor
For o = 1 To 2
SynapseWeight[i][o][2] = Math.GetRandomNumber(10)/10
EndFor
Shapes.Move(NueronShape[i],300,i*100)
LDShapes.BrushColour(NueronShape[i],"Cyan")
Shapes.Move(NueronText[i],300+18,(i*100)+18)
EndFor

For i = 1 To 3
Shapes.Move(InputShape[i],100,i*100)
LDShapes.BrushColour(InputShape[i],"Yellow")
Shapes.Move(InputText[i],100+18,(i*100)+18)
EndFor

For i = 1 To 2
Shapes.Move(OutputShape[i],500,(i*100)+50)
LDShapes.BrushColour(OutputShape[i],"White")
Shapes.Move(OutputText[i],500+18,(i*100)+68)
EndFor

While MinError <> 0
Program.Delay(15)
OutputValue[1] = ""
OutputValue[2] = ""
NueronValue[1] = ""
NueronValue[2] = ""
NueronValue[3] = ""
GenerationNum = GenerationNum + 1
SynapseWeight = SynapseData
EndIf

For i = 1 To 3
For u = 1 To 3
CalculateError()
If CalcSynapse Then
SynapseWeight[i][u][1] =  Math.GetRandomNumber(10)/10
EndIf
LDShapes.PenWidth(Synapse[i][u][1],2+(SynapseWeight[i][u][1]*6))
NueronRawValue[i][u] = InputValue[u] * SynapseWeight[i][u][1]
NueronValue[i] = NueronValue[i] + NueronRawValue[i][u]
EndFor
NueronValue[i] = Math.Round(NueronValue[i] / 3)
For o = 1 To 2
CalculateError()
If CalcSynapse Then
SynapseWeight[i][o][2] = Math.GetRandomNumber(10)/10
EndIf

LDShapes.PenWidth(Synapse[i][o][2],2+(SynapseWeight[i][o][2]*6))
OutputRawValue[i][o] = NueronValue[i] * SynapseWeight[i][o][2]
OutputValue[o] = OutputValue[o] + OutputRawValue[i][o]
EndFor
Shapes.SetText(NueronText[i],NueronValue[i])
EndFor
TotalError = ""
For r = 1 To 2
OutputValue[r] = Math.Round(OutputValue[r]/3)
Shapes.SetText(OutputText[r],OutputValue[r])
ErrorDist[r] = Math.Abs(OutputValue[r]-Target[r])
TotalError = TotalError + ErrorDist[r]
EndFor
If TotalError < MinError Then
MinError = TotalError
SynapseData[BestGenome] = SynapseWeight
ErrorPercent = 100-((MinError/200)*100)
SynapseData = SynapseWeight
EndIf
Shapes.SetText(FitnessText, "Fitness: " + TotalError)
Shapes.SetText(MaxFitnessText, "MaxFitness: " + MinError)
Shapes.SetText(GenerationText, "Generation: " + GenerationNum)
EndWhile

Sub CalculateError
Rand = Math.GetRandomNumber(100)
If ErrorPercent < Rand Then
CalcSynapse = "True"
Else
CalcSynapse = "False"
EndIf
EndSub```

Oh yeah. I also used LDShapes, but its only for the visualization, and not for function.

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, December 2, 2015 12:51 AM
• Or with three outputs: NKZ435

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, December 2, 2015 12:56 AM
• Or with three outputs: NKZ435

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

Your program works well and clearly can find the 'hidden layer' wieghts required to linearly combine 3 input values to find 3 outputs using a genetic algorithm type optimiser.  Often there is not an exact optimal solution (yours actually has several exact solutions) so you may want to terminate the optimiser when we are quite close or see little improvement for a lot of exra work.

How about trying to solve the 'travelling salesman' problem.

Nice work.

Wednesday, December 2, 2015 6:46 PM

Small Basic Challenges of the Month - December 2015 (turtle, tree, your national anthem, Euler, stickman, AI, and more!)

Ed Price, Azure & Power BI Customer Program Manager (Blog, Small Basic, Wiki Ninjas, Wiki)

Friday, December 4, 2015 8:59 PM
• Here's my solution to the Step Up game: Step Up to Level 10

I coded this last year and it's a personal favourite because it's progressively challenging and simple. It reminds me a bit of Flappy Birds but not as hard and short.

I've hung it in the gallery because I plan on upgrading it.

Monday, December 7, 2015 12:03 AM
• Here's my solution to find GCF: QGW926

Is there a simple way to determine if a non numerical value is entered in a textbox?

---sort of like tb1 * tb2

that doesn't return zero?

Also code for extension: ext

Monday, December 7, 2015 8:09 PM
• Hi JJ, how about (same for TB):

TextWindow.WriteLine(1 * "string")  ' -> 0
TextWindow.WriteLine("string" + 0)  ' compare Len vs. Len("string")

Zock's challenge: Make a filled ellipse without using ellipse methods. If 'DrawLine' is allowed, eg.:

a = 350 ' 200
b = 200 ' 350

'GraphicsWindow.PenWidth = 1

GraphicsWindow.PenColor = "Red"
For x = 0 To a
y = b * Math.SquareRoot(1 - x*x/a/a)
GraphicsWindow.DrawLine(a+x,b-y, a+x,b+y) ' right side
GraphicsWindow.DrawLine(a-x,b-y, a-x,b+y) ' left side
EndFor

ditto for Hyperbel ID: WXM333 and Parabel ID: FTZ689

Monday, December 7, 2015 8:19 PM
• Hey yeah. Thanks PL

```tb = Controls.AddTextBox(10, 10)
btn = Controls.AddButton("  ", 10, 40)
Controls.ButtonClicked = BC
Sub BC
If Text.GetLength(Controls.GetTextBoxText(tb) + 0) = Text.GetLength(Controls.GetTextBoxText(tb)) Then
GraphicsWindow.ShowMessage("is num" "")
Else
GraphicsWindow.ShowMessage("is string" "")
EndIf
EndSub```

Monday, December 7, 2015 9:33 PM
• GCD challenge:

```TextWindow.Write("Enter the first number: ")
TextWindow.Write("Enter the second number: ")

For i = 1 To Math.Max(Num1,Num2)
If Math.Remainder(Math.Max(Num1,Num2),i) = 0 Then
If Math.Remainder(Math.Min(Num1,Num2),i) = 0 Then
GCD = i
EndIf
EndIf
EndFor

TextWindow.WriteLine("The greatest common denomonator is " + GCD)```

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

Monday, December 7, 2015 9:49 PM
• Fill ellipse:

```  Width = 100
Height = 50

GraphicsWindow.PenColor = "Red"

For i = 0 To 314
DX = Math.Cos((i+314)/100) * Width
DY = Math.Sin((i+314)/100) * Height
X = Math.Cos(i/100) * Width
Y = Math.Sin(i/100) * Height
GraphicsWindow.DrawLine(x+200,y+200,DX+200,DY+200)
EndFor```

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

Monday, December 7, 2015 10:20 PM
• GCD challenge (from LDCall function collection):

arrNum = "1=1155;2=1296;"       ' <-  2 numbers here
TextWindow.Write("gcd for '"+ arrNum +"' = ")
gcdCalc()
TextWindow.WriteLine(return)
TextWindow.WriteLine("")

Sub gcdCalc ' ggTCalc
gcdCnt = Array.GetItemCount(arrNum)
If gcdCnt > 1 Then
While (arrNum[1] <> arrNum[2])
If arrNum[1] > arrNum[2] Then
arrNum[1] = arrNum[1] - arrNum[2]
Else
arrNum[2] = arrNum[2] - arrNum[1]
EndIf
EndWhile
return = arrNum[1]
Else
return = "Error! At least 2 integers needed."
EndIf
gcdCnt = ""
EndSub

Monday, December 7, 2015 11:04 PM
• My solution of GCF  (modified Zock77 version)

sqv= Math.Round(Math.SquareRoot(Math.Max(a,B)))
For i= 2 To sqv
If Math.Remainder(A,i)=0 and Math.Remainder(B,i)=0 Then
max= Math.Max(max,i)
EndIf
EndFor
TextWindow.WriteLine("GCF= "+max)

Monday, December 7, 2015 11:56 PM
• I got 6857 for the largest prime factor.

I cheated though, I used the extensions we built last month. Might write an exploder for the csv strings that puts the values in an array.

Tuesday, December 8, 2015 3:42 AM
• My solution for the largest prime number:

```number=600851475143
TextWindow.Write("Factors of "+number+" : ")
i=3
While i<99999999
while Math.Remainder(number,i)=0
number=number/i
TextWindow.Write(" "+i)
Endwhile
If number=1 then
i=99999999
endif
i=i+2
endwhile
TextWindow.WriteLine("")```
At first I tried to generate an array of primes to test on the given large number. That worked but was slow, The slowest part was the generation of the array. The checking of all the values was so quick, that I decided to test all odd numbers, as in the above program. That was the quickest.

Jan [ WhTurner ] The Netherlands

Tuesday, December 8, 2015 11:50 AM
• 1,2,3,4 gcd/gcf's!  Gcd city here... There4 out of competition: LDCall also supports  Recursion (like for n!, nFib etc.). Just for interest here an ot extension solution for gcd and its big sister lcm. ID: LNX632
Tuesday, December 8, 2015 2:54 PM
• Yep! I have an idea for a challenge: Write a pathmapping program. If you want to do a hard one, you might try to use the A-star algorithm, or for something a little easier, the Breadth-first algorithm.

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

Tuesday, December 8, 2015 5:36 PM
• Nice.
Tuesday, December 8, 2015 10:09 PM
• This is my solution for a small challenge (use the Turtle to follow your mouse): JPQ837.

Nonki Takahashi

Thursday, December 10, 2015 1:24 PM
• Hi,

Here is my Challenge on Small basic Program

1) Simple Car Animation Program http://smallbasic.com/program/?HGP255

1) Simple Small Basic Painting Tool Small Baci Painting Tool - program id - BFM797

Small Basic Car Animation Complete Code

```'Set the Graphics Window size and sow with your title
GraphicsWindow.Show()
GraphicsWindow.Title = "My Simple Animation"
GraphicsWindow.Height = 600
GraphicsWindow.Width = 600

''Set the global variable for draing car for animation
xval=20
yval=160
carWidth=150
carHeight=40

' redraw the car for every time delay
up:
GraphicsWindow.BrushColor = "black"
GraphicsWindow.PenWidth = 2

GraphicsWindow.FillRectangle(0, yval-60, GraphicsWindow.Width, yval+carHeight)

GraphicsWindow.PenColor = "Black"
GraphicsWindow.PenWidth = 2
'for adding the Top Part of Car
GraphicsWindow.DrawRectangle(xval+carWidth/4, yval-carHeight+10, carWidth/2, carHeight-10)
GraphicsWindow.BrushColor = "Orange"
GraphicsWindow.FillRectangle(xval+carWidth/4, yval-carHeight+10, carWidth/2, carHeight-10)
'for adding the Main Part of Car
GraphicsWindow.DrawRectangle(xval, yval, carWidth, carHeight)
GraphicsWindow.BrushColor = "Orange"
GraphicsWindow.FillRectangle(xval, yval, carWidth, carHeight)

'' for Draw Back Wheel
GraphicsWindow.BrushColor = "black"
GraphicsWindow.DrawEllipse(xval+carWidth/12, yval+carHeight, 34, 34)
GraphicsWindow.BrushColor = "gray"
GraphicsWindow.FillEllipse(xval+carWidth/12, yval+carHeight, 34, 34)

'' for Draw Front Wheel
GraphicsWindow.BrushColor = "black"
GraphicsWindow.DrawEllipse(xval+(carWidth-46), yval+carHeight, 34, 34)
GraphicsWindow.BrushColor = "gray"
GraphicsWindow.FillEllipse(xval+(carWidth-46), yval+carHeight, 34, 34)

'for the timer we use this delay
Program.Delay(1000)

'after the delay time we clear all the graphics
GraphicsWindow.Clear()

'using Goto we will again redraw the graphics with new xval position
If xval+carWidth <=GraphicsWindow.Width Then
xval=xval+20
Else
xval=20
EndIf
Goto up```

Small Basic Simple Painting Tool

```'Set the Graphics Window size and sow with your title
GraphicsWindow.Show()
GraphicsWindow.CanResize = "False"
GraphicsWindow.Title = "SHANU SmallBasic Drawing Tool"
GraphicsWindow.Height = 800
GraphicsWindow.Width = 800

'Draw Toolbar
GraphicsWindow.PenColor = "Black"
GraphicsWindow.PenWidth = 1
titles="SHANU SmallBasic Drawing Tool"
GraphicsWindow.DrawBoundText(6, 4, GraphicsWindow.Width, titles)
GraphicsWindow.DrawRectangle(6, 26, GraphicsWindow.Width-12, 70)
drawType=0

'Draw the buttons at the toolbar
drawButtons()

Controls.ButtonClicked = ButtonEvents

Sub drawButtons
Controls.SetSize(clearAll, 80, 40)
freePen = Controls.AddButton("Free PEN Draw", 104, 44)
Controls.SetSize(freePen, 120, 40)
Controls.SetSize(drawImage, 80, 40)
Controls.SetSize(drawRectangle, 80, 40)
Controls.SetSize(fillRectangle, 80, 40)
Controls.SetSize(drawCircle, 80, 40)
Controls.SetSize(fillCircle, 80, 40)
EndSub

''set the Drwaing Area Starting Xval,Yval and width and Height
drawXval=20
drawYval=140
drawWidth=GraphicsWindow.Width-60
drawHeight=GraphicsWindow.Height-200

'' Draw the Draw Area inside this area we will draw
GraphicsWindow.DrawRectangle(drawXval, drawYval, drawWidth,  drawHeight)

'' Check for the button clieked event and perform the action
Sub ButtonEvents
buttonText = Controls.GetButtonCaption(Controls.LastClickedButton)

If buttonText = "ClearALL" Then
' Clear the draw Area for redraw
drawType=1
GraphicsWindow.BrushColor="white"
GraphicsWindow.FillRectangle(drawXval, drawYval, drawWidth,  drawHeight)

ElseIf buttonText = "Free PEN Draw" Then
' Draw the Free Pen
drawType=2
ElseIf buttonText = "Image" Then
' Add Image in draw area
drawType=3

ElseIf buttonText = "Rectangle" Then
' Draw Rectangle in draw area
drawType=4
ElseIf buttonText = "FillRectangle" Then
' Fill Rectangle in draw area
drawType=5
ElseIf buttonText = "Circle" Then
' Draw Circle in draw area
drawType=6
ElseIf buttonText = "Fill Circle" Then
' Draw Circle in draw area
drawType=7

EndIf
EndSub

'Mouse Click Events

'here we check for draw type and if the dray type is
GraphicsWindow.MouseDown = MouseClick
Sub MouseClick
OrgX = GraphicsWindow.MouseX
OrgY = GraphicsWindow.MouseY

' If the Drawtype is 3 then its for Image Add
If drawType=3 Then
if OrgX >drawXval And OrgX<drawWidth Then
if OrgY >drawYval And OrgY<drawHeight+drawYval-6 Then
image2 = "C:\ShanuICON.jpg"

GraphicsWindow.DrawResizedImage(image2, OrgX, OrgY, 80, 80)

EndIf
EndIf
'-- end Draw Image
' to Draw Rectangle
ElseIf drawType=4 Then
if OrgX >drawXval And OrgX<drawWidth Then
if OrgY >drawYval And OrgY<drawHeight+drawYval-6 Then
GraphicsWindow.DrawRectangle(OrgX, OrgY, 60,  60)
EndIf
EndIf
' to Fill Rectangle
ElseIf drawType=5 Then
if OrgX >drawXval And OrgX<drawWidth Then
if OrgY >drawYval And OrgY<drawHeight+drawYval-6 Then
GraphicsWindow.FillRectangle(OrgX, OrgY, 60,  60)
EndIf
EndIf
' to Draw Circle
ElseIf drawType=6 Then
if OrgX >drawXval And OrgX<drawWidth Then
if OrgY >drawYval And OrgY<drawHeight+drawYval-6 Then
GraphicsWindow.DrawEllipse(OrgX, OrgY, 60,  60)
EndIf
EndIf
' to Fill Circle
ElseIf drawType=7 Then
if OrgX >drawXval And OrgX<drawWidth Then
if OrgY >drawYval And OrgY<drawHeight+drawYval-6 Then
GraphicsWindow.FillEllipse(OrgX, OrgY, 60,  60)
EndIf
EndIf
EndIf

EndSub

'Mouse Move event is used to draw the free pen
GraphicsWindow.MouseMove = MouseDrag

Sub MouseDrag
x = GraphicsWindow.MouseX
y = GraphicsWindow.MouseY

'If the drawtype is 2 then for Free Pen draw here we will draw the colors with random
If drawType=2 Then
If (Mouse.IsLeftButtonDown) then
if x >drawXval And x<drawWidth Then
if y >drawYval And y<drawHeight+drawYval-6 Then

GraphicsWindow.FillEllipse(x, y, 6, 6)
EndIf

EndIf
Endif
EndIf
'-- fre pen
EndSub

GraphicsWindow.MouseUp   = MouseUp
Sub MouseUp
GraphicsWindow.BrushColor=GraphicsWindow.GetRandomColor()

EndSub```

Monday, December 14, 2015 4:35 AM
• Not easy!

Monday, December 14, 2015 9:22 AM
• Good idea Nonki. Comic style captions.

Monday, December 14, 2015 9:29 AM
• A solution for the "Follow the Mouse" Challenge. I have had this one on hand for quite some time. It one took me a while to get the math right.

```'Follow the mouse - (C)opyright Matthew L. Parets aka codingCat - No Rights Reserved.  :-)

Timer.Interval = 50
Timer.Tick = tock
Turtle.Speed = 6

Sub tock
chgY = GraphicsWindow.MouseY - Turtle.y
chgX = GraphicsWindow.MouseX - Turtle.x
angl = 90 + Math.GetDegrees(Math.ArcTan( (chgy) / (chgX)))
If GraphicsWindow.MouseX-Turtle.x < 0 Then
angl = angl + 180
EndIf
Turtle.Angle = angl

Turtle.Move(10)
EndSub

```

Monday, December 14, 2015 6:41 PM
• Here are my solutions for the first 8 Basic Motion exercises:

1. TGK844-0
2. TJV733-0
3. JFZ089-0
4. PRJ691-0
5. VDQ487-0
6. WZT962-0
7. BTQ589-0
8. DRD234-0
Saturday, December 19, 2015 11:40 PM
• Here's my solution to Basic Motion 9: "Make a shape move randomly all over the screen at a constant speed."

PMD031-0

Has anyone got some pseudo code thoughts on how I could do collision detection for the balls hitting each other and what to do with them when they collide?

Sunday, December 20, 2015 9:54 PM
• This seems to work well if the balls only hit head on: WVB556

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

Tuesday, December 22, 2015 12:01 AM
• Basically since all your collisions will be head on, you can use a formula like this:

```OldDx = Dx[Ball1]
Dx[Ball1] = Dx[Ball2]
Dx[Ball2] = OldDx
OldDy = Dy[Ball1]
Dy[Ball1] = Dy[Ball2]
Dy[Ball2] = OldDy```

Or if you want to take restitution into account:

```OldDx = Dx[Ball1]
Dx[Ball1] = Dx[Ball2]*restitution
Dx[Ball2] = OldDx*restitution
OldDy = Dy[Ball1]
Dy[Ball1] = Dy[Ball2]*restitution
Dy[Ball2] = OldDy*restitution```

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

Tuesday, December 22, 2015 12:06 AM
• Thanks Zock.

When I started coding it I didn't plan on doing collisions for the circles. I'll come back to it.

Wednesday, December 23, 2015 10:13 AM
• I programmed a calculator a few weeks ago and published it on TechNet Gallery. Actually I just found out that this is part of this months challenge.

The calculator can be found here: 123 Calculator.

Wednesday, December 23, 2015 6:29 PM
• Hey Zock,

if too cluncy in WVB556, you could consider eg.

Dx[i] = 2 * Math.GetRandomNumber(2) - 3 '  always returns -1 OR +1
Dy[i] = 2 * Math.GetRandomNumber(2) - 3 '  or  = Dx[i]

Friday, December 25, 2015 11:50 AM
• Used turtle do draw a Christmas tree in Graphics Window (for the small challenge): DVD961
Friday, December 25, 2015 1:35 PM
• 2 really good programs Bluegrams.

If it's ok with Bluegrams maybe someone team in and apply some gradients to the turtle Xmas tree. We did some back in August with Naochans Swimming Shark: with Sardines

Saturday, December 26, 2015 12:58 PM
• Here's my Xmas tree: PMB843  only works for local.
Saturday, December 26, 2015 2:34 PM
• Hey Zock,

if too cluncy in WVB556, you could consider eg.

Dx[i] = 2 * Math.GetRandomNumber(2) - 3 '  always returns -1 OR +1
Dy[i] = 2 * Math.GetRandomNumber(2) - 3 '  or  = Dx[i]

That works great! Thanks!

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

Sunday, December 27, 2015 1:29 AM
• Thought I'd post an image of my Xmas tree.

It's basically just 1 line drawn top to bottom in the centre of the gw.

As line goes down the penwidth increases and pencolor changes using GraphicsWindow.GetColorFromRGB().

The moon is simply a ")" in a wide font.

Tuesday, December 29, 2015 5:27 AM
• 2 really good programs Bluegrams.

If it's ok with Bluegrams maybe someone team in and apply some gradients to the turtle Xmas tree. We did some back in August with Naochans Swimming Shark: with Sardines

Jibba Jabba, could you feature some of these on the blog?

I got one up for today. So maybe tomorrow or later.

Thanks!

Ed Price, Azure & Power BI Customer Program Manager (Blog, Small Basic, Wiki Ninjas, Wiki)

Friday, January 1, 2016 4:48 PM
• Ed. Blog. Yeah no worries. Bluegrams does very tidy work. I like it.
Friday, January 1, 2016 10:08 PM
• 123 Calculator & Christmas Tree Turtle are blogged here.
Wednesday, January 6, 2016 9:15 AM
• This is my idea for a future challenge:

• Make a calendar program with holidays 2016 in your country.

Nonki Takahashi

Friday, January 8, 2016 2:52 PM
• running stickman      GKX860

press  Right or Left key

Monday, January 11, 2016 12:56 PM
• Amazing Naochan. I think you're the grand master of Shapes.
Monday, January 11, 2016 11:48 PM