Created
November 25, 2017 17:23
-
-
Save KrabCode/6e30aaac1a8aaf26a4c97cec596b8d2a to your computer and use it in GitHub Desktop.
screenshot seeded animated christmas
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 java.awt.*; | |
| PImage orig; | |
| int scaledown = 2; | |
| public void settings() | |
| { | |
| orig = screenshot(); | |
| // orig = loadImage("C:\\Projects\\Sand\\ohno.jpg"); | |
| if(orig.width == 1920 && orig.height == 1080){ | |
| fullScreen(); | |
| scaledown = 1; | |
| }else{ | |
| size(orig.width/ scaledown, orig.height/ scaledown); | |
| } | |
| } | |
| public void setup(){ | |
| imageMode(CENTER); | |
| image(orig, width/2, height/2,orig.width/scaledown, orig.height/scaledown); | |
| } | |
| public void draw() | |
| { | |
| loadPixels(); | |
| modifyPixels(); | |
| updatePixels(); | |
| // saveFrame(); | |
| checkInput(); | |
| } | |
| private void modifyPixels(){ | |
| for(int x = 0; x < width; x++) { | |
| for (int y = 0; y < height; y++) { | |
| if(coinFlip()){ | |
| shiftUpwards(x, y); | |
| } | |
| else{ | |
| shiftLeft(x,y); | |
| } | |
| } | |
| } | |
| } | |
| private void shiftUpwards(int x, int y){ | |
| if(getPixel(x, y) > getPixel(x+1, y)){ | |
| swapPixels(x, y, x, y+1); | |
| } | |
| } | |
| private void shiftLeft(int x, int y){ | |
| if(getPixel(x, y) > getPixel(x, y+1)){ | |
| swapPixels(x, y, x+1, y); | |
| } | |
| } | |
| private boolean coinFlip(){ | |
| return (random(1)>0.5f); | |
| } | |
| private int getPixel(int x, int y){ | |
| int index = x + y * width; | |
| if(index < pixels.length && index > 0){ | |
| return pixels[index]; | |
| } | |
| return 0; | |
| } | |
| private void setPixel(int x, int y, int clr){ | |
| int index = x + y * width; | |
| if(index < pixels.length && index > 0){ | |
| 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; | |
| } | |
| public void checkInput(){ | |
| frame.requestFocus(); | |
| if(keyPressed){ | |
| exit(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment