Subdomain Posts
Lisp | 3 days ago
None | 4 days ago
Lisp | 5 days ago
Lisp | 6 days ago
Lisp | 7 days ago
Lisp | 7 days ago
Lisp | 7 days ago
Lisp | 7 days ago
Lisp | 7 days ago
Lisp | 7 days ago
Recent Posts
C | 1 min ago
None | 2 min ago
None | 3 min ago
PHP | 5 min ago
None | 6 min ago
PHP | 6 min ago
None | 7 min ago
None | 7 min ago
XML | 8 min ago
None | 9 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By PhiLho on the 10th of Feb 2009 08:09:29 PM Download | Raw | Embed | Report
  1. /**
  2. Handles demo: draw handles than can be dragged with the mouse.
  3. http://processing.org/
  4.  
  5. by Philippe Lhoste <PhiLho(a)GMX.net> http://Phi.Lho.free.fr & http://PhiLho.deviantART.com
  6. */
  7. /* File/Project history:
  8.  1.00.000 -- 2008/04/29 (PL) -- Creation.
  9. */
  10. /* Copyright notice: For details, see the following file:
  11. http://Phi.Lho.free.fr/softwares/PhiLhoSoft/PhiLhoSoftLicence.txt
  12. This program is distributed under the zlib/libpng license.
  13. Copyright (c) 2008 Philippe Lhoste / PhiLhoSoft
  14. */
  15.  
  16. final int CANVAS_HEIGHT = 400;
  17. final int CANVAS_WIDTH = 400;
  18. final int HANDLE_NB = 10;
  19. Handle[] g_h = new Handle[HANDLE_NB];
  20. boolean g_bDragging;
  21.  
  22. void setup()
  23. {
  24.   smooth();
  25.   size(CANVAS_HEIGHT, CANVAS_WIDTH);
  26.  
  27.   // Create random handles
  28.   for (int i = 0; i < HANDLE_NB; i++)
  29.   {
  30.     int size = int(random(5, 20));
  31.     g_h[i] = new Handle(random(CANVAS_HEIGHT - 10), random(CANVAS_WIDTH - 10),
  32.         size, size / 5,
  33.         color(random(0, 128), 0, 0), color(0, random(200, 255), 0), color(0, 0, random(200, 255))
  34.     );
  35.   }
  36. }
  37.  
  38. void draw()
  39. {
  40.   background(#AADDFF);
  41.  
  42.   // We suppose we are not dragging by default
  43.   boolean bDragging = false;
  44.   // Check each handle
  45.   for (int i = 0; i < HANDLE_NB; i++)
  46.   {
  47.     // Check if the user tries to drag it
  48.     g_h[i].Update(g_bDragging);
  49.     // Ah, this one is indeed dragged!
  50.     if (g_h[i].IsDragged())
  51.     {
  52.       // We will remember a dragging is being done
  53.       bDragging = true;
  54.       // And move it to mouse position
  55.       g_h[i].Move();
  56.     }
  57.     // In all case, we redraw the handle
  58.     g_h[i].Draw();
  59.   }
  60.   // If no dragging is found, we reset the state
  61.   g_bDragging = bDragging;
  62. }
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: