Skip to content

Instantly share code, notes, and snippets.

@soharu
Last active April 18, 2017 12:26
Show Gist options
  • Save soharu/177bdf2c5d70e9eee39129b5ab52acb9 to your computer and use it in GitHub Desktop.
Save soharu/177bdf2c5d70e9eee39129b5ab52acb9 to your computer and use it in GitHub Desktop.
Red filter in Processing.py
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)
@soharu
Copy link
Author

soharu commented Apr 18, 2017

I made it by referring to 500lines - Make your own image filters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment