xxxxxxxxxx
var stw; //strokeweight
var w_color;
var b_color; //color variables
var xpos;
var ypos; //x and y positions
var h;
var w; //height and width
var repx; //repeat for x-axis
var repy; //repeat for y axis
var sz;
function setup() {
createCanvas(600, 600);
background(250, 248, 245); //smoky white
stw = 2; //define strokeweight
w_color = '#FFFFFF'; //define colors with hex codes
b_color = '#ADD8E6';
repx = 30; //define repeat value for x
repy = 30; //define repeat value for y
sz = 40; //mazimum size
//disable loop
noLoop();
//background
push();
translate(0, 0);
for (var a = 0; a < 17; a = a + 1) {
for (var b = 0; b < 17; b = b + 1) {
push();
translate(repx * a, repy * b);
squares();
pop();
}
}
pop();
}
function draw() {
randomsquares(); //squares randomly drawn
}
function squares() {
strokeWeight(stw); //properties of blue squares
stroke(b_color);
noFill();
xpos = 50; //define variables to make shape
ypos = 50;
h = 20;
w = 20;
rect(xpos, ypos, w, h); //shape command that will be repeated
}
function randomsquares() {
strokeWeight(stw); //properties of red square
noFill();
h = 20; //defined height and width
w = 20;
push();
translate(150, 150);
x = random(0, 300);
y = random(0, 300);
//select RGB for colorsu want to be randomized
stroke(random(255, 255, 0), random(255, 0, 0), random(160, 32, 240));
//to draw square with random colors
rect(x, y, w, h);
pop();
}
function keyPressed() {
if (key == 'd') {
draw();
}
}