Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
help to draw a swing
Author Message
DAV1209

Posted: Tue Nov 04, 2003 4:35 pm   Post subject: 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.

Questions.doc
Description:
Download
Filename:  Questions.doc
Filesize:  48.5 KB
Downloaded:  174 Time(s)

Sponsor
Sponsor

Tony

Posted: Tue Nov 04, 2003 4:45 pm   Post subject: (No subject)

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

Though if accurasy is not required, you can just have some forloops The initial size of the loop depends on the distance swing is pulled back, and it diminishes with each swing because of friction.
Tony's programming blog. DWITE - a programming contest.
DAV1209

Posted: Wed Nov 05, 2003 7:22 pm   Post subject: (No subject)

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

Posted: Thu Nov 06, 2003 10:14 am   Post subject: (No subject)

they teach turing at york?! at York University?!
*spontaniously combusts*
Your prof is on crack.

But dont worry, we'll help you here

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

First of all.. the input. Hold space down to pull swing back.
 code: 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)

 code: %after input is taken var pull:int := 180 %is how many degrees it swings, from input above loop exit when pull<=0 %exit loop when swing stops for i:pull .. -pull+5 %loses 5 degrees per swing. Change +5 to +1 later Draw.FillOval(100+sind(i)*100,100+cosd(i)*100,5,5,red) %draws red circle for a swing. Circle hangs from 100,100 and rope length is 100 Draw.Line(100,100,sind(i)*100,cosd(i)*100,black) %draws line end for %now to go back for i:-pull+5 .. pull -10 Draw.FillOval(100+sind(i)*100,100+cosd(i)*100,5,5,red) Draw.Line(100,100,sind(i)*100,cosd(i)*100,black) end for pull := pull - 10 %we lost 10 degrees while swinging back and forth end loop

The code above might make the swing go upside down... and it probably will. To fix it, just change +cosd(i) and +sind(i) to -cosd(i) and -sind(i)

I'll check on accurasy of the code when I get home.
Tony's programming blog. DWITE - a programming contest.
Mazer

Posted: Thu Nov 06, 2003 2:12 pm   Post subject: (No subject)

i thought they taught fortran at york. that's what my friend is being taught, anyways.
DAV1209

Posted: Thu Nov 06, 2003 3:51 pm   Post subject: (No subject)

yeah they did teach turing in York university
my major is computer sience and turing course is the course for non programming experience student

and right on my first programming course i have this professor
what a pain in the ass
he didn't even know how to use windows
i don't know how did he be a professor in York university
but beside he's kinda easy with us
he even answer the question when we doing the test and give some extra mark for student
he always ask what did he teach and what he did not
anyway i'm gonna try the turing code you show me to see if it's work
thank you so much Tony

hey Tony i saw your name is Tony Dan
are you a vietnamese ?
Mazerm, in York they have so many courses for you to chouse and Turing is my first programming course
your friend might chose the different course that teach fortran
DAV1209

Posted: Thu Nov 06, 2003 3:53 pm   Post subject: (No subject)

by the way this the link for download turing i found on the forum

[url]http://schools.tdsb.on.ca/dmthomson/CS/Turing/401/SETUP.EXE [/url][/url]
DAV1209

Posted: Thu Nov 06, 2003 4:18 pm   Post subject: (No subject)

i try to run the program but there is some errors and i couldn't find the way to fix it
Sponsor
Sponsor

Dan

Posted: Thu Nov 06, 2003 6:03 pm   Post subject: (No subject)

"Tony Dan", lol

no Dan is not Tony's last name it is my 1st name

i am the admin that posts less but keeps it running (also the one who gets blamed for everything )
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
DAV1209

Posted: Thu Nov 06, 2003 7:27 pm   Post subject: (No subject)

lol i saw the name Dan and i thought it was Tony's name but ....
hey Dan, your name is short for Daniel or what?
coz Dan is vietnamese name too
just wondering if you are vietnamese or not

Tony
i checked through the program , there are some errors but i couldn't fix it
thoughtful

Posted: Thu Nov 06, 2003 8:01 pm   Post subject: (No subject)

LOL, man this is funny turing at York. My friend asked me to make a similar program for his sister who studies at York. I couldn't beleive him, i thought he was screwing around.
thoughtful

Posted: Thu Nov 06, 2003 8:03 pm   Post subject: (No subject)

And bythe way the program tony made doesnt work because he didn't round the values for the drawing. Maybe he thought that you were atleast that smart
Tony

Posted: Thu Nov 06, 2003 8:15 pm   Post subject: (No subject)

pff come on guys, give me a break. just 2.5 mistakes in the code. and I didn't even had the compiler to check it. Was writing it up right here.

1 - forgot to round (Java and C++ automatically typecast )
2 - first loop should be decreasing since it goes backwards... once again, Java/C++'s forloops pwn
2.5 - swing was upside down, but I mentioned that when I wrote up the code

here's the fixed one
 code: %after input is taken var pull:int := 45 %is how many degrees it swings, from input above loop exit when pull<=0 %exit loop when swing stops for decreasing i:pull .. -pull+5 %loses 5 degrees per swing. Change +5 to +1 later Draw.FillOval(100-round(sind(i)*100),100-round(cosd(i)*100),5,5,red) %draws red circle for a swing. Circle hangs from 100,100 and rope length is 100 Draw.Line(100,100,100-round(sind(i)*100),100-round(cosd(i)*100),black) %draws line delay(10) cls end for %now to go back for i:-pull+5 .. pull -10 Draw.FillOval(100-round(sind(i)*100),100-round(cosd(i)*100),5,5,red) %draws red circle for a swing. Circle hangs from 100,100 and rope length is 100 Draw.Line(100,100,100-round(sind(i)*100),100-round(cosd(i)*100),black) %draws line delay(10) cls end for pull := pull - 10 %we lost 10 degrees while swinging back and forth end loop

btw, DAV1209 - I come from Russian background if you care 8)
Tony's programming blog. DWITE - a programming contest.
Dan

Posted: Fri Nov 07, 2003 5:10 pm   Post subject: (No subject)

DAV1209 wrote:

hey Dan, your name is short for Daniel or what?
coz Dan is vietnamese name too
just wondering if you are vietnamese or not

Short for Daniel
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
DAV1209

Posted: Tue Nov 11, 2003 5:44 pm   Post subject: (No subject)

thanks you so much Tony but when i put the 2 codes together
the program still not working
 code: 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 %after input is taken var pull:int := 45 %is how many degrees it swings, from input above loop exit when pull<=0 %exit loop when swing stops for decreasing i:pull .. -pull+5 %loses 5 degrees per swing. Change +5 to +1 later Draw.FillOval(100-round(sind(i)*100),100-round(cosd(i)*100),5,5,red) %draws red circle for a swing. Circle hangs from 100,100 and rope length is 100 Draw.Line(100,100,100-round(sind(i)*100),100-round(cosd(i)*100),black) %draws line delay(10) cls end for %now to go back for i:-pull+5 .. pull -10 Draw.FillOval(100-round(sind(i)*100),100-round(cosd(i)*100),5,5,red) %draws red circle for a swing. Circle hangs from 100,100 and rope length is 100 Draw.Line(100,100,100-round(sind(i)*100),100-round(cosd(i)*100),black) %draws line delay(10) cls end for pull := pull - 10 %we lost 10 degrees while swinging back and forth end loop

i did try to take out this line
Quote:
var pull:int := 45 %is how many degrees it swings, from input above
because the first possition of the line and ball is in the middle when ever we hit the space bar button, the ball goes up a little bit and the ball will release and starting falling down.
and another problem is
in this statement
Quote:
put "swing is pulled back:" + pull
,
i try to change to + round(pull) but it's still cause an error
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 2  [ 24 Posts ]
Goto page 1, 2  Next
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: