-
-
Save Melvin-Abraham/d4e1c3dafb239ed508a664a3021d8493 to your computer and use it in GitHub Desktop.
10PRINT in p5.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 10print.org | |
// Animated version of 10 print. | |
var x = 0; | |
var y = 0; | |
function setup() { | |
createCanvas(640, 360); | |
background(255); | |
} | |
function draw() { | |
if (random(1) > 0.5) { | |
line(x, y, x+20, y+20); | |
} | |
else { | |
line(x, y+20, x+20, y); | |
} | |
x += 20; | |
if (x > width) { | |
x = 0; | |
y += 20; | |
} | |
if (y > height) { | |
background(255); | |
x = 0; | |
y = 0; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 10print.org | |
// Static all in a loop | |
function setup() { | |
createCanvas(640, 360); | |
} | |
function draw() { | |
background(255); | |
for (var y = 0; y < height; y += 20) { | |
for (var x = 0; x < width; x += 20) { | |
if (random(1) > 0.5) { | |
line(x, y, x + 20, y + 20); | |
} else { | |
line(x, y + 20, x + 20, y); | |
} | |
} | |
} | |
noLoop(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 10print.org | |
// Ported from the book | |
var w = 16; | |
var h = 16; | |
var index = 0; | |
function setup() { | |
createCanvas(640, 384); | |
background('#0000ff'); | |
strokeWeight(3); | |
stroke(224); | |
} | |
function draw() { | |
var x1 = w*index; | |
var x2 = x1 + w; | |
var y1 = h*23; | |
var y2 = h*24; | |
if (random(2) < 1) { | |
line(x2, y1, x1, y2); | |
} | |
else { | |
line(x1, y1, x2, y2); | |
} | |
index++; | |
if (index == width/w) { | |
var p = get(0, h, width, h*23); | |
background('#0000ff'); | |
set(0, 0, p); | |
index = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment