Start learning with our library of video tutorials taught by experts. Get started
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 this movie, I want to show you some of the methods that Processing gives you for manipulating the grid on which you make your sketches, that is the invisible grid that exists inside the window of pixels across and pixels up and down. Let's start this by putting a little comment here at the top of the drawing, at the top of the sketch and I'm going to bring in a color palette as an array, this one is called chemistry and what I have is OC2550, I am to remove the space and turn on the capitals to do this.
Next one is A3DOC1, next one is FDF6DD, after that is FEE406 and the last one is a F4651. I close with a curly bracket, and that's the palette that I'm going to be using can be using for this particular design, and then I'm going to introduce a secondary palette, just to keep the name. Great.
Now what I'm going to do, is I'm going to create a size window. I'm going to do 600x200, I'm going to turn on smooth, I'm going to turn off the strokes and I'm going to make the background, the first color in the palette. We can just check that up by seeing, yep, there we have a dark blue. All right, now there's two other variables that I want to introduce into this one, that are going to be helpful in creating the shapes I use for this one.
I'm going to have one that is the size of some of the shapes, "s" is for size, I'll make that 80; then I have another one "d" that'll also be used in specifying the size of some very small circles within the drawing. OK. So now I've got my two arrays for the color palettes. I have two integer variables that are used for determining the sizes of objects in the drawing and then I have some specifications for the window itself. Next, I'm going to come down and draw a rectangle. What I'm going to do, is I'm going to put that one with a fill of the first item from the palette, then the rectangle and then I'm going to start by putting this one way up in the corner 0, 0 starts in the origin of the top left and then it will be "s" or 80 pixels wide and 80 pixels tall.
I'm using the variable "s" for that; so when I do that there is my rectangle, right up there in the corner. And what I'm also going to do, is I'm going to draw a small dot to indicate where the origin is because as you see on some of these, the origin is going to be moving around a little bit. So I'm going to do fill, actually I'll just copy this and this one, I'm going to make palette the fourth color and I'll put ellipse, and the ellipse will be right on the origin and it is going to be "d" for diameter across and down.
So now, when I draw it, you see at least a quarter of a small orange circle at the 0, 0 origin point in the drawing. Now what I'm going to show you is that you can translate, that is you can move over the origin point. So if you don't want to origin at the side of the top, say for instance, you want it in the middle, you can move it around. So we're just going to show how to translate and what I'm going to do right here is I type in the function translate and then, I specify how many pixels over and down I want it to move.
If you wanted to go straight to the center of the drawing, you can do like this width/2 and height/2 and what that would do is it would put the origin right at the middle of the sketch. What I'm going to do however, is I'm going to move it over not quite so far. I'm going to move it over just 40 pixels over and 90 pixels down. And then what I'm going to do, is I'm going to copy these commands right here. The only thing I'm going to do is I'm going to change the palette color for the rectangle, I save it and run that and now, you can see I have a second rectangle a second square, that's drawn lower and slightly to the right of the first one.
However, the orange dot for this one is still on the 0, 0 origin point. And so, I haven't moved the rectangle per se, I've shifted the entire grid for the drawing and now this is going to be a very helpful way if you have an entire collection of shapes that together form an object and they can stay in orientation this way. The next transformation we're going to do is to change the scale of the grid that we're dealing with. I'm going to do this one, by copying some of this text up here and bringing it down.
We're going to translate again, to move the origin over because I want to be able to show exactly, where the origin is at each point. We'll go 140 to the right and then, we'll go -70 to bring it back up a little bit. But then I'm going to add a second transformation. I'm going to put a scale and I'm just going to put a 2 to make it all twice as big, 2 and now it'll be twice as big and I'm going to switch the palette to get to the third color for the rectangle. I save that and press Run, and now I have yet another rectangle and please note, I'm using the exact same parameters for the rectangle, it is still located at 0, 0 with a size of "d" on both sides, that's the same on all of them.
What I'm doing is I'm moving the origin point, and I'm also changing the size of the grid. Now there is one interesting thing here, you may have noticed that not only did the square get twice as big, the circle got twice as big, and it's possible that you don't want the circle to get bigger. And so what you can do is you can actually undo the transformation of scale, before you draw the circles, I'm going to do that right here by copying this part scale and all you need to do to get back to where you are is use the reciprocal. So the reciprocal of two is one half.
I'm going to write that as .5 and what we get is that the dot stays the same size even though the rectangle has changed. This can be a good way of maintaining some of the cohesion between the elements in your design. The last thing that I want to show you is, that you can actually rotate the grid as well. So I'm going to copy this code right here, I'll change this one to rotate, I'm going to translate this one more time, to move the point of origin over from where it is on the large yellow circle.
To do that, I'm going to go translate. Instead of 140, I'm going to move it over a fair amount to 280 and I'm going to add 10 and again, this is relative to the last transformation to that point of origin. I'm going to change the scale a little bit. I'm going to change it to 1.33 and then, I'm going to add another command here, where we rotate and then what rotating does, is it rotates the entire grid from the 0, 0 origin point and it rotates it clockwise.
And when we dealt with arcs a while ago, you remember that we had to specify things in radians. And radians work on units of PI. So halfway around the circle is PI and all the way around the circle is 2x PI and 90 degrees is .5 PI and so on. What I'm going to do in this one, is I'm going to make just a small rotation. I'm going to type in PI which needs to be in capital letters, I'm going to multiply times .5, so I'm going to do just a quarter PI, a small rotation.
Now, if you want to, you do have the option of writing that out in degrees. You can do rotate and then, you can use a radians function and you can take 90 degrees and that will take 90 degrees translate into radians for you either way, it works, I'll comment that out just for right now. And then I'm going to look at my palette, I'm going to go to back to color 1 on this, and still 0, 0 and s, s and I can hit draw and but first I see that I've missed a semicolon up here, to finish that off.
All right, and now I can hit draw and what you see is that this last rectangle has rotated itself and it's done it not by rotating the angle per se, I didn't need to use a quadrangle functions instead of the square. I was able to rotate the entire grid for this. Now if I continued to add more squares, they would be on the same rotated and rescaled grid. But this lets you know that sometimes instead of changing the shape that your drawing, it's easier to change the entire grid on what it is drawn and your shape will follow it, that's one of the interesting pieces of flexibility in Processing, and something you can exploit in your own sketches.
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.