Last active
August 4, 2020 14:09
-
-
Save volfegan/d3d9ca1ecf87b46ee8dab82e3e449caa to your computer and use it in GitHub Desktop.
Gradually puts colour on Black and White images
This file contains hidden or 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
| //tweet size: https://twitter.com/VolfeganGeist/status/1290397301522010112 | |
| float t=0; | |
| PImage img; | |
| PImage back_white; //image processed | |
| String filename; | |
| void keyPressed() { | |
| if (keyPressed) { | |
| if (key == 'r' || key == 'R') { | |
| println("r"); | |
| t = 0; //reset to Black & White image | |
| } | |
| } | |
| } | |
| //there is no file validation, so any non-img selected will crash the program | |
| void fileSelected(File selection) { | |
| if (selection == null) { | |
| println("No image file selected."); | |
| exit(); | |
| } else { | |
| String filepath = selection.getAbsolutePath(); | |
| filename = selection.getName(); | |
| int pos = filename.lastIndexOf("."); | |
| if (pos != -1) filename = filename.substring(0, pos); | |
| println("File selected " + filepath); | |
| // load file here | |
| img = loadImage(filepath); | |
| } | |
| } | |
| void interrupt() { | |
| while (img==null) delay(200); | |
| } | |
| void settings() { | |
| selectInput("Select an image file to process:", "fileSelected"); | |
| interrupt(); //interrupt process until img is selected | |
| //for testing | |
| //img = loadImage("test.jpg"); | |
| width = img.width; | |
| height = img.height; | |
| if (width > 1920) { | |
| int resizer = width / 1200; | |
| width = 1200; | |
| height = height / resizer; | |
| img.resize(width, height); | |
| } | |
| if (height > 1080) { | |
| int resizer = height / 900; | |
| height = 900; | |
| width = width / resizer; | |
| img.resize(width, height); | |
| } | |
| //the canvas window size will be according to the img size | |
| size(width, height); | |
| } | |
| void setup() { | |
| image(img.get(), 0, 0); | |
| filter(GRAY); | |
| back_white = this.copy(); | |
| } | |
| void draw() { | |
| if (t<255 && frameCount > 200) t+=.5; | |
| if (t==255) {println("Colourfy complete");t++;} | |
| tint(255, 255-t); //Apply transparency fading black & white | |
| image(back_white, 0, 0); | |
| tint(255, t); //Apply transparency increasing colour img | |
| image(img, 0, 0); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment