 Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki Blog Search Turing Chat Room Members
Math.Distance Example        Author Message
Delta  Posted: Sun Apr 18, 2004 10:59 pm   Post subject: Math.Distance Example

Well I'm not sure why I'm posting this but my friend told me to make it hence... I did.. so ya... its probably not too efficient but I tried so here test it if you like.

 code: View.Set ("title:Ron's Grid Thingy,graphics:610;560,nocursor,noecho,offscreenonly") % Set resolution, title and modes of the run window type balls :     record         x : int % [y] coordinate         y : int % [x] coordinate         size : int % Size of the ball         dist : real % Distance from the mouse         clr : int % The colour of the ball     end record var ball : array 1 .. 60, 1 .. 55 of balls % Build a two demensional array for a grid of balls var mX, mY, mB : int % Holds mouse [x,y] coordinates and button status var oldX, oldY : int := 0 % Holds the old mouse [x,y] coordinates var invert : boolean := false % Invert colours true or false var down : boolean := false % Stores whether the mouse button is down or not % Draw the balls for decreasing i : 55 .. 1     for j : 1 .. 60         ball (j, i).x := 10 * j % Store [x] coordinate         ball (j, i).y := 10 * i % Store [y] coordinate         ball (j, i).size := 1 % Set default ball size         Draw.FillOval (ball (j, i).x, ball (j, i).y, 2, 2, 2) % Draw the ball     end for end for loop     Mouse.Where (mX, mY, mB)     if oldX not= mX and oldY not= mY then % If the mouse has been moved then         Draw.Cls % Clear the screen         if invert = true then % If invert is activated             Draw.FillBox (0, 0, maxx, maxy, 0) % Draw White Background         else             Draw.FillBox (0, 0, maxx, maxy, 7) % Draw Black Background         end if         for decreasing i : 55 .. 1             for j : 1 .. 60                 %Draw.FillOval (ball (j, i).x, ball (j, i).y, ball (j, i).size, ball (j, i).size, 7) % Erase the old ball                 % Check the distance of the ball from the mouse and set the size of the ball depending on its distance from the mouse                 if Math.Distance (ball (j, i).x, ball (j, i).y, mX, mY) > 80 then                     ball (j, i).size := 1 % Change Size of ball                     if invert = true then % If invert is activated                         ball (j, i).clr := 30                     else                         ball (j, i).clr := 19 % Change colour of ball                     end if                 elsif Math.Distance (ball (j, i).x, ball (j, i).y, mX, mY) < 80 and Math.Distance (ball (j, i).x, ball (j, i).y, mX, mY) > 60 then                     ball (j, i).size := 2 % Change Size of ball                     if invert = true then % If invert is activated                         ball (j, i).clr := 28 % Change colour of ball                     else                         ball (j, i).clr := 22 % Change colour of ball                     end if                 elsif Math.Distance (ball (j, i).x, ball (j, i).y, mX, mY) < 60 and Math.Distance (ball (j, i).x, ball (j, i).y, mX, mY) > 40 then                     ball (j, i).size := 3 % Change Size of ball                     ball (j, i).clr := 25 % Change colour of ball                 elsif Math.Distance (ball (j, i).x, ball (j, i).y, mX, mY) < 40 and Math.Distance (ball (j, i).x, ball (j, i).y, mX, mY) > 20 then                     ball (j, i).size := 4 % Change Size of ball                     if invert = true then  % If invert is activated                         ball (j, i).clr := 22 % Change colour of ball                     else                         ball (j, i).clr := 28 % Change colour of ball                     end if                 elsif Math.Distance (ball (j, i).x, ball (j, i).y, mX, mY) < 20 and Math.Distance (ball (j, i).x, ball (j, i).y, mX, mY) > 0 then                     ball (j, i).size := 5 % Change Size of ball                     if invert = true then % If invert is activated                         ball (j, i).clr := 19 % Change colour of ball                     else                         ball (j, i).clr := 30 % Change colour of ball                     end if                 end if                 Draw.FillOval (ball (j, i).x, ball (j, i).y, ball (j, i).size, ball (j, i).size, ball (j, i).clr) % Draw the new ball             end for         end for         View.Update % Update all the balls     end if     if mB = 1 and down = false then % If mouse is pressed and down = false(prevents constant switching)         if invert = false then % If colours aren't inverted then invert them             invert := true % Enable inversion of colours         else % If colours are inverted then restore to original colours             invert := false % Disable inversion of colours         end if         down := true % Set down to true     elsif mB = 0 and down = true then % If mouse is pressed and down = true(prevents constant switching)         down := false % Reset down to false     end if     oldX := mX % Store mouse's [x] coordinate     oldY := mY % Store mouse's [y] coordinate end loop    Delos  Posted: Mon Apr 19, 2004 11:57 am   Post subject: (No subject)

Nice...reminds me of Catalysts' old prog w/ the glowing green text...and the other one with the spotlight on image... Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First         Page 1 of 1  [ 2 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: