画像を表示する
size(512, 512);
PImage image = loadImage("lena.jpg");
image(image, 0, 0);
画像に色をつける
PImage image;
void setup(){
size(512, 512);
image = loadImage("lena.jpg");
image(image, 0, 0);
}
void draw(){
tint((float(mouseY) / height) * 255);
image(image, 0, 0);
}
画像の色を取得する
PImage image;
void setup(){
size(512, 512);
noStroke();
image = loadImage("lena.jpg");
}
void draw(){
image(image, 0, 0);
fill(255, 255, 255);
rect(width/2, 0, width, height);
fill(get(mouseX, mouseY));
rect(width/2, 0, width, height);
}
モザイクにする
PImage image;
int samplingWidth = 10;
void setup(){
size(512, 512);
noStroke();
image = loadImage("lena.jpg");
image(image, 0, 0);
loadPixels();
for(int x = 0; x < width; x += samplingWidth){
for(int y = 0; y < height; y += samplingWidth){
color c = pixels[y * width + x];
fill(c);
rect(x, y, samplingWidth, samplingWidth);
}
}
}
白黒化する
PImage image;
void setup(){
size(512, 512);
noStroke();
image = loadImage("lena.jpg");
image(image, 0, 0);
loadPixels();
for(int x = 0; x < width; x += 1){
for(int y = 0; y < height; y += 1){
color c = pixels[y * width + x];
float grey = 0.30 * red(c) + 0.59 * green(c) + 0.11 * blue(c);
pixels[y * width + x] = color(grey, grey, grey);
}
}
updatePixels();
}
2値化する
PImage image;
void setup(){
size(512, 512);
noStroke();
image = loadImage("lena.jpg");
}
void draw(){
image(image, 0, 0);
loadPixels();
for(int x = 0; x < width; x += 1){
for(int y = 0; y < height; y += 1){
color c = pixels[y * width + x];
float grey = 0.30 * red(c) + 0.59 * green(c) + 0.11 * blue(c);
if(grey > (float(mouseY) / height) * 255){
pixels[y * width + x] = color(255);
} else {
pixels[y * width + x] = color(0);
}
}
}
updatePixels();
}