xxxxxxxxxx
141
const Y_AXIS = 1;
const X_AXIS = 2;
function setup() {
createCanvas(1000, 1000);
background(20);
let scribble = new Scribble();
scribble.bowing = 0.1;
scribble.roughness = 1.5;
var gap = random(1.5, 5.5);
// the angle of the hachure in degrees
var angle = random(0, 360);
// setGradient(
// 0,
// 0,
// width,
// height,
// color(0, 255, 255, 20),
// color(255, 0, 255, 20),
// Y_AXIS,
// null
// );
setGradient(
0,
0,
width,
height,
color(255, 0, 255, 80),
color(0, 255, 0, 80),
Y_AXIS,
scribble
);
strokeWeight(1);
let cellsize = width * 0.05;
noFill();
let numcells = width / cellsize;
let x = 0;
let y = 0;
let r = int(random(1, numcells - 1));
let c = int(random(1, numcells - 1));
let cnt = 0;
stroke(color(255, 0, 255, 220));
// noStroke();
x = c * cellsize - 1;
y = r * cellsize - 1;
let xcoords = [x, x + cellsize, x + cellsize, x];
let ycoords = [y, y, y + cellsize, y + cellsize];
scribble.scribbleFilling(xcoords, ycoords, gap, angle);
// rect(c * cellsize - 1, r * cellsize - 1, cellsize + 2, cellsize + 2);
noFill();
// stroke(220);
noStroke();
for (let _ = 0; _ < int(random(1, 10)); _++) {
modder = int(random(1, numcells / 2));
x = 0;
y = 0;
console.log(modder);
fill(color(0, 0, 0, 100));
for (let r = 0; r < numcells; r++) {
for (let c = 0; c < numcells; c++) {
if (!(c == 0 || r == 0 || c == numcells - 1 || r == numcells - 1))
if (cnt % modder == 0) rect(x, y, cellsize, cellsize);
x += cellsize;
cnt++;
}
y += cellsize;
x = 0;
}
}
/*
// draw a horizontal line across the center of the screen
// scribble.scribbleLine(0, 0, width, height);
let cell = width * 0.25;
let hcell = cell / 2;
let hw = width / 2;
// set the thikness of our hachure lines
strokeWeight(random(0.5, 3));
//set the color of the hachure to a nice blue
stroke(0, 50, 180, 120);
let xcoords, ycoords;
for (let y = 0; y < height; y += cell) {
for (let x = 0; x < width; x += cell) {
angle = random(0,360)
xcoords = [x, x+cell, x+cell, x];
ycoords = [y, y, y+cell, y+cell];
scribble.scribbleFilling(xcoords, ycoords, gap, angle);
}
}
stroke(0, 50, 180);
// fill the rect with a hachure
xcoords = [hw - hcell, hw + hcell, hw + hcell, hw - hcell];
ycoords = [hw - hcell, hw - hcell, hw + hcell, hw + hcell];
scribble.scribbleFilling(xcoords, ycoords, gap, angle);
*/
noLoop();
}
let step = 0;
function draw() {
// background(220);
}
function setGradient(x, y, w, h, c1, c2, axis, scribble) {
noFill();
if (axis === Y_AXIS) {
// Top to bottom gradient
for (let i = y; i <= y + h; i++) {
let inter = map(i, y, y + h, 0, 1);
let c = lerpColor(c1, c2, inter);
stroke(c);
if (scribble == null) line(x, i, x + w, i);
else scribble.scribbleLine(x, i, x + w, i);
}
} else if (axis === X_AXIS) {
// Left to right gradient
for (let i = x; i <= x + w; i++) {
let inter = map(i, x, x + w, 0, 1);
let c = lerpColor(c1, c2, inter);
stroke(c);
line(i, y, i, y + h);
}
}
}