Advertisement
Guest User

Untitled

a guest
Aug 28th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. //Initial variables setup
  2. public int
  3. canvasSize = 720, // Set the square canvas size.
  4. rectLength = 432, // length of rects. This will be the length and width of the square.
  5. rectAmount = 10; // Set rect density of square.
  6.  
  7. void settings() {
  8. size(canvasSize, canvasSize); // Set canvas dimensions in setup so that canvasSize can be used as a variable.
  9. }
  10.  
  11. void setup(){
  12. noStroke(); // Do not use stokes by default.
  13. noSmooth(); // Romove antialiased effect, not needed on square geometry.
  14. fill(0); // Set rect fill to black.
  15. }
  16.  
  17. void draw()
  18. {
  19.  
  20. //**** EXTRAS **** --------------------------------------------------------------------------
  21. // Rect amount is relative to mouse Y.
  22. // rectAmount = (mouseY > 4)? mouseY/2 : rectAmount;
  23. // Rect length is relative to mouse X.
  24. // rectLength = mouseX;
  25. // Canvas size is relative to Rect length.
  26. // surface.setSize(rectLength+200, rectLength+200); canvasSize = width;
  27.  
  28. // Add background color each frame to clear trash.
  29. background(255);
  30. // Calculate height of rect by Y position of mouse and amount of rects.
  31. int rectHeight = (mouseY > 4)? mouseY / (canvasSize / (rectLength/rectAmount + 1)) +1 : 1;
  32. // Run a loop to create and position the rect elements.
  33. for (int i = 0; i < rectAmount; i++)
  34. {
  35. // Create a rect
  36. rect(
  37. // Calculate and set X position.
  38. (canvasSize - rectLength) / 2,
  39. // Calculage and set Y position.
  40. rectLength * i / (rectAmount-1) - rectHeight * i / (rectAmount-1)+(canvasSize - rectLength) / 2,
  41. // Set Rect length
  42. rectLength,
  43. // Set Rect Height
  44. rectHeight
  45. );
  46. };
  47. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement