Viewers: in countries Watching now:
Start communicating ideas and diagramming data in a more interactive way. In this course, author Barton Poulson shows how to read, map, and illustrate data with Processing, an open-source drawing and development environment. On top of a solid introduction to Processing itself, this course investigates methods for obtaining and preparing data, designing for data visualization, and building an interactive experience out of a design. When your visualization is complete, explore the options for sharing your work, whether uploading it to specialized websites, embedding the visualizations in your own web pages, or even creating a desktop or Android app for your work.
In order to do data visualization in Processing, the first thing you have to do is actually have data in Processing to work with. The simplest version of this is to actually have the data embedded as an array in the sketch itself, and that's what we're going to start with. We've actually been doing this for quite a while. When we've been using the color information, those are arrays that we've put in. I'm going to show you how we can actually use a data set and then try to draw a depiction of that data. The first thing I'm going to do is I'm going to just put down the sketch name as a comment.
It is not necessary, but I find it handy. Then I'm going to bring in a palette to work with. I'm going to use this one up here. Just copy it and go back and paste it in. There we go. First I set the window size, size 600 x 200. For the background we will use the palette's first color, index number 0, and we'll turn on the anti-aliasing.
Then what I'm going to do is I'm going to introduce some data in an array, and this is going to be an integer array, because these are all going to be a whole numbers. So, I put int, and then I put the open and closing squar to indicate that it's an array. Then I'm going to give it a name. I'm actually going to use numbers from the Fibonacci sequence. And so I call it the array Fibonacci. And then because I'm entering the data directly into the sketch, I just use curly brackets and I start putting the numbers in. I go 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, and 377. Of course, it's an infinite sequence, but these are all the numbers in the Fibonacci sequence that are less than 600, so this is an reasonable place to work with.
So, I'm going to use a curly bracket to close it and a semicolon to finish it off. So, that's my data array. It's a very small amount of data, but it's enough for our particular purpose is. Then what I'm going to do is I'm actually going to draw a bunch of marks on my window to indicate the data. I am going to use a for loop for this. That's probably the easiest way to do it. So, I do for, and then I have my initialization statement. I'm going to use the local variable i, start at 0. And then as long as i is less than the length of the Fibonacci array--and then I put in curly brackets what I want it to draw.
And once I have my loop set up, I can put the code inside that I want to repeat for every item in the array. What I'm going to do is I'm first going to set the stroke to the index number 1 in the color array. Then I'm going to set this strokeWeight to 2 pixels. Then I'm going to create a variable x to get the x coordinate for each one, and that's just going to be based off of each item in the array, and I do that with the index number.
And then I put the function in for an ellipse. And then I save that and run it and there we have. Now, you'll see there are a couple things going on here. Number one is, the stuff is really jammed over at the left end. One way of dealing with that is to make the shapes somewhat transparent, and that can be a neat effect, so I'm going to do that right here. And in fact, I think what I'm going to do is I'm temporally going to turn off the stroke and I'll replace that with noStroke.
And then we'll get down to the fill. What I'm going to do is I'm going to specify a fill. Let's make it the second item in the palette, but let's make it very transparent. So, let's try 50 on the 0 to 255 scale. Now, when we do that, it gets a lot ghostlier, but you can see that things are building up at the left end. And so there are times when using transparency can be a very helpful way of allowing people to see layered data.
There is probably a better way in this particular situation though-- I'll close this window--and that is instead of using ellipses, we draw lines. And so now I'll bring in the line function, line x. I'm going to start at about 75 pixels down. Then we'll go to x. Then we'll go to 125 pixels, and that should be enough. And now what we have is, because of the lines, they're vertical and they are kind of tall, they still have prominence, but because they're thinner than the ellipses are, it doesn't have quite that pile-up problem that it used to.
I think though, I might change the strokeWeight, and I'll just turn this off so it will be back at the default 1, and that works even a little bit better. And the idea here as you can see how the Fibonacci sequence is increasing dramatically as it goes through. Anyhow, this is our first way of dealing with embedded data in a representation of that data, and this is our first data visualization in Processing.
There are currently no FAQs about Interactive Data Visualization with Processing.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.