Skip to main content

PYTHON PROCESSING / Working with Image

IMAGE being drawn on top of each other on every loop. Each image is drawn on the position of mouse X and Y. Can you guess what image is this?

Continuing with my Python Processing study. I wanted to touch on IMAGE object real soon because it is one of the most fun topic we can do pretty quickly and easily.

While doing this, I am also looking at the provided example on IMAGE topic and also this YouTube video tutorial by John Park on Processing 3 (Java): https://youtu.be/ddtdPO3m1hw



What I am showing here is pretty basic however important for beginners and I am familiarizing myself with Python language for Processing. Instead of Java.

The whole code looks like below, with some parts commented for you to try yourself:
# Testing image processing using Python Processing
def setup():
size(640, 360)
global img
img = loadImage("yoshi1.png") # load and variable of image
#noLoop()
def draw():
# background(20,150,111)
# image( img, x, y, size_x, size_y)
#imageMode(CORNER)
#image(img, 100, 100, img.width/4, img.height/4)
#image(img, 200, 100, img.width/4, img.height/4)
#image(img, 300, 100, img.width/4, img.height/4)
#image(img, 400, 100, img.width/4, img.height/4)
imageMode(CENTER)
image(img, mouseX, mouseY, img.width/10, img.height/10)
#image(img, 0, height/2, img.width/2, img.height/2)

Few important notes:

  • With Python, we do not seem have to explicitly specify the TYPE of object instance we are creating, in this case the IMAGE type. We simply load the image from path. Python guess the object type.
  • We probably need to definte the image variable as GLOBAL
  • imageMode(CORNER) or imageMode(CENTER) are useful to set the placement of image
  • noLoop() and background() are kind of related. When we allow LOOP and draw() to run everytime and with no background() we will get the image being drawn over and over again each processing run, so we get overlapping result
I really feel that Python language really makes Processing experience a lot friendlier.

A slight modification to the script above and we can get this image below.

Image YOSHI that I borrowed from the Internet. It's PNG so it can have transparency.



Not sure how the whole Processing works together with Python modules or Java modules, but in the basic level, loading image, displaying image and assigning MOUSE POSITION to draw the image is a lot simpler!

There are many other METHODS of IMAGE object type in Processing you can use to modify the image, you can check for image related examples and also the documentations.

I guess the rest is up to you what you wanted to do with image, but this is only touching the very basic of:
- Creating a variable for image type of object
- Loading Image
- Displaying Image
- Drawing Image on specific position
- Drawing Image on mouse position

Enjoy!

Comments

Popular posts from this blog

WOLFRAM / Making Text With Rainbow Color

Continuing with my Wolfram Mathematica Trial Experience... I watched and went through some more Mathematica introduction videos, read lots of Mathematica documentation and also going through the Wolfram Lab Online again a few times. There are some major learning curves and Mathematica is a lot different from normal programming language. Sometimes there is a lot of interesting "shortcuts", say like: FindFaces[] , WordCloud[] . Sometimes I got a little confused on how one can do iterations. Normally FOR LOOP concept is introduced early, but in Wolfram, because everything is EXPRESSIONS and ENTITY (like OBJECTS), sometimes it gets quite quirky. Mind you I am still in the first impression and having to look at many tutorials. Lots of NEAT EXAMPLES from documentation, but sometimes I got lost. I found Wolfram to be really awesome with LIST and generating list. It's almost too easy when it works visually. I cannot explain them with my own words yet, but there are ...

PYTHON PROCESSING / It only really begins ...

Back into Processing again, with Python! While Daniel Shiffman is continuously inspiring us with his CODING TRAIN series on YouTube, using Processing with Java and Javascript language, I decided to free my mind and trying to really do something using Processing and Python language. Installing Python language version on Processing 3 is easy enough, just first download the latest Processing and install the Python language mode via Add Mode button. Other link that might help: https://github.com/jdf/processing.py http://py.processing.org/tutorials/ BLANK MODE As soon as Processing Python Mode, opens up and running I am presented with a  blank environment. Suddenly I recalled my journey in learning programming from zero until now... With Python, outside Processing, commonly people will be introduced to Python IDE or IDLE environment. Something that looks like Console Window or Command Prompt, where we type single liners command. Python Command Line and IDE normally ha...

SONICPI / Ruby, Python, MIDI and OSC

I have a big curiosity on how we can use OSC or MIDI to send message from one app to another app, potentially to generate (realtime) synth sound, visualization, and animation. This is especially a fun area and environment when we wanted to use CODE for CREATIVITY. Sonic Pi (by Sam Aaron) is one app I really love to use when dealing with Synth and Sonic generator. I remember using ChucK in the past by Ge Wang, ChucK is also cool, but Sonic Pi is a lot more friendly. http://sonic-pi.net Sonic Pi multi-threaded ness and LIVE LOOP is really something new for me. But Sam made it easy enough so that we could generate "listener" very easily. MAKING SOUND WITH CODE There are plenty of ways we can "trigger" Sonic Pi to generate sound. Obviously we can just use the built in RUBY language inside Sonic Pi app. Fairly simple and fun language to use and you can generate some noise in no time! Sonic Pi RUBY language documentation is really in depth and a full on progr...