Learn creative coding writing simple programs

116. Reading and displaying bytes, part 1

After using noise() and random() very often, let's take a look at reading data from computer files. We get started by doing some experiments converting bytes into colors. All computer files are full of bytes, so why not take a look at them? Maybe we can find differences between the colors given by each file type.

In part 1 we create some files just to show that one letter often occupies one byte, except for special letters which can occupy more bytes. 1 megabyte is 1 million bytes. A typical camera image these days occupies several megabytes, so that's the size of several million letters.

Reading bytes from files is very easy, you just need the loadBytes() function. Be careful with the file size of the files you load. It's probably good to avoid files larger than 10 Mb. If you try loading a large movie file with hundreds of megabytes, your computer may stop responding for a while.

This episode is split in two parts because apparently I just talk too much :)

Tags: loadBytes, data, byte, megabyte

Code editor

You can make changes to the code below. Then
Below you can ask and answer questions related to this video. If your question is unrelated to the video, please post it at the Processing Forum as I'm unable to help with all of your programs and still have enough free time to eat and sleep :)
comments powered by Disqus