Last active
April 18, 2017 12:26
-
-
Save soharu/177bdf2c5d70e9eee39129b5ab52acb9 to your computer and use it in GitHub Desktop.
Red filter in Processing.py
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
WIDTH = 360 | |
HEIGHT = 240 | |
def setup(): | |
global img | |
img = None | |
noLoop() | |
size(WIDTH, HEIGHT) | |
frame.setResizable(True) | |
background(200) | |
def draw(): | |
print("called draw") | |
global img | |
if img != None: | |
print(img) | |
applyRedFilter(img) | |
image(img, 0, 0) | |
def chooseFile(): | |
selectInput("Select a file to process:", "fileSelected") | |
def fileSelected(file): | |
if file == None: | |
return | |
global img | |
img = loadImage(file.getAbsolutePath()) | |
frame.setSize(img.width, img.height) | |
redraw() | |
def keyPressed(): | |
print("key pressed: " + key) | |
if key == 'c': | |
chooseFile() | |
elif key == 'p': | |
pass | |
elif key == ' ': | |
pass | |
def applyRedFilter(img): | |
img.loadPixels() | |
numberOfPixels = len(img.pixels) | |
for i in range(numberOfPixels): | |
pixel = img.pixels[i] | |
a = alpha(pixel) | |
r = 0 | |
g = green(pixel) | |
b = blue(pixel) | |
img.pixels[i] = color(r, g, b, a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I made it by referring to 500lines - Make your own image filters.