Explain code please =)
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







Sponsor Sponsor



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 x1y1, 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 neverending 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!!







