Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
In this next video, we're going to look at some of the ways that Processing allows you to modify the way that lines are drawn as well as circles and rectangles, with some pretty fundamental things like stroke weight, the ends of strokes and the way things are joined together as well as methods for placing rectangles in the circles. Let's start by drawing a few lines and show some functions that you may have already seen a few times. I'll start by putting the name of the file as a comment and them I'm going to put in a palette and I call it rainbow, I've used this one before.
And so it's an array of colors, I'm just going to put in FFFFCD, CC5C54, F69162, 85A562 and the last one is 7AB5DB. Okay, this is a palette I've used previously. All right.
Now what I'm going to do is I'm going to draw a window. I'll make it 600x200, and we'll just pull that up really quickly. It's got a gray background. So what I'm going to do is I'm going to adjust the background, to be the first color in the palette, and that one will just be rainbow, like that. Now, we've got our tan color back there. All right. The first thing I'm going to do is I'm going to explain something I've used in nearly every drawing that is the anti-aliasing. We have the opportunity to draw lines.
Let me draw a line for instance that goes from 50 pixels in divided by 2, over to 550 pixels and still the height divided by 2, we should make this a thicker line. So I'll just stroke 20 pixels. I'm also going to adjust to fill here, I'm sorry that should be strokeWeight because the stroke is going to be one of the colors, now I'm going to use rainbow, there we go. Now by default anti-aliasing is not turned on and the funny thing is it's really hard to tell that it's not going on except sometimes, it seems like a little fuzzy at the ends, where they are circular or they are diagonals.
This one is just a tiny bit fuzzy, and so what I'm going to do is what we've done in basically every other one, is I'm going to turn the anti-aliasing on that's the first attribute that we're looking at, do that with smooth and it's slightly sharper there you can tell. Now, if for some reason you ever wanted to turn anti-aliasing off, the complimentary function to this is noSmooth. And since, I have it coming second, the anti-aliasing will get turned on and then right back off and we have the slightly fuzzy ends again, a little easier to see this time, but I'm going to close that and I'm going to comment that one out, I don't want that anymore.
The next thing I'm going to show you is well, I've already showed you, it's the strokeWeight. You can change the thickness of these strokes by designating the number of pixels. This one is designated 20 pixels. You can make it as thick as you want. I can make it, let's make it just for fun, 180 pixels wide. So now it's really big. Now, the important thing to realize about this is how it positions the strokes and how it measures them. You may see here that the line doesn't start until it's 50 pixels in. On the other hand, the line that's drawn here goes off the screen at both ends.
What happens is, is at the round cap at the end is in addition to the length of the line, it's the lines coordinates in this case 50 and halfway down the height, determine the center of the round cap. Also, it determines the center of the line. So if you're trying to get things lined up, you need to understand that you're having the position of the line plus half of the thickness of the line on either side as a function to deal with. I'll get that back to a more reasonable value, 20 works and there's that one line.
In fact, right now I'm going to talk to you about how to do the stroke caps. You see how these are circular on the end. What you can do right here is the function is strokeCap and the default is ROUND and it has to be in all caps like that. But you have some other options. In fact, let me copy this and I'll paste it and show you some of the other options. So the first one will be ROUND, the second one will be SQUARE, and the third one will be PROJECT, looks like project, but it's project.
And then I'm going to put these things at different places on the lines, I'm going to make them all the same length. I'll just do this one at a height of .25, I can just copy that down here. That one can still be in the middle and this one, we'll do height times .75 and so they should be one above another, and there we go. And so the first one has the round endings, that's the default and you can see how it's longer than the one that simply as a square ending that stops, where the x is.
The bottom one project is kind of a funny one because what it is is it's still a square cap, but it's a square cap that goes the same distance that a round one would. So, if you need to have a square cap and a round cap, that are exactly the same length, you would need to use project. And understanding that both of them are actually, slightly longer than the designated line coordinates. So that's one attribute of lines that you can modify. Next thing I want to show you is about rectangles. So I'm going to take this information here, I'll just comment these lines out, and I'm going to come down and draw a few rectangles and this one I'm going to leave the strokes the same. What I am going to do though, is I'm going to turn off the fill and I'm going to draw a rectangle, I'll put it near the middle.
Actually I'll just go 100 pixels in, 50 pixels down, this will not be near, I know this would be near the left and I'll make it 100 pixels wide and 100 tall. And so there I have my rectangle, it's drawn in the same colors, it has no fill, it's got the same thickness of 20 pixels and again, what this means also, is that the actual coordinates for the rectangle are slightly to the inside of the line. The coordinates are running down the middle of the line. So when you are placing things on the edge, in fact, the easiest way to see that is if I move this right to the origin to 0, 0 and what you'll see there is that you only get half of it because the actual coordinates are running down the middle of the line and that's how it got placed on this one.
So when I run it back out to where it was before, I just hit Undo to get those back. There it is with its square corner. Now, one thing is you can change the way that their corners are drawn. This is actually, what's right here, the function I want to use here is called strokeJoin, it's for drawing corners and any shape that has corners. And the default which we've been using is a MITERED or a MITER edge, that's the default, but we have a few other choices. Let me copy this and I'll do to two others.
I'm going to comment this one out for a moment. The other one that we can do is a beveled edge and please note, again, Processing is case-sensitive so these things need to be written exactly this way. I'll comment out the second one, so now we can see what the rectangle looks like with our beveled edge. It's chopped off the way that you often do university varsity jacket letters and then the other choice, we can comment out the bevel and the third one is rounded corners, just do ROUND, I'll save it and run it and there you can see that one, it makes the same sense and again, what you can tell is that the center point for the radius is where the coordinates for the corners actually are.
And so what you you've seen here are some of the basic ways of drawing lines for individual lines and for shapes in Processing to give a little more variety to your drawings and some more visual interest.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 98575 Viewers
61 Video lessons · 85870 Viewers
71 Video lessons · 69760 Viewers
56 Video lessons · 102063 Viewers
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.
Your file was successfully uploaded.