
-----------------------------------
DAV1209
Tue Nov 04, 2003 4:35 pm

help to draw a swing
-----------------------------------
i have this assignment and i don't know how to do
any help plz........

Question 1. Draw a Swing

Use Turing's pixel graphics mode to draw a swing and simulate its behaviour. The sample images on the next few pages should be self-explanatory.

Your program should set the size of the screen and all parameters for the graphics should  be proportional so that the program will work regardless of screen dimensions.

Your program should draw the swing at rest and tell the user what to do. Each time the user presses a key the swing should move a small distance away from the rest position. Then, when the user presses the SPACEBAR the swing will be released and swing back and forth. You will need to control the speed of the swing so that the swinging is visible to the user.

The swing should travel a shorter distance each time it changes direction so that it will stop back at the rest position. You will further need to control the speed to make the swing slow down as its arc gets shorter. It is not necessary that you model the actual motion of a swing, though you can if you feel up to it. 
	
To "freeze" the swing during its motion click the Pause button in the Run Window. This will allow you print it at different positions. The Print button will send the contents of the Run window directly to the printer - without the Title Bar and Menu Bar.

-----------------------------------
Tony
Tue Nov 04, 2003 4:45 pm


-----------------------------------
sounds simple enough..

gravity is constant = -9.81 m/s^2
the velocity is in direction of a tangent of the swing's path.

Some physics and some calculus and you'll be modeling simulations in no time :lol:

Though if accurasy is not required, you can just have some forloops :roll: The initial size of the loop depends on the distance swing is pulled back, and it diminishes with each swing because of friction.

-----------------------------------
DAV1209
Wed Nov 05, 2003 7:22 pm


-----------------------------------
it might sound easy for you but not for me 
i just start my first year in CS in York and i have no experience at programming 
and in my turing couse, my professor is just doing some funny things in class
he didn't show us or help us on the assignment and also i'm a international student so i have some difficulties with this assignment and i dont' know anyone to ask for help.
can you show me more careful to write this program
the file i attach with is the example of how the output is 
thanks

-----------------------------------
Tony
Thu Nov 06, 2003 10:14 am


-----------------------------------
they teach turing at york?! at York University?! :shock:
*spontaniously combusts*
Your prof is on crack.

But dont worry, we'll help you here :D

First of all... you have to keep in mind that this assignment is an animation, not an actual stimulation, so we don't need exact numbers. We can assume and create perfect conditions to make it easier for us :lol:

First of all.. the input. Hold space down to pull swing back.

var pull:int:=0
put "hold down space to pull back"
loop
if hasch then %if input buffer has length
     loop
     pull+=1 %adds one to pull
     locate(1,1)
     put "swing is pulled back:" + pull
     exit when not hasch %exit when buffer is empty
     end loop
end if
exit when pull>0 %swing was pulled back, exit loop
end loop


I dont have turing installed on my school computer, can't say how acurate that code is, but that's the idea. Using Input.KeyDown(read tutorial) will probably be more efficient and accurate though, since if your keyboard's repeat rate is too slow or too fast, you might run into issues.

Now for the swing itself... We just go in a forloop, back and forth, gradually losing the number of degrees. We calculate the position of the swing using Trig (Cos/Sin)


%after input is taken
var pull:int := 180 %is how many degrees it swings, from input above
loop
exit when pull0 %swing was pulled back, exit loop 
end loop 
%after input is taken 
var pull:int := 45 %is how many degrees it swings, from input above 
loop 
exit when pull