Last active
March 16, 2017 16:28
-
-
Save unknowndomain/14b29c8ce52726f9245bbb3f8a0a1c0d to your computer and use it in GitHub Desktop.
EXP012 Seperation
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
| PImage redImg, greenImg, blueImg; | |
| PImage createChannel(float r, float g, float b) { | |
| PGraphics pg = createGraphics(200, 200); | |
| pg.beginDraw(); | |
| pg.background(0x00); | |
| pg.stroke(r, g, b); | |
| pg.strokeWeight(20); | |
| pg.noFill(); | |
| pg.rect(0.5 * pg.width, 0.5 * pg.height, pg.width - 130, pg.height - 180); | |
| pg.endDraw(); | |
| return pg; | |
| } | |
| PImage drawChannel(PImage img, float x, float y) { | |
| float u = img.width; | |
| float v = img.height; | |
| blend(img, 0, 0, int( u ), int( v ), int( x - 0.5 * u ), int( y - 0.5 * v) , int( u ), int( v ), SUBTRACT); | |
| return img; | |
| } | |
| void setup() { | |
| size(400, 400); | |
| redImg = createChannel(0xff, 0x00, 0x00); | |
| greenImg = createChannel(0x00, 0xff, 0x00); | |
| blueImg = createChannel(0x00, 0x00, 0xff); | |
| } | |
| void draw() { | |
| float x0 = 0.5 * width; | |
| float y0 = 0.5 * height; | |
| float dmouseX = mouseX - pmouseX; | |
| float dmouseY = mouseY - pmouseY; | |
| background(0xff); | |
| drawChannel(redImg, x0 - dmouseX, y0 - dmouseY); | |
| drawChannel(greenImg, x0, y0); | |
| drawChannel(blueImg, x0 + dmouseX, y0 + dmouseY); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment