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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
yuchima commentedSep 19, 2015
Hello Dan,
In sketch3.js, does get() means a screenshot of an area?
and set() means paste that area h height upper?