CS1335
  • Introduction
  • Assignments
    • A1: Meta, Metta
    • A2: Functions, Emotions
    • A3: Repeat Patterns
    • A4 - Objects: Things and No Thing
    • Final Inspirations
    • A?: Grid Patterns
    • Inspiration
  • Getting Started
    • Processing
    • PDE - Code Editor
    • Learning Processing
  • Java Language
    • Java Syntax
      • Typed-Variables
      • Float - Integer Conversion Errors
      • Modulus
      • Functions
      • Object Reference Data Types
      • Arrays
        • Class Example Code
      • Switch-Case Statement
      • Ternary Operator
      • Class
  • Project 1
    • Random Variation
    • Noise
    • HSB Color Mode
      • HSB Color Wheel
        • Dynamic ColorWheel
        • HSB Color Palette Tool
    • PShape Objects
      • Example Code: PShape
        • Inspiration
    • Modeling Emotions
      • Emotions
        • Kandinsky Color - Emotion
    • PShape with Contour
    • Recursion
      • Recursion Call-Stack
      • Recursion Examples
        • Example Code 1
        • Example Code 2
    • Recursion - PShape
    • Recursive Patterns
    • Planning Structure: Functions:
      • Example Code - Feb 19
      • Final Code Structure
    • Project 1: Programmatic Variations in Color
      • LerpColor
      • Map Function
      • Map with LerpColor
      • noise( )
    • Transforms for Mirroring
    • Project 1-Steps
  • Grid Based Designs
    • Computational Design
    • Artist: Victor Vasarely
    • Grid Pattern Design
    • 1D - Array of PShapes for Grid Layout
      • Truchet Tiling
      • Example Code S2020
      • Example Code March 11
      • Example - March9
      • Example Code
    • PShapes in Grid Regions
    • Grid Region Logic
    • Pattern Preview - Transforms: Translate & Scale
  • Project 2
    • Project 2 - 2D Arrays for Gradient Logic
      • 2D Array Grid with Labels
    • Grid Patterns using 2D Array Indexes: i, j
      • Example Class Code
    • lerpColor( ) and map( ) Functions
    • Demo Lerp Colors
    • 2D Arrays with lerpColor
    • Create PShape 2D Array
    • Function: Populate2DArray( )
    • Function: DisplayShapeMatrix()
    • Transforms for Position, Rotation, Scale of ShapeMatrix Elements
    • Project 2 - Steps
    • Animation for ShapeMatrix
      • Animation w/Noise
  • Object Oriented Programming
    • Introduction to Objects
    • Button States
    • Buttons as Objects
      • Button Class
    • Create Object Instances
    • Button Types
    • Modeling Buttons: States and Events
    • OOP - Inheritance
    • OOP - Polymorphism
    • Child-Class: PImageButton
    • PShape - SVG Objects
    • Menu of Buttons
    • ButtonGroup - Final Version
    • Slider Controller
    • UML Class Diagram
  • Project 3
    • Project 3 - Logic, Steps
    • Project 3 - Class Definitions
      • Button
      • PImageButton
      • ButtonGroup
      • Pattern
        • PShapes - SVG, Vertex Shapes
        • Setting Colors For Patterns
        • Pattern - With Child-PShapes
      • Slider
      • Particles
  • Modeling
    • UML Class Diagram
  • Resources and References
    • Glossary
    • Resources
      • Acoustics
      • Learning Science
        • Emotional Intelligence
      • Creativity
      • Conceptual Art
      • Books
        • Art
      • Games, Rules
      • Complexity
    • Random Inspiration
      • Ulm School
      • Heart-Mind, Mind, Body
      • Statistical Uncertainty
Powered by GitBook
On this page
  • Transforms: Translate and Scale
  • Code to create mini pattern preview

Was this helpful?

  1. Grid Based Designs

Pattern Preview - Transforms: Translate & Scale

Transforms: Translate and Scale

If we want to get a preview of the color gradients in our designs, we can make a mini version below the canvas area where we are designing our grid pattern. We'll use Processing Transform Functions, to move the origin, then nested for-loops to draw each PShape in our 1D arrays.

We'll need to change the project canvas size: size(800,800), To create space for our mini-preview below the artwork area. Also, we'll need to change how we calculate the cellSize for our grid, since we're no longer using the full canvas width:

The steps to create the mini-pattern preview are the same as the logic for creating a normal grid: 2 nested for-loops to position designs across columns and down rows. The only difference here is that we're going to translate the origin to the x,y position as the first step, this way we can put the grid wherever we want. Second, we want to scale the grid smaller, so we'll pass in a scaleFactor parameter - this will scale the entire canvas smaller, if the scaleFactor is smaller than 1. We'll use pushMatrix() and popMatrix() to wrap this logic, this will prevent our transforms from impacting other code in our program.

NewCanvasSize = scaleFactor CanvasSize: If scaleFactor = .20, then 160 = .20 800; //mini canvas dimension is 160x160

Code to create mini pattern preview

   void setup(){
   size( 800,800);
   int artBoard = 600; //new variable for artwork size
   int rows = 6
   int cols = 6;
   int cellSize = artBoard/rows;

   shapes1 = new PShape[rows * cols ];  //initialize array
   populateShapeList1(shapes1, cellSize);
   //call function to draw mini-grid
   drawMiniGrid(shapes1, 50,650,cellSize, rows, cols, .20, "Shapes1");

   }

    void drawMiniGrid(PShape[] shapes, int xPos, int yPos, float size, int rows, int cols, float scaleFactor, String label){
  pushMatrix();  //take a snapshot of current transform matrix
      translate( xPos, yPos);
      pushMatrix(); //remember translate ( ) position
      int x =0;
      int y=0;
      int shapeIndex=0;
      scale( scaleFactor );
      for( int i=0; i<rows; i++){
        for( int j=0; j< cols; j++){
        shape( shapes[shapeIndex], x,y);
        x += size;
        shapeIndex++;
        }
        x=0;
        y+= size;
      }
      popMatrix(); //undo scale, keep transform
  fill(160,255,255);
  text(label, 0,-10);   
  popMatrix();  //restore transformation matrix 
}
PreviousGrid Region LogicNextProject 2 - 2D Arrays for Gradient Logic

Last updated 5 years ago

Was this helpful?