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

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, use ```processing and ``` like this:
  void setup() {
    size(600, 600);