Created
February 11, 2021 21:01
-
-
Save volfegan/6b27e612da880b6e83f61965479dd9d5 to your computer and use it in GitHub Desktop.
Bad TV image reception: Black & White and Colour version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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