cgr­e­4­6­9­9­_­S­t­a­t­i­c Var­i­a­t­i­o­n­s

by Chris Green
  • Show Code
  @peep sketch
  @author cgre4699
  @since April 2016
  This piece of code is designed to create a unique design each time
  it is run. I have decided to focus on creating T-Shirt prints with
  the theme of balance and harmony. The prints are designed to cover
  the entire item of clothing to give it a colourful acid wash look.
  My inspiration for this design was perlin noise. I wanted to
  experiment with it as I find its ability to create natural and
  complex shapes procedurally very interesting. Its use in 3d terrain 
  creates some amazing landscapes.
  To make the design more engaging I added a smooth implementation of
  colour to the script. By using a random min rbg value to reduce
  darker colours and by adding a random variable that will use one
  of three colour themes each time I had the design changing enough.
  Looking at my code it does seem I made it unnecessarily complex by 
  making use of an array. Although a far simpler approch can be taken
  and was origionally taken, I used the array as I decided that if a
  design was created that you wanted to keep, it would be simple to
  tweak the sketch so that it could export the arrays values and 
  re import them at a later date. 
  Origionally I had difficulty running this sketch in processing 3.0.2
  and no trouble in the processing.js implementation in peepproject, 
  however by replacing point with set to draw this sketch it became
  far faster and more reliable.
//set a random offset for the noise
float xOff = random(-1000,1000);
float yOff = random(-1000,1000); 
//random noise multiplyer for extra variation
float noiseMult = random(0.02,0.05); 
//Used in a test that defines the colours the sketch uses
float colRand = random(1,12); 
//define the lower value that rgb colours should be mapped to
float minR = random(0,200);
float minB = random(0,200);
float minG = random(0,200); 
void setup(){
  Setting up the document with black background, 
  no smoothing, and 400x300 size which can be set
  to anything, then calling the backDrop function.
void backDrop(){
  //This variable will determine the slot in the array that each colour recieves
  int iteration = 0;  
  //Here I create an array to hold colour data
  color[] colours = new color[width*height]; 
  //Loop through all x,y coords on canvas
  for(int x = 0; x < width; x++){ 
    for(int y = 0; y < height; y++){ 
      //Setting up the perlin noise with a random multiplyer for variety each execution
      float n = noise((xOff+x)*noiseMult,(yOff+y)*noiseMult); 
      //Mapping the alpha to range 0-255
      float alpha = map(n,0.0,1.0,0,255); 
      //Here I use the screens dimensions to create a smooth colour change
      float r = map(x,0,width,minR,255); 
      float g = map(y,0,height,minG,255);
      float b = map((x+y)/2,0,(width+height)/2,minB,255); 
      //This section defines a 33% chance of each colour scheme
      if(colRand <= 4){
        colours[iteration] = color(r,g,b,alpha);
      else if(colRand >= 4 && colRand <= 8){
        colours[iteration] = color(r,b,g,alpha);
      else if(colRand >= 8){
        colours[iteration] = color(b,r,g,alpha);
      //adds to the increment variable
  //Finally I call on the Generate function where the image is drawn. Sends the colours table as a parameter
void Generate(color[] colours){
  //Like before uses an iteration var to determine the slot on the table
  int iteration = 0; 
  for(int x = 0; x < width; x++){ 
    for(int y = 0; y < height; y++){
      //Sets the stroke colour that was calculated beforehand and stored in the table
      //Makes a point to display this colour
      //Using set instead of point is more lightweight