Learn creative coding writing simple programs

51. Convert float into int and animate a photo

We now continue with the program started in episode 49 where we copy() part of a photo and show this part on our screen. The idea is to animate it by moving which part of the loaded photo we show. If we randomly change the vertical position of the part we copy, we will have an interesting effect. But we encounter a little problem: copy accepts only integer values like 2, 5, 33 or 43, but random() and noise() return float values like 1.4325 or 38.4124. We solve this by converting the float value into an integer by using the int() function.

Tags: copy, int, float, convert, datatype, software tutorial

Code editor

You can make changes to the code below. Then

Questions and comments

Try to stay close to the topic of this episode. Use the Processing forums for help with unrelated Processing projects (or hire me for help ;-)

To indicate that a word in your comment is code, use the `backtick`. Example
Do `float` and `int` smell similar?
To highlight code blocks, surround it with ``` code-fences ``` like this:
``` void setup() { size(600, 600); } ```