xxxxxxxxxx
159
// REFERENCES:
// https://svg2p5.com/
// https://www.svgrepo.com/vectors/planet/
// https://programmingdesignsystems.com/shape/procedural-shapes/index.html
const DPI = 72;
// these are variables can be changed
// WIDTH and HEIGHT define the size of the printing
// N defines the character count
const WIDTH = 9, HEIGHT = 5, N = 12, EXTRA_SKY = 0; // horizontal
// const WIDTH = 9, HEIGHT = 18, N = 26, EXTRA_SKY = 3; // vertical
// const WIDTH = 7, HEIGHT = 12, N = 18, EXTRA_SKY = 3; // vertical small
const WARMACHINES = [
shape_cannon,
shape_fighter,
shape_rifle,
shape_rocket,
shape_sword,
shape_tank,
];
const WORDS = [
"FREEDOM",
"HUMANRIGHTS",
"LIFE",
"FUTURE",
"LIVINGTHINGS",
"LOVE",
"TRUST",
];
let svgs = [];
function choose(list) {
return list[floor(random() * list.length)];
}
function drawWarMachine(layer=window, shape=()=>{}) {
// color and outlines
layer.noStroke();
layer.fill(255);
// draw shapes
layer.push();
layer.translate(0.5*DPI, (HEIGHT - 2.5)*DPI);
shape(layer);
layer.pop();
}
function drawSky(layer=window) {
layer.push();
layer.translate(width, 0);
layer.scale(3);
layer.noStroke();
const startingScale = 1 / pow(0.9, EXTRA_SKY);
layer.scale(startingScale);
for (let i = 10+EXTRA_SKY; i > 5; i--) {
layer.fill(map(i, 10+EXTRA_SKY, 6, 64, 110));
layer.rotate(random() * PI);
// const extra_layer = createGraphics(width, height);
// shape_sky(extra_layer, i * floor(random() * 2 + 3));
// layer.cutout(extra_layer);
shape_sky(layer, i * floor(random() * 2 + 3));
if (i > 10) {
layer.scale(0.9);
} else {
layer.scale(0.8);
}
if (i <= 8) {
layer.scale(0.9);
}
}
layer.pop();
}
const S = (WIDTH - 3) * DPI;
const H = (HEIGHT - 3) * DPI;
const A = H / (S * S);
function routeFn(step) {
const x = - S / N * (N - step);
const y = - A * x * x + H;
return [x, y];
}
function drawPhrase(layer=window, word="") {
layer.textSize(28);
layer.fill(255);
layer.stroke(255);
word += " ";
for (let step = 0; step < N; step++) {
layer.push();
const c = word[step % word.length];
const [dx, dy] = routeFn(step);
layer.translate(width+dx, (HEIGHT - 2)*DPI-dy);
layer.rotate(((random() * 0.6) - 0.3) * PI);
const s = random() * 0.6 + 0.7;
layer.scale(s, s);
layer.text(c, 0, 0);
layer.pop();
}
}
function drawOnce(){
background(255);
Riso.channels = [];
clearRiso();
const backgroundLayer = new Riso("blue");
backgroundLayer.fill(200);
backgroundLayer.rect(0, 0, width, height);
const layer1 = createGraphics(width, height);
// const layer1 = new Riso("blue");
const layer2 = new Riso("red");
// draw a random war machine
drawWarMachine(layer1, choose(WARMACHINES));
// draw sky
drawSky(layer2);
// draw a random phrase
drawPhrase(layer1, choose(WORDS));
layer2.cutout(layer1);
backgroundLayer.cutout(layer2);
backgroundLayer.cutout(layer1);
drawRiso();
}
function setup() {
createCanvas(WIDTH * DPI, HEIGHT * DPI);
pixelDensity(1);
drawOnce();
}
function keyPressed() {
switch (keyCode) {
case ENTER:
exportRiso();
break;
case 32:
drawOnce();
break;
}
}