pattern 4

var x, y;

function setup() {
  createCanvas(1600, 600);
  noLoop();
}

function draw(){
  background(255);
  rectMode(CENTER);
  x = width/2;
  y = height/2;
  noFill();
  strokeWeight(2);

  for (var i = 0; i< 10; i++) {
      stroke(random(255), random(20, 225), random(255));
    rect(x + random(-4, 4), y + random(-4, 4), .8*width, .8*height);
  }
  for (var i = (.1*height); i < (.9*height); i += 2) {
    strokeWeight(1);
    stroke(random(255), random(255), random(255));
    line(.1*width+ random(-6, 6), i+random(-4, 4), .9*width + random(-6, 6), i+ random(-4, 4));
  }
}

function mousePressed(){
  redraw();
}
function setup() {
 createCanvas(800, 600);
   background("#ff00ff");
   smooth();
}
 
function draw_grid() {
  noFill();
  background("#ff00ff");
  var incr = 50;
  for (var x=5+ incr/2; x < width; x +=incr) {
    for (var y =5+ incr/2; y < height; y += incr) {
      if (random(20)>18) {
        strokeWeight(8);
        stroke(255);
      }
      else {
        strokeWeight(2);
        stroke("#ff0090");
      }
      ellipse(x, y, incr-10, incr-10);
    }
  }
}
 
function draw() {
}
 
function mousePressed() {
  draw_grid();
  //save("image.png");
}
var incr_x, incr_y, x, y, r;
var countLine = 0; // how many lines in a (vertical) row?
var countCross = 0; // how many crosses in a (vertical) row?
var margin = 5;
var counter = -1;
var isX = [];
var val;
var steps_x, steps_y; // number of rows and columns
var max = 4; // max number of symbols in a row, vertically!
 
function setup() {
  createCanvas(500, 500);
  stroke(0);
  strokeWeight(12);
  strokeCap(SQUARE);
 
  steps_x = 10; //number of columns
  steps_y = 12; //number of lines
 
  incr_x = width/float(steps_x);
  incr_y = height/float(steps_y);
 
  drawPattern();
}
 
function draw() {
}
 
function drawPattern() {
  background(255);
  for (x = 0; x < width; x += incr_x) {
    for (y = (incr_y)/2; y < height; y += incr_y) {
      counter += 1;
      r = random(1);
      if (counter>2*steps_y-1) {
        if (isX[counter-2*steps_y]+isX[counter-steps_y]== 2) {
          val = 0;
        }
        else if (isX[counter-2*steps_y]+isX[counter-steps_y]== 0) {
          val = 1;
        }
        else {
          if (r >0.6) {
            val = 1;
          }
          else {
            val = 0;
          }
        }
      }
      else {
        if (r >0.5) {
          val = 1;
        }
        else {
          val = 0;
        }
      }
      if (countLine == max) {
        val = 1;
      }
      if (countCross == max) {
        val = 0;
      }
      isX = append(isX, val);
      if (isX[counter] == 1) {
        isCross();
      }
      else {
        isLine();
      }
    }
  }
}
 
 
function mouseClicked() {
  drawPattern();
}
 
function isCross() {
  line(x+10, y+(incr_y)/2-margin, x+(incr_x) - margin, y-(incr_y)/2 +margin);
  line(x+10, y-(incr_y)/2+margin, x+(incr_x) - margin, y+ (incr_y)/2 -margin);
  countCross += 1;
  countLine =0;
}
 
function isLine() {
  line(x +margin, y, x + (incr_x)-margin, y);
  countCross = 0;
  countLine +=1;
}