Skip to content

Instantly share code, notes, and snippets.

@shiffman
Created September 15, 2015 20:02
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shiffman/e683b93f5600dbb7495f to your computer and use it in GitHub Desktop.
Save shiffman/e683b93f5600dbb7495f to your computer and use it in GitHub Desktop.
10PRINT in p5.js
// 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;
}
}
// 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();
}
// 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;
}
}
@yuchima
Copy link

yuchima commented Sep 19, 2015

Hello Dan,
In sketch3.js, does get() means a screenshot of an area?
and set() means paste that area h height upper?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment