xxxxxxxxxx
//Code by Aaron Reuland
//for the #wccChallenge on the theme of 'Chalchiuhtlicue (or Mesoamerican design)'.
//The tiled design was inspired by squared spiral designs from some Aztec Temples.
//Tried implementing a wave function collapse alogrithm to try and match the tiles
//but eventually settled a much simpler approach (see 'orientGrid' function)
//Then since Chalchiuhtlicue is a water diety, I gave it some water theme.
let waterColors=["#2d2a19","#596760","#a2b6ab","#668487","#d9e6db","#f8fce9"]
let colors=['#EEF5DB',"#546d85",'#290300']
let simplex
let layoutGrid=[]
let div=12
let gs, md
function setup() {
md= min(windowWidth, windowHeight)
createCanvas(md, md);
gs= md/div
blendMode(MULTIPLY)
simplex= new openSimplexNoise(Date.now())
for(let y=0; y<height-1; y+=gs){
for(let x=0; x<width-1; x+=gs){
var start={
pos: createVector(x, y),
orientation: null,
}
layoutGrid.push(start)
}
}
orientGrid(layoutGrid)
}
function draw(){
clear()
for(let l of layoutGrid){
if(l.orientation){
block(l.pos.x, l.pos.y, gs, l.orientation)
}
}
//waves
wcI=1
let siner=md/6
push()
blendMode(MULTIPLY)
for(let i=0; i<TAU; i+=TAU/5){
let filler= color(waterColors[wcI])
filler.setAlpha(125)
fill(filler)
beginShape()
vertex(-10, md+10)
for(let x=-10; x<md+10; x+=10){
vertex(x, md-md/4 + sin(noise(x/siner-frameCount/30,frameCount/30, i*2))*md/4)
}
vertex(md+10, md+10)
endShape(CLOSE)
wcI++
}
pop()
push()
blendMode(BLEND)
//image(frame, 0, 0)
pop()
}
function block(x, y, s, orient){
noStroke()
let c1= colorMixer(createVector(x, y), waterColors)
let c2= colorMixer(createVector(x+gs, y+gs), waterColors)
push()
coloring = drawingContext.createLinearGradient(x/2, y, x/+gs, y+gs)
coloring.addColorStop(0, c1)
coloring.addColorStop(1, c2)
drawingContext.fillStyle = coloring
rect(x, y, s)
pop()
let c3= colorMixer(createVector(x+gs/10, y+gs/10), waterColors)
let c4= colorMixer(createVector(x+gs+gs/10, y+gs+gs/10), waterColors)
c3.setAlpha(20)
c4.setAlpha(20)
push()
coloring = drawingContext.createLinearGradient(x/2, y, x/+gs, y+gs)
coloring.addColorStop(0, c3)
coloring.addColorStop(1, c4)
drawingContext.fillStyle = coloring
rect(x, y, s)
pop()
push()
fill(colors[1])
let rot= orient*PI/2
push()
translate(x+s/2, y+s/2)
rotate(rot)
translate(-s/2, -s/2)
for(let xer=0; xer<=s; xer+=s/6.5){
rect(xer, 0, s/13, xer+s/28)
rect(0, xer, xer+s/13, s/13)
}
pop()
pop()
}
function orientGrid(array){
for(let i=0; i<array.length; i++){
if(!array[i].orientation){
if(i==0){
array[i].orientation=floor(random(1, 5))
}
let options=[]
array[i].orientation= floor(random(1, 5))
if(array[i].orientation==1 || array[i].orientation==2){
if(checkRight(i)){
options.push(3);
options.push(4);
array[i+1].orientation= random(options)
}
}
if(array[i].orientation==3){
if(checkDown(i)){
options.push(1);
options.push(4);
array[i+div].orientation= random(options)
}
}
}
}
}
function checkRight(i){
if(i%div==(div-1)){
return false
} else{
return true
}
}
function checkDown(i){
if(i+div> (div*div)-1){
return false
} else{
return true
}
}
function colorMixer(pos, colorArray) {
let c= map(simplex.noise2D(pos.x/(md*3)+random(0.001, 0.002), pos.y/(md*3)-frameCount/300 ), -1, 1, 0, colorArray.length)
let c1 = floor(c)
let c2 = floor(c+1)%colorArray.length
let color1 = colorArray[c1]
let color2 = colorArray[c2]
let mix = fract(c)
let coloring = color(spectral.mix(color1, color2, mix))
return coloring
}