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
  • Diagonal Color Gradients
  • Define variable k to determine color pattern.
  • Color Gradient Logic:
  • Odd-Even Gradient Logic
  • Random Patterning Logic
  • Logic for Randomized 2-pattern arrangement:
  • Other Patterns based on i, j index
  • Min( i, j)
  • Max( i, j);

Was this helpful?

  1. Project 2

Grid Patterns using 2D Array Indexes: i, j

Previous2D Array Grid with LabelsNextExample Class Code

Last updated 5 years ago

Was this helpful?

Diagonal Color Gradients

Define variable k to determine color pattern.

In the image above, we see a diagonal color gradient in both the foreground and background colors. The logic associated with this can be seen in the image below. If we define a new variable: int k = i + j; , where k is the sum of the i, j index variables, we see that the value of k increases along the grid's diagonal direction. Then we can use k as a factor to determine the fill color.

Color Gradient Logic:

Using the sum of grid indexes for color logic gives us a simple approach to create complex patterns. We can observe a pattern that forms when we consider i,j indexes of each cell: if we add i + j indexes for a cell, then neighboring cells along diagonal lines have equal values of i + j. We can use this relationship to determine fill values for cells, so we can create a gradient fill diagonally across a grid of cells.

      int k= i + j; //i,j are for-loop indexes
      fill( 150 + (k * 10) );  //gradient logic

Odd-Even Gradient Logic

We can also use this sum variable: k for determining odd-even logic. When we use the modulus operator %, we focus on the remainder component, so when k%2 has no remainder ( k%2 == 0 ), we have a way to implement odd-even logic in our patterns. In the image below, we've combined it with the gradient color fill logic. If we have an odd item, then we use a light gray fill(240), otherwise, we use our gradient logic to create our fill.

int k= i + j; //i,j are for-loop indexes
if(k % 2 == 0){
fill( 100 + k *10); //gradient logic
}
else{
fill(240); //light gray
}

Random Patterning Logic

In the images below, we can see that there are 2 different design units, shape1 has 2 colored vertically-stacked triangles on a dark background, shape 2 is a rotation - so the colored triangles have left/right orientation. By randomly selecting between these units, we have an additional design pattern.

Logic for Randomized 2-pattern arrangement:

We can use the Processing random(min,max ) function to simulate random events. We define and initialize a random variable: rand that will be assigned a decimal value between 0.0 and 2.0. We determine that if rand > 1, then we vertexPattern1( ), like a coin flip, roughly half the time we'll have rand < 1 and instead we'll vertexPattern2( ).

Other Patterns based on i, j index

Min( i, j)

The logic for the image above uses the fact that along square shaped sections, like the outer top-row and the left-column both share the feature that the minimum value of the i,j index for each element is 0.

k = min( i, j);

Max( i, j);

//Code snippet for random logic to determine which shape is created.
float rand= random(0,2);
if(rand > 1){
vertexPattern1(size, foreground, background);
}
else{
vertexPattern2(size, foreground, background);
}

Shape1 ... Shape2

The logic for the image above uses the fact that along square shaped sections, like the outer bottom-row and the right-column both share the feature that the max value of the i,j index for each element is 5. The can use a factor like k to determine color for each grid cell.

The image below uses logic: color factor k = min( i, j). In addition, there are color gradients on both the foreground and background colors. The primary block unit has been repeated 4 times across adjacent regions, where scale( scaleX, scaleY) has been used to create of the basic unit

mirror-images
lerpColor( ) function