Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Initial variables setup
- public int
- canvasSize = 720, // Set the square canvas size.
- rectLength = 432, // length of rects. This will be the length and width of the square.
- rectAmount = 10; // Set rect density of square.
- void settings() {
- size(canvasSize, canvasSize); // Set canvas dimensions in setup so that canvasSize can be used as a variable.
- }
- void setup(){
- noStroke(); // Do not use stokes by default.
- noSmooth(); // Romove antialiased effect, not needed on square geometry.
- fill(0); // Set rect fill to black.
- }
- void draw()
- {
- //**** EXTRAS **** --------------------------------------------------------------------------
- // Rect amount is relative to mouse Y.
- // rectAmount = (mouseY > 4)? mouseY/2 : rectAmount;
- // Rect length is relative to mouse X.
- // rectLength = mouseX;
- // Canvas size is relative to Rect length.
- // surface.setSize(rectLength+200, rectLength+200); canvasSize = width;
- // Add background color each frame to clear trash.
- background(255);
- // Calculate height of rect by Y position of mouse and amount of rects.
- int rectHeight = (mouseY > 4)? mouseY / (canvasSize / (rectLength/rectAmount + 1)) +1 : 1;
- // Run a loop to create and position the rect elements.
- for (int i = 0; i < rectAmount; i++)
- {
- // Create a rect
- rect(
- // Calculate and set X position.
- (canvasSize - rectLength) / 2,
- // Calculage and set Y position.
- rectLength * i / (rectAmount-1) - rectHeight * i / (rectAmount-1)+(canvasSize - rectLength) / 2,
- // Set Rect length
- rectLength,
- // Set Rect Height
- rectHeight
- );
- };
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement