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

Username:   Password: 
 RegisterRegister   
 Explain code please =)
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Nezura




PostPosted: Sat May 01, 2004 8:20 pm   Post subject: Explain code please =)

Could someone explain every line of this code? i get most of it but it'll be better if someone could go more indepth.

thanks

code:


function distance (x1, y1 : int) : int
    result abs (x1 - y1)
end distance

var x1, y1, x2, y2, mb : int := 320
y1 := 200
loop
    mousewhere (x2, y2, mb)
    if x2 > x1 then
        x1 += distance (x1, x2) div 10
    else
        x1 -= distance (x1, x2) div 10
    end if
    if y2 > y1 then
        y1 += distance (y1, y2) div 10
    else
        y1 -= distance (y1, y2) div 10
    end if

    Draw.FillOval (x1, y1, 20, 20, 9)
    delay (100)
    cls
    View.Update
   
end loop

Sponsor
Sponsor
Sponsor
sponsor
GreenTiger




PostPosted: Sat May 01, 2004 8:47 pm   Post subject: (No subject)

Okay the first three lines are a function that can be run at any time in the program. WHen you call distance, it will output the ABSOLUTE value of x1-y1, that is, making it positive even if it's a negative.

After the function, it calls the variables and starts them all off at 320, except for y1.
Then, we enter a never-ending loop

Inside this loop, it checks the mouse's position, and puts the x position in x2, the y in y2 and records if there's a mouse button press in mb.
Keep in mind y is the vertical position while x is horizontal.

Ok, then a bunch of if statements:
if those conditions are true, it adds/subtracts the result of the distance function.

IE: for the first one, the ABSOLUTE value of x1 - x2 divided by 10

After those if statements, it draws an oval centered at x1, y1, of a radius of 20 and colour 9 and delays, clears the screen and updates the view.

One of those last two is redundant.

From now on, highlight a term you don't understand and press F9 that should help you better than I can.
Nezura




PostPosted: Sun May 02, 2004 1:22 pm   Post subject: (No subject)

Thanks!!
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  [ 3 Posts ]
Jump to:   


Style:  
Search: