Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Author Message
Nezura

Posted: 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

GreenTiger

Posted: 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

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

Thanks!!
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 3 Posts ]
 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: