Skip to content

Instantly share code, notes, and snippets.

@volfegan
Created February 11, 2021 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save volfegan/6b27e612da880b6e83f61965479dd9d5 to your computer and use it in GitHub Desktop.
Save volfegan/6b27e612da880b6e83f61965479dd9d5 to your computer and use it in GitHub Desktop.
Bad TV image reception: Black & White and Colour version
//based on https://www.reddit.com/r/processing/comments/lgcy90/probabilistic_dithering/
PImage img;
int w, h;
boolean colour = false;
void keyPressed() {
if (key == 'C' || key == 'c') {
if (colour) colour = false;
else colour = true;
}
}
void settings() {
img=loadImage("cat.jpg");
size(w=img.width, h=img.height);
println("w="+w+", h="+h);
}
void setup() {
noStroke();
fill(0, 50);
}
void draw() {
background(255);
if (colour) {
tint(255, 100);
image(img, 0, 0);
fill(0, 20);
} else fill(0, 50);
for (int y = 0; y < height; y+=2) {
for (int x = 0; x < width; x+=2) {
color c = img.get(x, y);
float b = brightness(c);
float p = random(256);
if (b <= p) rect(x, y, 4, 4);
}
}
image(this.get(), random(3), 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment