get(x,y) and loadpixels()
in
Programming Questions
•
2 years ago
Hello,
in the old processing's forum i found a script for dithering :
- PImage photo;
- int n=4;
- void setup() {
- photo = loadImage("image.jpg");
- size(photo.width,photo.height,P3D);
- loadPixels();
- }
- void draw() {
- dither();
- }
- void dither() {
- float f=255./(pow(2,2*n)+1);
- for (int x=0;x<width;x++) {
- for (int y=0;y<height;y++) {
- color c=(photo.get(x,y));
- float t=(n>0?dizza(x,y,n)*f:128);
- if (n==5 ) {
- } else if(key == 'c') {
- int r=(t>=red(c)?0:255);
- int g=(t>=green(c)?0:255);
- int b=(t>=blue(c)?0:255);
- c=color(r,g,b);
- } else if(key == 'n') {
- c=color(t>=(red(c)+green(c)+blue(c))/3.?0:255);
- }
- pixels[x+y*width]=c;
- }
- }
- updatePixels();
- //image(photo,0,0);
- }
- void mousePressed() { n=(n>0?n-1:5);}
- int dizza(int i, int j, int n) {
- if (n==1) {
- return (i%2!=j%2 ? 2 : 0) + j%2;
- }
- else {
- return 4*dizza(i%2, j%2, n-1) + dizza(int(i/2), int(j/2), n-1);
- }
- }
1