Hello (I’m back with level 3 again, I’m really, really sorry). I’ve read the other discussions on this topic, but I haven’t found a way to change the perception of my problem.
The exercise appears to be completed, but I’m not satisfied because the ball doesn’t bounce randomly in all directions… It maintains a sort of similar trajectory.
I’m not really having any difficulty changing the color. However, I don’t really understand how to use the new “random” function.
Below is my code. I think I need to add to my if statements that, as soon as the ball touches an edge, it’s the X AND Y positions that change, and not one or the other. But I can’t figure out how to code this to achieve this result. If I widen the “min” and “max” (which I tried), the ball appears and disappears in various places but doesn’t really bounce…
Could you please point me in the right direction?
// TODO: Create your variables
set x_and_y_position to 5 //starting value's position
set x to 3 //before increasement
set y to 4 //before increasement
set radius to 10
set hue to 99 //before increasement because starting value is 100
set saturation to 80
set luminosity to 50
//animation
set speed_x to 2 //the one that will change again and again
set speed_y to 1//the one that will change again and again
set speed_right to 2 //the variable to change the move_x
set speed_down to 1 //the variable to change the move_y
set speed_left to -2 //the variable to change the move_x
set speed_up to -1 //the variable to change the move_y
set hue_increasement to 1
//bouncing
set min_x_left to -10
set max_x_left to 10
set min_x_right to 110
set max_x_right to 90
set min_y_up to -10
set max_y_up to 10
set min_y_down to 110
set max_y_down to 90
// TODO: Update variables
repeat 900 times do
//changing hue
change hue to hue + hue_increasement
if hue == 355 do
change hue_increasement to -1
else if hue == 100 do
change hue_increasement to 1
end
// changing X position
change x to x + speed_x
if x >= 100 do
change speed_x to speed_left
change x to random_number(min_x_right, max_x_right)
else if x <= 0 do
change speed_x to speed_right
change x to random_number(min_x_left, max_x_left)
end
// changing y position
change y to y + speed_y
if y >= 100 do
change speed_y to speed_up
change y to random_number(min_y_down, max_y_down)
else if y <= 0 do
change speed_y to speed_down
change y to random_number(min_y_up, max_y_up)
end
// TODO: Update variables
// Draw the circle
fill_color_hsl(hue, saturation, luminosity)
circle(x, y, radius)
end