xxxxxxxxxx
90
// basic 10 PRINT based on Dan Schiffman's
// Coding Challenge #76
// https://thecodingtrain.com/challenges/76-10Print
// declare and initialize some variables
let x = 0;
let y = 0;
let spacing = 50;
let choice = 0;
//choices of colors
let colors = [
{r: 200, g: 40, b: 40}, //red ish
{r: 40, g: 40, b: 200}, //blue ish
{r: 40, g: 200, b: 40}, // green ish
{r: 240, g: 40, b: 240}, //purple ish
{r: 40, g: 240, b: 240}, //cyan ish
{r: 240, g: 240, b: 40}, //yellow ish
];
function setup() {
createCanvas(1000, 1000);
// draw background just once!
background(20);
}
//different stroke every stroke
function strokeChange() {
//stroke(random(256),random(256),random(256)); // random color
choice = int(random(colors.length)); //choose a random index
stroke(colors[choice].r, //assign chosen index's color
colors[choice].g,
colors[choice].b);
strokeWeight(int(random(5))); // random stroke weight out of 5
fill(colors[choice].r, //assign chosen index's color
colors[choice].g,
colors[choice].b);
}
function draw() {
// half the time draw a line from upper left to lower right
// diagonal draw
if (random() == random()) {
line(x, y, x + spacing, y + spacing);
strokeChange();
} else {
// otherwise, the opposite
line(x, y + spacing, x + spacing, y);
strokeChange();
}
//ellipse printed horizontally
ellipse(x,y,spacing/5);
// increment y spacing
y = y + spacing;
// when x is at the far right
if (x > width) {
// reset x to the left, and
x = 0;
// increment y spacing - new column!
y = y + spacing;
//increment spacing each time x reaches right
spacing++;
}
// when y is at the very bottom
if (y > height) {
// reset y to the top, and
y = 0;
// increment x spacing - new column!
x = x + spacing;
}
//if (x > width) {
// saveCanvas('Lab03', 'png');
// noLoop();
//}
}