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.
The next primitive shape that we're going to work with in Processing is squares or more appropriately, rectangles, because just as with circles, Processing doesn't have a built-in function for squares, when it is as rectangles where you draw the same width and height, but let's take a look at this one, this function is pretty easy to deal with. The first thing I'm going to do, I'm going to create a comment with my file name then I'll set the size of the window, turn on anti-aliasing then I'll put a background, it'll be a sort of a light yellowish color.
I'm going to use the hex codes again and when I save that you can see there's our background. Now I'm going to start drawing some squares and the way I do this is with rect for rectangle and it draws it from the top left corner. So what I need to do is I need to set the coordinates for the top left, in this case I'll use 60 pixels over, 60 pixels down and then you specify the width and the height of the rectangle, I'll do it 80 and 80.
Now just so you know, there are choices for this, this is what called the rectMode, in fact, I can just type it out right here. This is rectMode CORNER, I want to just mention that that is the default, so I don't actually have to type it, but it means it places it by the top left corner and you specify the width and height. The other options are to specify the center point and the width and the height or to specify the coordinates for the top left corner and the bottom right corner and I'll show you both of those in just a moment. But right now I'm just going to draw this rectangle.
I hit Run and there's my basic rectangle with a white fill black border, and I actually like to make the boarder a little bit thicker, so I'm going to close that and I'm going to come back here and put in strokeWeight, all lowercase, except for the capital W, I need to do bumpy caps, because that's the way the functions worked in here and I'll make it 5 pixels. Now when I Save it and Run it, it's a little bit thicker that works a little better for me, so I'm going to close out. Now I'm going to draw two other rectangles. To show you that there are different ways to draw these, I'm going to use rectMode CENTER, and again, sometimes it's easier to position things by the center and makes it also consistent with what happens with circles and some of the other shapes.
Sometimes it's easier to position it by the top left; it depends on the situation you're working with. So, this time I do a rect and then I have to specify that I'm going 300 pixels over and I'm going to 100 pixels down. Now notice in the one before I was 60 pixels down with an 80 pixel box, so halfway through that will actually be a hundred. So you'll see that these two line up actually, and I'll make this one 80 pixels wide and 80 pixels tall and I'm also going to just a little variety, I'm going to turn off the outlines with noStroke and I'll put in a fill using the hex code CC5C54, it's a sort of a red.
I'll Save that and Run it and now you can see that there are aligned, even though I specified very different dimensions, because the first one is positioned by the top left corner, the second one positioned by it's center point, but you do a little math so you can get them to line up. Then I'm going to do one more to show you the third way of drawing a rectangle. This one is rectMode CORNERS, please note it has an S, it make it different from the CORNER above, because what I'm specify now is coordinates for two of the corners. Now I'll change this one to make it a look a little bit different, so I'll give it an outline, use my hex codes, it'll be a slightly lighter orangish color and I'm going to turn off the fill.
Then I'm going to position the rectangle. This time I go to the top left corner, so that's 460 and 60, so you can see they are parallel with the very first one I did. But now instead of specifying and the width and the height of the rectangle, I simply go to the coordinates for the bottom right corner in this case 540 and 140, 540 pixels over from the top left, and then 140 pixels down. I Save it and Run and now you see the sequence of three squares all drawn with the rectangle function and positioned in different ways, the left one using the default corner, which I give the coordinates for the top left coordinate, and then I give the width and height.
The middle one is using center, where I specify the X and Y coordinates for the center of the box, along with its width and height. And the one on the right positioned using CORNERS, where I simply give the X and Y coordinates for the top left corner and the bottom right corner, and that's it, for drawing rectangles and squares 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.