Last active
November 26, 2017 22:44
-
-
Save KrabCode/114b388e74f8f77fd8818683b2ea42f2 to your computer and use it in GitHub Desktop.
pixel screensaver sketch with flame effects
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
| import processing.core.PApplet; | |
| import processing.core.PImage; | |
| import java.awt.*; | |
| PImage orig; | |
| int scaledown = 1; | |
| public void settings() | |
| { | |
| fullScreen(); | |
| orig = screenshot(); | |
| } | |
| public void setup(){ | |
| imageMode(CENTER); | |
| image(orig, width/2, height/2,orig.width/scaledown, orig.height/scaledown); | |
| } | |
| public void draw() | |
| { | |
| loadPixels(); | |
| modifyPixels(); | |
| updatePixels(); | |
| } | |
| private void modifyPixels(){ | |
| for(int y = 0; y < height-1; y++) { | |
| for(int x = 0; x < width-1; x++){ | |
| if(getPixel(x, y) > getPixel(x+1, y)){ | |
| swapPixels(x, y, x, y+1); | |
| } | |
| } | |
| } | |
| } | |
| private int getPixel(int x, int y){ | |
| int oneDim = x + y * width; | |
| if(oneDim < pixels.length){ | |
| return pixels[oneDim]; | |
| } | |
| return color(255); | |
| } | |
| private void setPixel(int x, int y, int clr){ | |
| int oneDim = x + y * width; | |
| if(oneDim<pixels.length){ | |
| pixels[x + y * width] = clr; | |
| } | |
| } | |
| private void swapPixels(int x0, int y0, int x1, int y1){ | |
| int a = getPixel(x0, y0); | |
| int b = getPixel(x1, y1); | |
| setPixel(x0, y0, b); | |
| setPixel(x1, y1, a); | |
| } | |
| private PImage screenshot() { | |
| PImage screenshot = null; | |
| try { | |
| screenshot = new PImage(new Robot().createScreenCapture(new Rectangle(0, 0, displayWidth, displayHeight))); | |
| } catch (AWTException e) { | |
| e.printStackTrace(); | |
| } | |
| return screenshot; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment