xxxxxxxxxx
var img;
function preload() {
// 500 x 500 px
img = loadImage("nasa_buzz.jpg");
}
function setup() {
createCanvas(500, 500);
background(0);
}
function draw() {
background(255);
image(img, 0, 0);
// Pixel in Speicher laden
img.loadPixels();
// Zeilen
for (var y = 0; y < img.height; y += 5) {
// Spalten
for (var x = 0; x < img.width; x += 5) {
var pixel = red(img.get(x, y));
rectMode(CENTER);
noStroke();
// Fairey Obama
if (pixel < 60)
fill(0, 43, 70);
else if (pixel >= 60 && pixel < 120)
fill(206, 24, 24);
else if (pixel >= 120 && pixel < 180)
fill(107, 139, 149);
else if (pixel >= 180)
fill(252, 224, 158);
rect(x, y, 5, 5);
}
}
}