Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 need help with this program...
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
noradII




PostPosted: Thu Jun 01, 2006 3:50 pm   Post subject: need help with this program...

how am i suppose to make this program
code:

setscreen ("graphics")          %puts the screen into graphics mode
var x, y : int := 0             %the variable for the dot
var dx, dy : int := 1           %the variable for bouncing off the wall
loop                            %starts the loop
    if whatdotcolor (x, y) not= 0 then      %if the dot hits the wall
    end if                                 
    drawfilloval (x, y, 10, 10, yellow)        %draws a black ball
    delay (4)                              %how fast the ball moves
    drawfilloval (x, y, 10, 10, white)      %"erases" the ball when it moves
    x := x + dx
    y := y + dy
    if x = 0 or x = maxx then               %makes the ball bounce off the wall
        dx := -dx
    end if
    if y = 0 or y = maxy then               %makes the ball bounce off the wall
        dy := -dy
    end if
end loop                                    %ends the loop

into a program that that have a ball that starts at the top of the screen so that its centre moves to the position it would move to under gravity in each step of the animation.
code:

Y = ymax  - ( ½ )  *  a  *  t  ** 2
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Thu Jun 01, 2006 4:11 pm   Post subject: (No subject)

You could use the kinematic formulas, or you could actually simulate the gravity. Consider the following code:

code:

View.Set ("offscreenonly")

var y := 300.0
var vy := 0.0
const Gravity := -0.3

loop

    y += vy             % Same as y := y + vy
    vy += Gravity       % Same as vy := vy + Gravity
   
    if y < 5 then
        vy *= -1        % Same as vy := vy * -1
    end if

    cls
    Draw.FillOval (200, round (y), 5, 5, black)
    View.Update
    delay (10)

end loop
noradII




PostPosted: Thu Jun 01, 2006 4:17 pm   Post subject: (No subject)

o boy, where should i get a newer version of turing @_@, view.update dont work on my turing
Tony




PostPosted: Thu Jun 01, 2006 4:20 pm   Post subject: (No subject)

you need version 4 or above. You can usually get it from your school. If they don't have it, let them know it's time to upgrade.

Otherwise you can get your own copy from Holtsoft. Or just take the command out. View.Update just draws from the double buffer to remove flicker in animation, doesn't change the actual program.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
noradII




PostPosted: Thu Jun 01, 2006 4:25 pm   Post subject: (No subject)

cool, thx...gotta remember to bring a disk to school next day [evil laugh]
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: