mouse press turns off replication, window resize changes dimensions
xxxxxxxxxx
/*
by Metamere
1-17-2023
Genuary day 17: A grid inside a grid inside a grid
*/
let wt_scale = 60
var AR, AR2
function setup() {
img = createCanvas(W=windowWidth, H=windowHeight);
w = W/2
h = H/2
AR = min(max(W/H, 0.667), 1.5)
AR2 = 1/AR
background(0);
wt = min(W,H)/wt_scale
}
const col_list = [65,240,[200,0,0]]
const col2_list = [0,90,[100,50,50]]
let spacing = 500
let t = 0
function grid_line(){
let orientation, dim1, dim2
if(Math.random() < 0.5){
orientation = 'V'
dim1 = width
dim2 = height
}
else{ orientation = 'H'
dim1 = height
dim2 = width
}
let index = int(Math.random()*3)
stroke(col_list[index])
let N = 0.1
let offset = N*(index+1) //*N/3
let location = int((randomGaussian(0.15,0.08))/N)*N + offset
let loc = map(location, 0, 1.1 + offset, 0, dim1)
if(orientation == 'V'){
push()
strokeWeight(AR*wt)
line(loc, 0, loc, height)
stroke(col2_list[index])
strokeWeight(AR*wt*0.5)
loc -= AR*wt*0.75
line(loc, 0, loc, height)
pop()
}
else{
push()
strokeWeight(AR2*wt)
line(0, loc, width, loc)
stroke(col2_list[index])
strokeWeight(AR2*wt*0.5)
loc += AR2*wt*0.75
line(0, loc, width, loc)
pop()
}
}
var trans_x = 0
var trans_y = 0
function draw() {
t += 0.0006
trans_x = lerp(trans_x, -1-round(pow(sin(t*0.5),2),0), 0.01)
trans_y = lerp(trans_y, -round(cos(t),0), 0.02)
translate(trans_x,trans_y)
if(frameCount%8==0){
grid_line()
}
if(!mouseIsPressed){
image(img, 0, 0);
image(img, w, 0, w, h);
image(img, 0, h, w, h);
image(img, w, h, w, h);
}
}
function mouseReleased(){
background(0)
}
function windowResized(){
setup()
}