Learn creative coding writing simple programs
118. Tips (copy paths, optimize, the binary AND operation)
In this short episode I make three comments about the program we created on episode 117. Nothing extremely important. You can safely skip it if you find it too serious.
1. Copying paths. It's easy to copy a path from any file in your computer and paste it inside your Processing program. This is only useful when using the Java based Processing version, not Processing.js.
2. Optimization. The original program was loading a file into a byte array, and then drawing one line for each byte. This can be very bad for performance if the file is large. For instance, if you load a 2 Mb file, it will draw 2 million lines, even the screen can only display a few hundred. For our current program, all the remaining lines would fall outside the screen. If we modify our loop to just cover the visible area the program runs much faster. Of course you could write a different program that does draw 2 million lines inside the visible area. I leave that as an exercise.
3. We have not yet studied binary operations, but we used one in the last episode to convert numbers in the range -128, 127 to the range 0, 255. In this episode we shortly compare using "map(number, -128, 127, 0, 255)" to using "number & 0xff".
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); } ```