xxxxxxxxxx
83
/*
Inspired by Vera Molnár's Un, deux, trois
Based on a translation from Generative Artistry:
https://generativeartistry.com/tutorials/un-deux-trois/
*/
//def setup function
function setup() {
//set canvas to window width and height
createCanvas(windowWidth, windowHeight);
//end each stroke with a rounded end
strokeCap(ROUND);
//set stroke width to 4
strokeWeight(4);
}
//start draw loop
function draw() {
//set background to white
background(255);
//define step as 1/15 of width or height, whichever is smaller
let step = min(width / 15, height / 15);
//initiate for loop. set y to step. if y is less than height - step, add step to y
for (let y = step; y < height - step; y += step) {
//initiate for loop. set x to step. if x is less than width - step, add step to x
for (let x = step; x < width - step; x += step) {
//if y is less than 1/3rd of height
if (y < height / 3) {
//draw a line at step point at the center of that step point
drawLine(x, y, step, [0.5]);
// 2/3rd of canvas,
} else if (y < (height / 3) * 2) {
//draw 2 line at step point, one at 0.2 of the step and one at 0.8 of the step
drawLine(x, y, step, [0.2, 0.8]);
// 3/3 of canvas
} else {
//draw 3 line at step point, at 0.1, 0.5, and 0.9 of the step
drawLine(x, y, step, [0.1, 0.5, 0.9]);
}
}
}
//don't loop
noLoop();
}
function drawLine(_x, _y, _step, positions) {
//start transform image
push();
//move to center of canvas
translate(_x + _step / 2, _y + _step / 2);
//rotate random 0-5
rotate(random(5));
//transform to each step location
translate(-_step / 2, -_step / 2);
//for loop init, if i is less than or equal to the amount of positions add 1.
for (let i = 0; i <= positions.length; i++) {
//create a line with the provided variables
line(positions[i] * _step, 0, positions[i] * _step, _step);
}
//stop transform
pop();
}
//if window is resized, resize canvas to window size
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}
/*
MIT License
Copyright (c) 2018 Tim Holman
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/