Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Moving Canada flag project
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Robotkubo




PostPosted: Thu Feb 18, 2016 9:34 am   Post subject: 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! Laughing

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
Sponsor
Sponsor
Sponsor
sponsor
Atherial




PostPosted: Thu Feb 18, 2016 2:42 pm   Post subject: 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! Smile
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:
Turing:

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! Smile
[/spoiler]

Hope I helped!
-Mac
Insectoid




PostPosted: Thu Feb 18, 2016 2:52 pm   Post subject: 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




PostPosted: Fri Feb 19, 2016 8:21 am   Post subject: RE:Moving Canada flag project

Yeah I see where I went wrong, thanks to both of you
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: