Computer Science Canada bouncing a ball... PLEASE HELP 
Author:  coolgirl97 [ Wed May 29, 2013 5:47 pm ] 
Post subject:  bouncing a ball... PLEASE HELP 
I need to make a ball bounce within a box... i got the box done and the bouncing boundaries for the x and y.... NOW I NEED TO ADD A Z.. so the ball can bounce front and back as well.. PLEASE HELP ME!! This is what i have so far.... drawline (510,360,510,40, black) drawline (510,360,190,360,black) drawline (190,360,190,40, black) drawline (190,40,510,40, black) drawline (450,300,450,100, black) drawline (450,300,250,300,black) drawline (250,300,250,100, black) drawline (250,100,450,100, black) drawline (190,360,250,300, black) drawline (450,300,510,360,black) drawline (190,40,250,100, black) drawline (510,40,450,100, black) %Ball bouncing const RADIUS := 15 const DELTA_TIME := 0.10 const TIME_DELAY := 10 const x_right_boundary := 480 const x_left_boundary := 220 const y_top_boundary := 330 const y_bottom_boundary := 70 var x, y, x0, y0, v0x, v0y, t : real x0 := 100 y0 := 100 v0x := 30 v0y := 10 t := 0 loop x := x0 + v0x * t y := y0 + v0y * t drawfilloval (round (x), round (y), round (RADIUS), round (RADIUS),black) delay (TIME_DELAY) drawfilloval (round (x), round (y), round (RADIUS), round (RADIUS), white) if x > x_right_boundary then x0 := 2 * x_right_boundary  x y0 := y v0x := v0x t := 0 end if if x < x_left_boundary then x0 := 2 * x_left_boundary  x v0x := v0x y0 := y t := 0 end if if y > y_top_boundary then y0 := 2 * y_top_boundary  y v0y := v0y x0 := x t := 0 end if if y < y_bottom_boundary then y0 := 2 * y_bottom_boundary  y v0y := v0y x0 := x t := 0 end if t := t + DELTA_TIME cls drawline (510,360,510,40, black) drawline (510,360,190,360,black) drawline (190,360,190,40, black) drawline (190,40,510,40, black) drawline (450,300,450,100, black) drawline (450,300,250,300,black) drawline (250,300,250,100, black) drawline (250,100,450,100, black) drawline (190,360,250,300, black) drawline (450,300,510,360,black) drawline (190,40,250,100, black) drawline (510,40,450,100, black) end loop 
Author:  Nathan4102 [ Wed May 29, 2013 5:55 pm ] 
Post subject:  RE:bouncing a ball... PLEASE HELP 
Your z coord would reflect how close the ball is to the user. When the z is bigger(or smaller), the ball would get bigger. So you could change the radius by some amount based on the z coord. 
Author:  coolgirl97 [ Wed May 29, 2013 5:59 pm ] 
Post subject:  Re: bouncing a ball... PLEASE HELP 
Thanks, but the thing is i'm really new to comp sci.. (have no idea y i took the course), and my teacher does not know how to teach :S so... how exactly do i add the z coord??? Thank you so much!! 
Author:  Nathan4102 [ Wed May 29, 2013 6:02 pm ] 
Post subject:  RE:bouncing a ball... PLEASE HELP 
Well "z" would be another variable, just like x and y, and you'd increase it the same way you increase your other variables. Then when you draw the ball, just have the radius relative in some way to z, instead of the constant RADIUS. E: You'd have to remember to make the ball "bounce" in the z plane as well, just like your x and y's. 
Author:  coolgirl97 [ Wed May 29, 2013 6:18 pm ] 
Post subject:  Re: bouncing a ball... PLEASE HELP 
so would i do something like this??.. (sorry for all the questions btw)... drawline (510,360,510,40, black) drawline (510,360,190,360,black) drawline (190,360,190,40, black) drawline (190,40,510,40, black) drawline (450,300,450,100, black) drawline (450,300,250,300,black) drawline (250,300,250,100, black) drawline (250,100,450,100, black) drawline (190,360,250,300, black) drawline (450,300,510,360,black) drawline (190,40,250,100, black) drawline (510,40,450,100, black) %Ball bouncing const RADIUS := 15 const DELTA_TIME := 0.10 const TIME_DELAY := 10 const x_right_boundary := 480 const x_left_boundary := 220 const y_top_boundary := 330 const y_bottom_boundary := 70 [color=red]const z_front_boundary := const z_back_boundary :=[/color] var x, y, [color=red]z[/color] , x0, y0[color=red], z0,[/color] v0x, v0y,[color=red] v0z[/color] ,t : real x0 := 100 y0 := 100 [color=red]z0 := [/color] v0x := 30 v0y := 10 [color=red]v0z :=[/color] t := 0 loop x := x0 + v0x * t y := y0 + v0y * t [color=red]z:= z0 + v0z * t[/color] drawfilloval (round (x), round (y), round (RADIUS), round (RADIUS),black) delay (TIME_DELAY) drawfilloval (round (x), round (y), round (RADIUS), round (RADIUS), white) [color=red]drawfilloval (round(z), round (x), round (RADIUS), round (RADIUS), black) delay (TIME_DELAY) drawfilloval (round(z), round (x), round (RADIUS), round (RADIUS), white) delay (TIME_DELAY) drawfilloval (round(z), round (y), round (RADIUS), round (RADIUS), black) delay (TIME_DELAY) drawfilloval (round (z), round (y), round (RADIUS), round (RADIUS), white) [/color] if x > x_right_boundary then x0 := 2 * x_right_boundary  x y0 := y v0x := v0x t := 0 end if if x < x_left_boundary then x0 := 2 * x_left_boundary  x v0x := v0x y0 := y t := 0 end if if y > y_top_boundary then y0 := 2 * y_top_boundary  y v0y := v0y x0 := x t := 0 end if if y < y_bottom_boundary then y0 := 2 * y_bottom_boundary  y v0y := v0y x0 := x t := 0 end if [color=red]if z > z_front_boundary then z0 := 2 * z_front _boundary  z v0z := v0z x0 := x t := 0 end if if z < z_back_boundary then z0 := 2 * z_back_boundary  z v0z := v0z x0 := x t := 0 end if[/color] t := t + DELTA_TIME cls drawline (510,360,510,40, black) drawline (510,360,190,360,black) drawline (190,360,190,40, black) drawline (190,40,510,40, black) drawline (450,300,450,100, black) drawline (450,300,250,300,black) drawline (250,300,250,100, black) drawline (250,100,450,100, black) drawline (190,360,250,300, black) drawline (450,300,510,360,black) drawline (190,40,250,100, black) drawline (510,40,450,100, black) end loop 
Author:  coolgirl97 [ Wed May 29, 2013 6:19 pm ] 
Post subject:  Re: bouncing a ball... PLEASE HELP 
ignore.. the colour red thing... i did it to show what i added.. but it is html coding, so you won't see the difference right away , anyways... Thanks! 
Author:  Nathan4102 [ Wed May 29, 2013 6:26 pm ] 
Post subject:  RE:bouncing a ball... PLEASE HELP 
No problem, and that should work, except you need to draw your circle based on your z coord aswell. 
Author:  onedirectionlover [ Wed May 29, 2013 6:31 pm ] 
Post subject:  Re: bouncing a ball... PLEASE HELP 
i did... didn't i ?? drawfilloval (round (x), round (y), round (RADIUS), round (RADIUS), black) delay (TIME_DELAY) drawfilloval (round (x), round (y), round (RADIUS), round (RADIUS), white) drawfilloval (round(z), round (x), round (RADIUS), round (RADIUS), black) delay (TIME_DELAY) drawfilloval (round(z), round (x), round (RADIUS), round (RADIUS), white) drawfilloval (round(z), round (y), round (RADIUS), round (RADIUS), black) delay (TIME_DELAY) drawfilloval (round (z), round (y), round (RADIUS), round (RADIUS), white) 
Author:  Nathan4102 [ Wed May 29, 2013 6:39 pm ] 
Post subject:  RE:bouncing a ball... PLEASE HELP 
Youre only changing the x and y parameters of "drawfilloval". round(x) and round(y) should stay as the x and y parameters. The thing you need to change is the x and y radius(3'rd and 4'th parameter). Assuming we're looking at this ball straight down the z plane, as z increases, the ball would appear bigger, correct? Thus, as z increases, we need to draw the ball larger. 
Author:  coolgirl97 [ Thu May 30, 2013 8:01 am ] 
Post subject:  Re: bouncing a ball... PLEASE HELP 
Okay... i kinda get what u r saying.. thank you! but.. just one more question... so instead of this: if z > z_front_boundary then z0 := 2 * z_front _boundary  z v0z := v0z x0 := x t := 0 end if if z < z_back_boundary then z0 := 2 * z_back_boundary  z v0z := v0z x0 := x t := 0 end if will it be something like this?? : if z > z_front_boundary then RADIUS := 20 v0z := v0z x0 := x t := 0 end if if z < z_back_boundary then RADIUS := 10 v0z := v0z x0 := x t := 0 end if THANK U SO MUCH !! <3 
Author:  jr5000pwp [ Thu May 30, 2013 8:21 am ]  
Post subject:  Re: bouncing a ball... PLEASE HELP  
I wouldn't do it like that personally. I would take more of an approach of

Author:  coolgirl97 [ Thu May 30, 2013 8:34 am ] 
Post subject:  Re: bouncing a ball... PLEASE HELP 
so... would depth_scale be a const??? and will i need to use it anywhere else other than drawfilloval? ty! 
Author:  coolgirl97 [ Thu May 30, 2013 8:38 am ] 
Post subject:  Re: bouncing a ball... PLEASE HELP 
okay, so this is what i have so far.. its prob all messed up, but can u tell me what i have to do to make it work?? Thank you so much. drawline (510,360,510,40, black) drawline (510,360,190,360,black) drawline (190,360,190,40, black) drawline (190,40,510,40, black) drawline (450,300,450,100, black) drawline (450,300,250,300,black) drawline (250,300,250,100, black) drawline (250,100,450,100, black) drawline (190,360,250,300, black) drawline (450,300,510,360,black) drawline (190,40,250,100, black) drawline (510,40,450,100, black) %Ball bouncing const RADIUS := 15 const DELTA_TIME := 0.10 const TIME_DELAY := 10 const x_right_boundary := 480 const x_left_boundary := 220 const y_top_boundary := 330 const y_bottom_boundary := 70 const z_front_boundary := const z_back_boundary := var x, y, z , x0, y0, z0, v0x, v0y, v0z ,t : real x0 := 100 y0 := 100 z0 := 100 v0x := 30 v0y := 10 v0z := 20 t := 0 loop x := x0 + v0x * t y := y0 + v0y * t z := z0 + v0z * t drawfilloval (round (x), round (y), round (RADIUS+z*DEPTH_SCALE), round (RADIUS+z*DEPTH_SCALE), black) delay (TIME_DELAY) drawfilloval (round (x), round (y), round (RADIUS+z*DEPTH_SCALE), round (RADIUS+z*DEPTH_SCALE), white) if x > x_right_boundary then x0 := 2 * x_right_boundary  x y0 := y v0x := v0x t := 0 end if if x < x_left_boundary then x0 := 2 * x_left_boundary  x v0x := v0x y0 := y t := 0 end if if y > y_top_boundary then y0 := 2 * y_top_boundary  y v0y := v0y x0 := x t := 0 end if if y < y_bottom_boundary then y0 := 2 * y_bottom_boundary  y v0y := v0y x0 := x t := 0 end if t := t + DELTA_TIME cls drawline (510,360,510,40, black) drawline (510,360,190,360,black) drawline (190,360,190,40, black) drawline (190,40,510,40, black) drawline (450,300,450,100, black) drawline (450,300,250,300,black) drawline (250,300,250,100, black) drawline (250,100,450,100, black) drawline (190,360,250,300, black) drawline (450,300,510,360,black) drawline (190,40,250,100, black) drawline (510,40,450,100, black) end loop 
Author:  jr5000pwp [ Thu May 30, 2013 9:02 am ] 
Post subject:  RE:bouncing a ball... PLEASE HELP 
Firstly, your z boundaries aren't set. Secondly, you'd want to declare a DEPTH_SCALE constant. This should probably be a real and you'll just need to play with it until it feels right. Thirdly, you aren't doing checking for your z coordinate. You can probably just copy the x or y code you have and substitute z in, making sure to use the appropriate variables such as z_front_boundary. 
Author:  coolgirl97 [ Thu May 30, 2013 12:54 pm ] 
Post subject:  Re: bouncing a ball... PLEASE HELP 
Thank you so much!! I've kinda fixed up everything u told me... is this correct?? : drawline (510,360,510,40, black) drawline (510,360,190,360,black) drawline (190,360,190,40, black) drawline (190,40,510,40, black) drawline (450,300,450,100, black) drawline (450,300,250,300,black) drawline (250,300,250,100, black) drawline (250,100,450,100, black) drawline (190,360,250,300, black) drawline (450,300,510,360,black) drawline (190,40,250,100, black) drawline (510,40,450,100, black) %Ball bouncing const RADIUS := 15 const DELTA_TIME := 0.10 const TIME_DELAY := 10 const x_right_boundary := 480 const x_left_boundary := 220 const y_top_boundary := 330 const y_bottom_boundary := 70 const z_front_boundary := 200 const z_back_boundary := 100 var x, y, z , x0, y0, z0, v0x, v0y, v0z ,t, DEPTH_SCALE : real DEPTH_SCALE := 18 x0 := 100 y0 := 100 z0 := 100 v0x := 30 v0y := 10 v0z := 20 t := 0 loop x := x0 + v0x * t y := y0 + v0y * t z := z0 + v0z * t drawfilloval (round (x), round (y), round (RADIUS+z*DEPTH_SCALE), round (RADIUS+z*DEPTH_SCALE), black) delay (TIME_DELAY) drawfilloval (round (x), round (y), round (RADIUS+z*DEPTH_SCALE), round (RADIUS+z*DEPTH_SCALE), white) if x > x_right_boundary then x0 := 2 * x_right_boundary  x y0 := y v0x := v0x t := 0 end if if x < x_left_boundary then x0 := 2 * x_left_boundary  x v0x := v0x y0 := y t := 0 end if if y > y_top_boundary then y0 := 2 * y_top_boundary  y v0y := v0y x0 := x t := 0 end if if y < y_bottom_boundary then y0 := 2 * y_bottom_boundary  y v0y := v0y x0 := x t := 0 end if if z > z_front_boundary then z0 := 2 * z_front _boundary  z v0z := v0z x0 := x t := 0 end if if z < z_back_boundary then z0 := 2 * z_back_boundary  z v0z := v0z x0 := x t := 0 end if t := t + DELTA_TIME cls drawline (510,360,510,40, black) drawline (510,360,190,360,black) drawline (190,360,190,40, black) drawline (190,40,510,40, black) drawline (450,300,450,100, black) drawline (450,300,250,300,black) drawline (250,300,250,100, black) drawline (250,100,450,100, black) drawline (190,360,250,300, black) drawline (450,300,510,360,black) drawline (190,40,250,100, black) drawline (510,40,450,100, black) end loop 
Author:  Nathan4102 [ Thu May 30, 2013 1:00 pm ] 
Post subject:  RE:bouncing a ball... PLEASE HELP 
A good way to see if it's correct is to run it, and see if it does what you want it to do. 
Author:  coolgirl97 [ Thu May 30, 2013 1:07 pm ] 
Post subject:  Re: bouncing a ball... PLEASE HELP 
yea.. good idea!, but the thing is that i only have macs at home.. so i don't have the turing program.... i tried searching for turing programs for macs, but i wasn't able to find one... the only chance i have to run it is during class, and that is if my teacher lets us use the computers.. 
Author:  Insectoid [ Thu May 30, 2013 1:38 pm ] 
Post subject:  RE:bouncing a ball... PLEASE HELP 
Here is a mac port of Turing. You'll have to make an account on that site to download it though. 
Author:  coolgirl97 [ Thu May 30, 2013 4:19 pm ] 
Post subject:  Re: bouncing a ball... PLEASE HELP 
thank you, i'll try it out 
: 