
-----------------------------------
Robotkubo
Thu Feb 18, 2016 9:34 am

Moving Canada flag project
-----------------------------------
Hey, I've made a thread before about this and since then I've made some progress, but I still need help. My Maple leaf goes crazy, its upside down and changes width and length all the time while moving, Some of the code Is from a bouncing ball template I found, not really sure where :/ if I can remember I'll be sure to edit it in Here (Idk)
My project is due really soon so if someone could please help me out! :lol: 

View.Set ("graphics,offscreenonly") 
var x, y, xChange, yChange : int := 1 
const RADIUS : int := 5 
Draw.Box (0, 0, maxx, maxy, black) 
x := maxx div 2 
y := maxy div 2 
loop 
Draw.Cls 
Draw.Box (0, 0, maxx, maxy, black) 
Draw.MapleLeaf (x, y, RADIUS, RADIUS, red) 
View.Update 
Time.Delay (5) 
x += xChange 
y += yChange 
if View.WhatDotColor (x, y + RADIUS) = black then 
yChange *= -1 
elsif View.WhatDotColor (x, y - RADIUS) = black then 
yChange *= -1 
end if 
if View.WhatDotColor (x + RADIUS, y) = black then 
xChange *= -1 
elsif View.WhatDotColor (x - RADIUS, y) = black then 
xChange *= -1 
end if 
end loop

-----------------------------------
Atherial
Thu Feb 18, 2016 2:42 pm

Re: Moving Canada flag project
-----------------------------------
I have found the one line that is messing up your program, I recommend you attempt to find it yourself first though! :)
if you want the answer, continue below; however I really do recommend you try it yourself, first. 


Firstly, I highly recommend you make your radius bigger, as a maple leaf with each side being 5, would be quite small, but that is besides the point.

So, your radius is a constant value of five, which is the size you want the maple leaf to be. 
When you are drawing it however, you are using "RADIUS" as both the X and Y values, Instead, add the radius to the x and y. 

So, heres my fixed code:

View.Set ("graphics,offscreenonly") 
var x, y, xChange, yChange : int := 1 
const RADIUS : int := 5 
Draw.Box (0, 0, maxx, maxy, black) 
x := maxx div 2 
y := maxy div 2 
loop 
Draw.Cls 
Draw.Box (0, 0, maxx, maxy, black) 
Draw.MapleLeaf (x, y,x + RADIUS,y + RADIUS, red) 
View.Update 
Time.Delay (5) 
x += xChange 
y += yChange 
if View.WhatDotColor (x, y + RADIUS) = black then 
yChange *= -1 
elsif View.WhatDotColor (x, y - RADIUS) = black then 
yChange *= -1 
end if 
if View.WhatDotColor (x + RADIUS, y) = black then 
xChange *= -1 
elsif View.WhatDotColor (x - RADIUS, y) = black then 
xChange *= -1 
end if 
end loop


I hope that is your desired outcome! :)
[/spoiler]

Hope I helped!
-Mac

-----------------------------------
Insectoid
Thu Feb 18, 2016 2:52 pm

RE:Moving Canada flag project
-----------------------------------
This is what happens when you copy code you don't understand. The code is from a bouncing BALL template. The code to draw a ball in Turing is Draw.Oval (x, y, radius, radius, color). The code to draw a maple leaf is Draw.MapleLeaf (x1, y1, x2, y2, color). Can you see where you might have gone wrong here?

-----------------------------------
Robotkubo
Fri Feb 19, 2016 8:21 am

RE:Moving Canada flag project
-----------------------------------
Yeah I see where I went wrong, thanks to both of you
