Follow the Bouncing Ball

Ask questions about projects relating to: computer science or pure mathematics (such as probability, statistics, geometry, etc...).

Moderators: kgudger, bfinio, Moderators

Locked
leafsnacks
Posts: 1
Joined: Wed Dec 02, 2015 12:58 am
Occupation: Student

Follow the Bouncing Ball

Post by leafsnacks »

What section of code is the step size? I can't find it anywhere.. and I've tried messing with what I know and I am just modifying the speed of the ball but I don't know how to make the step size smaller without decreasing the speed.
HowardE
Posts: 496
Joined: Thu Nov 20, 2014 1:35 pm
Occupation: Science Buddies content developer
Project Question: N/A
Project Due Date: N/A
Project Status: Not applicable

Re: Follow the Bouncing Ball

Post by HowardE »

Speed is a function of distance over time. In the example code the ball moves 10 every time you call the function and the function is called every 200 milliseconds. I'm assuming that by step size you mean how far the ball moves each time you call it, and that's the 10.

If you want it to move less distance each time without changing the speed, you have to increase the rate you call the function. So if you have one speed with loc=+10 at 200 miliiseconds, then you could make it move half as far each time but call it twice as often with loc+=5 and calling it every 100 milliseconds (change the 10 and 200 to 5 and 100). At some point though, you might call the function faster than your computer can execute it. Changing from 200 to 100 milliseconds should be visible but faster rates (just a few milliseconds) may be effectively ignored. Experiment and see what you find out.

Howard
Locked

Return to “Grades 9-12: Math and Computer Science”