You can modify parameters in the beginning of code to generate more variations.
A fork of trottoir _ica by yokoul
xxxxxxxxxx
//noprotect
let cubeSize, cubeColor, margin, numLayers, backgroundLightness, img;
let layerCount = [];
let layers = [];
let cubeCoords = [];
let xp = null;
let yp = null;
// éléments d'e
let imgCubeSize = 200;
let imgRadius = 50;
let imgAngle = 0;
let structImg = false;
let imgCopyBG = false;
// grille de cubes
let patchs = 18;
let hardLayer = 0;
let noiseScale = 1.75;
let noiseAmp = 3.75;
// paramètres fBm
let octaves = 4;
let persistence = 0.338;
let lacunarity = 0.03;
// dimensions du canevas
let aspW = 1;
let aspH = 0.7;
let ratio = aspW / aspH;
let border = 3;
// paramètres d'un cube
let roundIt = false;
let squareIt = true;
let nos = false;
let nosColor = true;
let nosh = true;
let showCoord = false;
// modèles de placements
let structCairo = false;
let structSizeMod = false;
let structFlatMod = false;
let structPlato = true;
let strucStar = false;
let strucKar = false;
let strucKarYmod = false;
// couleurs
let colorSchemA = false;
let colorSchemB = false;
let colorSchemC = true;
// ajouts visuels
let showLines = true;
let showCircles = true;
let showLCdensity = 0.75;
// variances d'affichage
let radiusVariance = 30;
let shake = false;
let vague = false;
let bigSeisme = false;
let sizeMod = 1;
let randMod = false;
let randModLight = true;
let traceCubeLines = true;
// background et grains
let gS = 33;
let bgP = false;
let bgPmax = false;
let bgClouds = false;
let bgCloudDot = false;
let bgCloudRed = false;
let bgDark = true;
let bgGrad = false;
let bgGaxis = "X";
let bgTriB = 5;
let bgTriH = 30;
// palettes
let l1Col = chroma.scale([
"#ffffff99", "#f3f2f299", "#e7e6e699", "#dbd9d999",
"#cfcdcd99", "#c3c1c199", "#b7b5b599", "#abaaaa99",
"#9f9e9e99", "#94939399", "#88878799", "#7d7c7c99",
"#71717199", "#67676799", "#5c5c5c99", "#52525299",
"#48484866", "#3e3e3e66", "#34343466", "#2b2b2b66",
"#22222266", "#19191966", "#0f0f0f33", "#00000033"
]).domain([0, patchs]);
let l2Col = chroma.scale([
"#fec5bbd2", "#fcd5ce90", "#fae1dd60", "#f8edebd1",
"#e8e8e4d1", "#D8E2DCE5", "#ece4db94", "#ffe5d999",
"#ffd7ba79", "#fec89a98"
]).domain([0, patchs]);
let l3Col = chroma.scale([
"#0e7c7bff", "#17bebbff", "#d4f4dd98", "#d62246ff",
"#4B1D3FC9"
]).domain([0, patchs]);
let l4Col = chroma.scale([
"#00121999", "#005F7396", "#0a939690", "#94d2bd96",
"#e9d8a696", "#ee9b0090", "#ca670298", "#bb3e0390",
"#ae201297", "#9b222698"
]).domain([0, patchs]);
let l5Col = chroma.scale([
"#edede9df", "#d6ccc2ff", "#f5ebe096", "#e3d5ca90",
"#d5bdaf99"
]).domain([0, patchs]);
let l6Col = chroma.scale([
"#dad7cd9f", "#a3b18a9d", "#588157d1", "#3a5a4099",
"#344e4199"
]).domain([0, patchs]);
let l7Col = chroma.scale([
"#00429d99", "#174aa199", "#2552a599", "#2f5aa899",
"#3962ac99", "#416bb099", "#4973b399", "#517cb799",
"#5884ba99", "#608dbe99", "#6895c199", "#6f9ec599",
"#77a7c899", "#7fb0cb99", "#87b8ce99", "#90c1d199",
"#99cad499", "#a2d3d799", "#acdbda99", "#b7e4dc99",
"#c4ecde99", "#d2f4e099", "#e4fbe199", "#ffffe099"
]).domain([0, patchs]);
let l8Col = chroma.scale([
"#995D81EF", "#EB8258EA", "#F6F740ED", "#D8DC6AEF",
"#6689A1F4"
]).domain([0, patchs]);
let l9Col = chroma.scale([
"#05299EEF", "#5E4AE3F4", "#947BD3F2", "#F0A7A0F7", "#F26CA7F2"
]).domain([0, patchs]);
let l10Col = chroma.scale([
"#F15025F4", "#FFFFFFF9", "#E6E8E6F2", "#CED0CEF7", "#191919F9"
]).domain([0, patchs]);
let l11Col = chroma.scale([
"#493B2AF9", "#593F62F4", "#7B6D8DEF", "#8499B1F7", "#A5C4D4F4"
]).domain([0, patchs]);
let l12Col = chroma.scale([
"#C3DFE0F2", "#BCD979ED", "#9DAD6FE0", "#7D6D61EA", "#5E574DF7"
]).domain([0, patchs]);
let l13Col = chroma.scale([
"#BFC3BAF7", "#A9ACA9F7", "#60495AF7", "#3F3244F4", "#2F2235F4"
]).domain([0, patchs]);
let l14Col = chroma.scale([
"#03071eff","#370617ff","#6a040fff","#9d0208ff",
"#d00000ff","#dc2f02ff","#e85d04ff","#f48c06ff",
"#faa307f4","#ffba08f4"
]).domain([0, patchs]);
let l15Col = chroma.scale([
"#9c89b8f9","#f0a6caf7","#efc3e6ff","#f0e6eff4","#b8beddf4"
]).domain([0, patchs]);
let l16Col = chroma.scale([
"#582f0e","#7f4f24","#936639","#a68a64","#b6ad90","#c2c5aa","#a4ac86","#656d4a","#414833","#333d29"
]).domain([0, patchs]);
let l17Col = chroma.scale([
"#ff99c8f4","#fcf6bdd9","#d0f4def7","#a9def9f5","#e4c1f9f5"
]).domain([0, patchs]);
let l100Col = chroma.scale([
"#FFFFFFF7", "#000000EF"
]).domain([0, patchs]);
let colorArray = [l1Col, l2Col, l3Col, l4Col, l5Col,
l6Col, l7Col, l8Col, l9Col, l10Col,
l11Col, l12Col, l13Col, l14Col, l15Col,
l16Col, l17Col];
function setup() {
//clear();
//randomSeed(1235678);
//noiseSeed(78911234);
wisW = 1000*aspW;
wisH = 1000*aspH;
//wisW = windowWidth * aspW;
//wisH = windowHeight * aspH;
createCanvas(wisW, wisH);
img = createGraphics(wisW,wisH);
p5grain.setup();
pixelDensity(2);
cubeSize = min(wisW, wisH) / (patchs + 1); // * (ratio/sizeMod);
margin = cubeSize * 2;
let rIndex = floor(random(1, 18));
let rIndex1 = floor(random(1, 18));
let rIndex2 = floor(random(1, 18));
let rIndex3 = floor(random(1, 18));
let rIndex4 = floor(random(1, 18));
let rIndex5 = floor(random(1, 18));
let rIndex6 = floor(random(1, 18));
let rIndex7 = floor(random(1, 18));
let rIndex8 = floor(random(1, 18));
let rCol = colorArray[rIndex - 1];
let rCol1 = colorArray[rIndex1 - 1];
let rCol2 = colorArray[rIndex2 - 1];
let rCol3 = colorArray[rIndex3 - 1];
let rCol4 = colorArray[rIndex4 - 1];
let rCol5 = colorArray[rIndex5 - 1];
let rCol6 = colorArray[rIndex6 - 1];
let rCol7 = colorArray[rIndex6 - 1];
let rCol8 = colorArray[rIndex6 - 1];
// Initialize layers
for (let i = 0; i < patchs; i++) {
layers[i] = [];
for (let j = 0; j < patchs; j++) {
layers[i][j] = [];
for (let k = 0; k < patchs; k++) {
let z = k * noiseScale;
let numLayers = hardLayer + floor(noise(i * noiseScale, j * noiseScale, z) * noiseAmp);
let color;
if (colorSchemA == true) {
if (i < patchs / 1 && j < patchs / 5) {
color = rCol(floor(random(0, patchs))).hex();
} else if (i < patchs / 2 && j < patchs / 3) {
color = rCol1(floor(random(0, patchs))).hex();
} else if (i < patchs / 2 && j < patchs / 1.9) {
color = rCol2(floor(random(0, patchs))).hex();
} else if (i < patchs / 1 && j < patchs / 1.4) {
color = rCol3(floor(random(0, patchs))).hex();
} else if (i < patchs / 1.5 && j < patchs / 1.2) {
color = rCol4(floor(random(0, patchs))).hex();
} else if (i < patchs / 0.3 && j < patchs / 1.7) {
color = rCol5(floor(random(0, patchs))).hex();
} else {
color = rCol6(floor(random(0, patchs))).hex();;
}
} else if (colorSchemB == true) {
color = rCol(floor(random(0, patchs))).hex();;
} else if (colorSchemC == true) {
if (i < patchs && j < patchs) {
color = rCol1(floor(random(-patchs, patchs))).hex();
} else if (i < patchs / 2 && j < patchs / 2){
color = rCol2(floor(random(-patchs, patchs))).hex();;
}
} else {
color = l100Col(floor(random(-patchs, patchs))).hex();;
}
layers[i][j] = {
numLayers: numLayers,
color: color
};
}
}
}
// Initialize cubeCoords
for (let i = 0; i < patchs; i++) {
cubeCoords[i] = [];
for (let j = 0; j < patchs; j++) {
cubeCoords[i][j] = {
x: 0,
y: 0
};
}
}
if (bgP == true) {
push();
background(220);
granulateSimple(gS);
noStroke();
fill(l3Col(floor(random(0, patchs))).hex());
translate(0, wisH / 1.75);
for (let y = bgTriH; y < wisH; y += bgTriH) {
for (let x = 0; x < wisW; x += bgTriB) {
triangle(x, y, x + bgTriB / random(2, 5), y - bgTriH, x + bgTriB, y + bgTriH);
//bgTriH *= 1.0005;
}
bgTriB *= 1.2;
}
pop();
} else if (bgPmax == true) {
push();
background(220);
granulateSimple(gS);
noStroke();
fill(l3Col(floor(random(0, patchs))).hex());
translate(0, wisH / 1.75);
for (let y = bgTriH; y < wisH; y += bgTriH) {
for (let x = 0; x < wisW; x += bgTriB) {
//triangle(x, y, x + bgTriB / random(2,5), y - bgTriH, x + bgTriB, y + bgTriH+(x/2));
triangle(x, y, x + bgTriB / random(2,5), y - bgTriH, x + bgTriB, y + bgTriH);
//square(x, y-wisH, bgTriB / random(14,20));
circle(x, y, bgTriH - x / y * 2);
push();
stroke(random(0.15, 1));
if (random(1, 20) <= 3) {
draw3DCube(x, y - bgTriH, y % random(bgTriH * 0.1, bgTriH * 3), rCol(floor(random(-patchs, patchs))).hex());
}
if (random(1, 20) >= 16) {
draw3DCube(x * 2, y - random(bgTriH * 5, bgTriH * 15), y % random(bgTriH * 0.1, bgTriH * 3), rCol(floor(random(-patchs, patchs))).hex());
}
pop();
bgTriH *= 1.0005;
}
bgTriB *= 1.2;
}
pop();
} else if (bgDark == true) {
push();
background(l14Col(floor(random(-patchs, patchs))).hex());
granulateSimple(gS);
pop();
} else if (bgClouds == true) {
push();
let yPosOffset = 0;
for (let xPos = -wisW * 1.05; xPos < wisW * 1.05; xPos += 3) {
let xPosOffset = 0;
for (let yPos = 0; yPos < wisH; yPos += 5) {
let cloudAngle = noise(xPosOffset, yPosOffset) * TAU * 2 - cos(xPos / yPos) * 1;
let vectorDirection = p5.Vector.fromAngle(cloudAngle);
let noiseValue = noise(xPosOffset, yPosOffset) * random(50, 255);
push();
translate(xPos + cos(yPos / 20) * 20, yPos);
rotate(vectorDirection.heading());
let circleSize = random(3, 35);
noFill();
strokeWeight(random(0.5, 3));
stroke(rCol3(floor(random(0, patchs))).hex());
stroke(noiseValue * 3.5, noiseValue * 5, noiseValue / 5 + yPos / 2.5, 8);
ellipse(0, 0, circleSize, circleSize);
pop();
xPosOffset += 0.1;
}
yPosOffset += 0.01;
}
pop();
} else if (bgGrad == true) {
push();
let color1 = color(rCol3(floor(random(0, patchs))).hex());
let color2 = color(rCol4(floor(random(0, patchs))).hex());
setGradient(0, 0, wisW, wisH, color1, color2, bgGaxis);
granulateSimple(gS);
pop();
} else if (bgCloudDot == true) {
let yPosOffset = 0;
for (let xPos = -25; xPos < wisW+25; xPos += 5) {
let xPosOffset = 0;
for (let yPos = 0; yPos < wisH; yPos += 15) {
let cloudAngle = noise(xPosOffset, yPosOffset) * TAU * 2 - cos(xPos / yPos);
let vectorDirection = p5.Vector.fromAngle(cloudAngle);
let noiseValue = noise(xPosOffset, yPosOffset) * random(50, 255);
push();
//colorMode(HSB);
translate(xPos + cos(yPos / 5) * 50, yPos);
rotate(vectorDirection.heading()*2);
let circleSize = random(5, 35);
if (circleSize <= 10) {
//fill(210,random(1,20),random(98,16), 10);
fill(rCol4(floor(random(0, patchs))).hex());
} else {
noFill();
}
strokeWeight(random(0.2, 1.5));
stroke(210,random(1,20),random(98,16), 20);
arc(0, 0, circleSize*random(0.1,1), circleSize*random(0.3,0.9), 30, random(QUARTER_PI,PI));
rotate(xPos + cos(yPos));
arc(0, circleSize, circleSize*random(0.1,1), circleSize*random(0.3,0.9), 30, random(QUARTER_PI,PI));
pop();
xPosOffset += 0.05;
}
yPosOffset += 0.005;
}
} else if (bgCloudRed == true) {
let yPosOffset = 0;
for (let xPos = -50; xPos < width+50; xPos += 3) {
let xPosOffset = 0;
for (let yPos = 0; yPos < height; yPos += 5) {
let cloudAngle = noise(xPosOffset, yPosOffset) * TAU * 2 - cos(xPos / yPos) * 6;
let vectorDirection = p5.Vector.fromAngle(cloudAngle);
let noiseValue = noise(xPosOffset, yPosOffset) * random(50, 450);
push();
translate(xPos + cos(yPos / 20) * 20, yPos);
rotate(vectorDirection.heading());
let circleSize = random(5, 25);
//fill(rCol6(floor(random(0, patchs))).hex());
fill(noiseValue * 2, noiseValue / 10 - yPos / 40, 5);
noStroke();
ellipse(0, 0, circleSize, circleSize);
noFill();
strokeWeight(random(1, 3));
//stroke(rCol5(floor(random(0, patchs))).hex());
stroke(noiseValue * 2, noiseValue / 10 - yPos / 40, 15);
ellipse(0, 0, circleSize, circleSize);
pop();
xPosOffset += 0.1;
}
yPosOffset += 0.01;
}
}
if (structImg == true) {
let xoff = 0;
let yoff = 0;
for (let i = 0; i < patchs; i++) {
let xoff = 0;
for (let j = 0; j < patchs; j++) {
let numLayers = layers[i][j].numLayers;
let color = layers[i][j].color;
let zoff = 0;
for (let k = 0; k < numLayers; k++) {
let x, y;
x = i * i / j * cubeSize + cubeSize * (0.5 * ratio * random(0.5, 1.5));
y = j + j * (cubeSize + cubeSize * 0.5) * random(0.5, 1.5);
let z = map(fBm(xoff, yoff, zoff), 0, 1, 0, patchs);
cubeCoords[i][j].x = x;
cubeCoords[i][j].y = y - numLayers * cubeSize / 5 - z + (margin);
for (let k = 0; k < numLayers; k++) {
let yOffset = k * cubeSize / 2;
drawCubeImg(x, y - yOffset - z + margin, cubeSize, color);
zoff += 0.1;
}
xoff += 0.1;
}
yoff += 0.1;
}
}
}
}
function draw() {
imgElips();
//blendMode(OVERLAY);
let xoff = 0;
let yoff = 0;
for (let i = 0; i < patchs; i++) {
let xoff = 0;
for (let j = 0; j < patchs; j++) {
let numLayers = layers[i][j].numLayers;
let color = layers[i][j].color;
let zoff = 0;
for (let k = 0; k < numLayers; k++) {
let x, y;
if (structPlato == true) {
x = i * i / j * cubeSize + cubeSize * (0.5 * ratio * random(0.5, 1.5));
y = j + j * (cubeSize + cubeSize * 0.5) * random(0.5, 1.5);
} else if (strucStar == true) {
let centerX = (patchs * cubeSize / 2) + border * 2;
let centerY = (patchs * cubeSize / 1.85) + border * 2;
let angle = TWO_PI * (i / patchs);
let radius = (patchs + radiusVariance / 2.1) * cubeSize * (j / patchs);
x = centerX + radius * cos(angle);
y = centerY + radius * sin(angle);
} else if (strucKar == true) {
x = i * cubeSize + wisW / 1.9 - (cubeSize * patchs) / 2;
y = j * cubeSize + wisH / 2 - (cubeSize * patchs) / 2;
} else if (strucKarYmod == true) {
x = i * cubeSize + wisW / 1.9 - (cubeSize * patchs) / 2;
y = j * cubeSize + wisH / 1.8 - (cubeSize * patchs) / 2;
} else if (structCairo == true) {
x = (i + j) * cubeSize + (10.5 + ((noiseScale + noiseAmp + patchs) / 10));
y = (i - j) * cubeSize / 2 + wisH / 2.5;
} else if (structSizeMod == true) {
x = (i - j) * cubeSize / 2 + wisW / 2;
y = (i + j) * cubeSize / 4 + wisH / (4 - ((noiseScale + noiseAmp + patchs) % sizeMod));
} else if (structFlatMod == true) {
x = (i - j) * (cubeSize * sizeMod) / (2 * aspW) + wisW / (2 * aspW);
y = (i + j) * (cubeSize * sizeMod) / (4 / aspH) + wisH / ((4 / aspH) - ((noiseScale + noiseAmp)/3));
} else {
//x = (i - j) * cubeSize / (2 * aspW) + wisW / (2 * aspW);
//y = (i + j) * cubeSize / (4 / aspH) + wisH / ((4 / aspH) - ((noiseScale + noiseAmp) / 10));
x = (i - j) * cubeSize / (2 * aspW) + wisW / (2 * aspW);
y = (i + j) * cubeSize / (2 / aspH) + wisH / 4 //+ (aspH + ((noiseScale + noiseAmp) / 10));
}
let z = map(fBm(xoff, yoff, zoff), 0, 1, 0, patchs);
cubeCoords[i][j].x = x;
cubeCoords[i][j].y = y - numLayers * cubeSize / 5 - z + (margin);
for (let k = 0; k < numLayers; k++) {
let yOffset = k * cubeSize / 2;
//drawCube(x, y - yOffset - z + margin, cubeSize, color);
y = y - yOffset - z + margin;
drawCube(x, y, cubeSize, color);
zoff += 0.1;
}
xoff += 0.1;
}
yoff += 0.1;
}
}
if (imgCopyBG == true) {
push();
blendMode(REPLACE);
imageMode(CENTER);
img.filter(GRAY);
image(img, wisW/2, wisH/2);
pop();
}
//drawBorder();
boxBorder();
//triWBorder();
//triHBorder();
noLoop();
}
function imgElips() {
while (imgRadius < wisW/2-50) {
let partX = int(random(0, img.wisW - imgCubeSize));
let partY = int(random(0, img.wisH - imgCubeSize));
let part = img.get(partX, partY, imgCubeSize*2, imgCubeSize*2);
tint(255,40);
part.resize(imgCubeSize, imgCubeSize);
if (random() < 0.2) part.filter(BLUR, 1);
if (random() > 0.97) part.filter(INVERT);
if (random() < 0.01) part.filter(GRAY);
push();
translate(wisW/2, wisH/2);
rotate(imgAngle);
translate(imgRadius, 0);
image(part, 0, 0);
pop();
imgAngle += radians(6);
imgRadius += 0.5;
}
}
function fBm(x, y, z) {
let sum = 0;
let amplitude = random(0.1, 5);
let frequency = random(0.1, 20);
let maxValue = 0;
for (let i = 0; i < octaves; i++) {
sum += amplitude * noise(x * frequency, y * frequency, z * frequency);
maxValue += amplitude;
amplitude *= persistence;
frequency *= lacunarity;
}
return sum / maxValue;
}
function drawBorder() {
push();
noFill();
stroke(l100Col(floor(random(0, patchs))).hex());
strokeWeight(wisW / wisH * border);
rect(border / 2, border / 2, wisW - border, wisH - border);
strokeWeight(wisW / height * border * 1.3);
drawingContext.setLineDash([0, 3, 5, 2, 6]);
rect(border / 2, border / 2, wisW - border, wisH - border);
pop();
}
function boxBorder() {
let twoborder = border * 2;
push();
noFill();
stroke(l100Col(floor(random(0, patchs))).hex());
strokeWeight(wisW / height * border * 1.3);
line(0, border/2, wisW + border, border/2);
line(border/2, 0, border/2, wisH + border);
line(0, wisH - border/2, wisW, wisH - border/2);
line(wisW - border/2, 0, wisW - border/2, wisH);
fill(l1Col(floor(random(0, patchs))).hex());
for (let i = 0; i < wisW; i += random(border,twoborder)) {
square(+i*2, 0, random(border,twoborder));
square(+i*2, wisH, -random(border,twoborder));
}
for (let i = 0; i < wisH; i += random(border,twoborder)) {
square(0, +i*2, random(border,twoborder));
square(wisW, +i*2, -random(border,twoborder));
}
pop();
}
function triWBorder() {
push();
noStroke();
rect(0, wisH*0.332, wisW, border*2);
rect(0, wisH*0.664, wisW, border*2);
pop();
}
function triHBorder() {
push();
noStroke();
rect(wisW*0.332, 0, border*2, wisH);
rect(wisW*0.664, 0, border*2, wisH);
pop();
}
function drawCube(x, y, size, fillCol) {
if (randMod == true) {
sizeMod = random(0.5, 5.5);
}
if (randModLight == true) {
sizeMod = random(0.15, 0.95);
}
push();
if (shake == true) {
translate(wisW / 2.5, 0);
rotate(HALF_PI);
}
if (vague == true) {
translate(-wisW * 0.1, wisH * 0.2);
rotate(random(PI, TAU));
}
translate(0, -wisH / 30 * sizeMod);
draw3DCube(x, y, size, fillCol);
if (showLines == true) {
let randLineShow = random();
if (randLineShow < showLCdensity) {
push();
noFill();
stroke(l100Col(floor(random(0, patchs))).hex());
strokeWeight(0.015);
drawingContext.setLineDash([0, 3, 0, 0, 1, 2]);
line(y, x, y, random(-wisW, wisW) + y);
drawingContext.setLineDash([1, 0, 3, 0, 1, 1]);
line(x, random(-wisH, wisH) + x, x, y);
stroke(l1Col(floor(random(0, patchs))).hex());
line(x, y, random(-wisW, wisW) + x, x);
pop();
}
}
if (showCircles == true) {
let randCircShow = random();
if (randCircShow < showLCdensity) {
xx = x + random(1,x);
yy = y + random(1,y);
push();
noFill();
strokeWeight(0.25);
stroke(l100Col(floor(random(0, patchs))).hex());
drawingContext.setLineDash([0, 3, 0, 0, 1, 2]);
random() < 0.1 ? circle(xx, xx, random(-wisW * 0.3, wisW * 0.3)) : null;
drawingContext.setLineDash([1, 0, 3, 0, 1, 1]);
random() < 0.2 ? circle(yy, yy, random(-wisW * 0.2, wisW * 0.2)) : null;
stroke(l1Col(floor(random(0, patchs))).hex());
random() > 0.9 ? circle(yy, xx, random(-wisW * 0.1, wisW * 0.1)) : null;
pop();
}
}
pop();
}
function drawCubeImg(x, y, size, fillCol) {
if (randMod == true) {
sizeMod = random(0.5, 5.5);
}
if (randModLight == true) {
sizeMod = random(0.15, 0.95);
}
push();
if (shake == true) {
translate(wisW / 2.5, 0);
rotate(HALF_PI);
}
if (vague == true) {
translate(-wisW * 0.1, wisH * 0.2);
rotate(random(PI, TAU));
}
translate(0, -wisH / 30 * img.sizeMod);
draw3DCubeImg(x, y, size, fillCol);
if (showLines == true) {
let randLineShow = random();
if (randLineShow < showLCdensity) {
img.push();
img.noFill();
img.stroke(l100Col(floor(random(0, patchs))).hex());
img.strokeWeight(0.015);
img.drawingContext.setLineDash([0, 3, 0, 0, 1, 2]);
img.line(y, x, y, random(-wisW, wisW) + y);
img.drawingContext.setLineDash([1, 0, 3, 0, 1, 1]);
img.line(x, random(-wisH, wisH) + x, x, y);
img.stroke(l1Col(floor(random(0, patchs))).hex());
img.line(x, y, random(-wisW, wisW) + x, x);
img.pop();
}
}
if (showCircles == true) {
let randCircShow = random();
if (randCircShow < showLCdensity) {
img.xx = x + random(1,x);
img.yy = y + random(1,y);
img.push();
img.noFill();
img.strokeWeight(0.25);
img.stroke(l100Col(floor(random(0, patchs))).hex());
img.drawingContext.setLineDash([0, 3, 0, 0, 1, 2]);
img.circle(img.xx, img.xx, random(-wisW * 0.3, wisW * 0.3));
img.drawingContext.setLineDash([1, 0, 3, 0, 1, 1]);
img.circle(img.yy, img.yy, random(-wisW * 0.2, wisW * 0.2));
img.stroke(l1Col(floor(random(0, patchs))).hex());
img.circle(img.yy, img.xx, random(-wisW * 0.1, wisW * 0.1));
img.pop();
}
}
pop();
}
function draw3DCubeImg(x, y, size, fillCol) {
size = size * sizeMod;
let rCo = l2Col;
img.push();
img.translate(x, y);
if (bigSeisme == true) {
img.rotate(random(PI, TAU));
}
if (nos === true) {
img.noStroke();
} else if (nosColor == true) {
img.stroke(rCo(floor(random(0, patchs))).hex());
}
// Top face
img.fill(chroma(fillCol).darken(0.1).css());
if (squareIt == true) {
img.quad(0, 0, size / 2, size / 4, 0, size / 2, -size / 2, size / 4);
}
if (roundIt == true) {
img.beginShape();
img.vertex(0, 0);
img.quadraticVertex(0, 0, size / 2, size / 4);
img.quadraticVertex(0, size / 2, -size / 2, size / 4);
img.quadraticVertex(size / 4, 0, 0, size / 2);
img.endShape();
}
// top
if (showCoord == true) {
img.push();
//img.line(0, 0, 0, size / 10);
img.translate(size / 4, 0);
img.fill(0);
img.textSize(8);
let showPosX = "x:" + Math.round((x + Number.EPSILON) * 1000) / 1000;
let showPosY = "y:" + Math.round((y + Number.EPSILON) * 1000) / 1000;
img.text(showPosX, -size / 2, size / 4);
img.text(showPosY, -size / 2, size / 3);
img.pop();
}
// left
img.fill(chroma(fillCol).darken(0.2).alpha(0.8).css());
for (let ll = 0; ll < size; ll += size / 3) {
img.push();
if (nosh === true) {
img.strokeWeight(0.35);
img.stroke(0);
}
img.drawingContext.setLineDash([5, 15, 25, 2, 12, 100]);
img.line(-size / 2, (size / 4) + ll / 2, 0, (size / 2) + ll / 2);
img.pop();
}
img.beginShape();
if (squareIt == true) {
img.vertex(-size / 2, size / 4);
img.vertex(0, size / 2);
img.vertex(0, size);
img.vertex(-size / 2, size / 4 * 3);
}
if (roundIt == true) {
img.curveVertex(-size / 2, size / 4);
img.curveVertex(0, size / 2);
img.curveVertex(0, size);
img.curveVertex(-size / 2, size / 4 * 3);
}
img.endShape(CLOSE);
// right
for (let l = 0; l < size; l += size / 5) {
img.push();
if (nosh === true) {
img.strokeWeight(0.45);
img.stroke(0);
}
img.drawingContext.setLineDash([3, 5, 15]);
img.line(0, (size / 2) + l / 2, size / 2, (size / 4) + l / 2);
img.pop();
}
img.beginShape();
if (squareIt == true) {
img.vertex(size / 2, size / 4);
img.vertex(0, size / 2);
img.vertex(0, size);
img.vertex(size / 2, size / 4 * 3);
}
if (roundIt == true) {
img.curveVertex(size / 2, size / 4);
img.curveVertex(0, size / 2);
img.curveVertex(0, size);
img.curveVertex(size / 2, size / 4 * 3);
}
img.endShape(CLOSE);
img.pop();
}
function draw3DCube(x, y, size, fillCol) {
size = size * sizeMod;
let rCo = l2Col;
push();
translate(x, y);
if (bigSeisme == true) {
rotate(random(PI, TAU));
}
if (nos === true) {
noStroke();
} else if (nosColor == true) {
stroke(rCo(floor(random(0, patchs))).hex());
}
// Top face
fill(chroma(fillCol).darken(0.1).css());
if (squareIt == true) {
quad(0, 0, size / 2, size / 4, 0, size / 2, -size / 2, size / 4);
}
if (roundIt == true) {
beginShape();
vertex(0, 0);
quadraticVertex(0, 0, size / 2, size / 4);
quadraticVertex(0, size / 2, -size / 2, size / 4);
quadraticVertex(size / 4, 0, 0, size / 2);
endShape();
}
// top
if (showCoord == true) {
push();
//line(0, 0, 0, size / 10);
translate(size / 4, 0);
fill(0);
textSize(8);
let showPosX = "x:" + Math.round((x + Number.EPSILON) * 1000) / 1000;
let showPosY = "y:" + Math.round((y + Number.EPSILON) * 1000) / 1000;
text(showPosX, -size / 2, size / 4);
text(showPosY, -size / 2, size / 3);
pop();
}
// left
fill(chroma(fillCol).darken(0.2).alpha(0.8).css());
for (let ll = 0; ll < size; ll += size / 3) {
push();
if (nosh === true) {
strokeWeight(0.35);
stroke(0);
}
drawingContext.setLineDash([5, 15, 25, 2, 12, 100]);
line(-size / 2, (size / 4) + ll / 2, 0, (size / 2) + ll / 2);
pop();
}
beginShape();
if (squareIt == true) {
vertex(-size / 2, size / 4);
vertex(0, size / 2);
vertex(0, size);
vertex(-size / 2, size / 4 * 3);
}
if (roundIt == true) {
curveVertex(-size / 2, size / 4);
curveVertex(0, size / 2);
curveVertex(0, size);
curveVertex(-size / 2, size / 4 * 3);
}
endShape(CLOSE);
// right
for (let l = 0; l < size; l += size / 5) {
push();
if (nosh === true) {
strokeWeight(0.45);
stroke(0);
}
drawingContext.setLineDash([3, 5, 15]);
line(0, (size / 2) + l / 2, size / 2, (size / 4) + l / 2);
pop();
}
beginShape();
if (squareIt == true) {
vertex(size / 2, size / 4);
vertex(0, size / 2);
vertex(0, size);
vertex(size / 2, size / 4 * 3);
}
if (roundIt == true) {
curveVertex(size / 2, size / 4);
curveVertex(0, size / 2);
curveVertex(0, size);
curveVertex(size / 2, size / 4 * 3);
}
endShape(CLOSE);
if (traceCubeLines == true) {
if (xp !== null && yp !== null) {
push();
strokeWeight(random(0.15,0.75));
drawingContext.setLineDash([0, 3, 0, 2, 1]);
if (random() < 0.4) {
line(0, 0, xp - x, yp - y);
line(size / 2, size / 4, xp - x + size / 2, yp - y + size / 4);
}
drawingContext.setLineDash([1, 0, 3, 1, 2]);
random() < 0.1 ? line(0, xp - x, 0, yp - y) : null;
pop();
}
}
xp = x;
yp = y;
pop();
}
function setGradient(x, y, w, h, c1, c2, axis) {
noFill();
if (axis === "Y") {
for (let i = y; i <= y + h; i++) {
var inter = map(i, y, y + h, 0, 1);
var c = lerpColor(c1, c2, inter);
stroke(c);
line(x, i, x + w, i);
}
} else if (axis === "X") {
for (let j = x; j <= x + w; j++) {
var inter2 = map(j, x, x + w, 0, 1);
var d = lerpColor(c1, c2, inter2);
stroke(d);
line(j, y, j, y + h);
}
} else if (axis === "R") {
var centerX = x + w / 2;
var centerY = y + h / 2;
var maxDistance = dist(centerX, centerY, x, y);
for (let i = x; i <= x + w; i++) {
for (let j = y; j <= y + h; j++) {
var distance = dist(i, j, centerX, centerY);
var angle = map(distance, 0, maxDistance, 0, TWO_PI);
var inter3 = map(angle, 0, TWO_PI, 0, 1);
var e = lerpColor(c1, c2, inter3);
stroke(e);
point(i, j);
}
}
}
}
function keyTyped() {
if (key === "s" || key === "S") {
saveCanvas("trottoir_iba-" + floor(random(100)), "png");
}
if (key === "r" || key === "R") {
clear();
setup();
redraw();
}
}