Transcripts
1. Color & Texture Intro video: Hello everyone, My name is Hadeel and this is generative color and texture. When I first learned generative art, I was over the moon by the possibilities of procedural creations. But only when I started to push for out-of-the-box ideas is when I began developing a style. Whenever I learned new techniques, I go back to old sketches and implement them, figuring out how to amalgamate the two projects. This course will discuss how you can deliver depth and semi realism in your work with easy to implement texturing and coloring methods. I created eight different lessons on ways you can texturize and color your generative design. And one final projects showcasing the combination of multiple procedures in one final artwork. In four of the lessons, we'll examine four ways to add texture to your work, from resembling hand-drawn shapes to adding simple graphic drop-down shadows. And finally, not to discounted, a perfectly randomized color palette. But in this course, I'll show you four coloring techniques that will elevate your work to the next level, we'll create a complete artwork from scratch for each method, demonstrating how I thought of employing them and giving you application ideas. I think that's enough for an introduction. So let's get started.
2. Texture 01: Recreating circles: In the first two lessons for texture number one, I wanted to talk about recreating the primitive shapes are the native shapes in processing, like circles and rectangles, specifically circles and rectangles. So in this first lesson we'll talk about circles and then in the next lesson we'll talk about recreating rectangles. So for this one, we are going to create a new class, and that class is going to be the circle. So to start, we'll just do, we'll name it blob. Now in this class we'll define all the properties that we are going to need in order to create a circle using points. If you think about it, a circle has a center point and then it has a radius. And later, the points that are going to create the perimeter of the circle. So for the points that creates the perimeter, that is going to be an array of floats that are going to be positions of x and y. And then we also need the resolution for knowing the amount of points that we need to create that circle. For that, I'll just create an integer and I'm just going to call it Raz for resolution. And we also are going to need center x and center y for the center of the circle. And then we also said that we are going to need a radius. So let's not forget that. Okay, and to start, we'll create reservoir here. And I'm going to initialize those variables are those properties in the constructor. So I'll do and reds. And then I also want to define the central axis and Central why later. So I'm not going to find them in here. Center x is going to be equal to this center x, and then centralize the same. And now we'll initialize x and y. Those are going to be of length reds. Because x and y, I'm just going to be the positions and the amount of them is going to be the resolution of that circle. And for the radius, I'm going to start with random values. I'm going to stick with random values actually. Show for me it's going to be from 10 to 50 in there floats before I start creating or displaying the circle using the points x and y, I have to initialize the values for x and y. So I'm going to create an init function. And in this function are going to have a loop. And that of course is going to be less than the resolution. And then we're going to increment by one just normally. Now in here we're going to create the points. If you've visited my Instagram or YouTube, then you would have seen how you can create points around the circle. Or if you've taken my Polar Grid course. But generally we're going to create those points around the circle by rotating using cosine and sine. So we're going to use those functions to, to draw the points around the circle using the angles of the points inside of that circle. As we go through this, you'll be able to understand how this works. So for the first one is going to be accent I position. And for this we're going to use cosine the angle. And we'll create the angle in a bit. And then we're going to multiply it by the radius. We're basically creating points on triangles and then rotating based on the angle of those triangles and that will create the circle. That's why the resolution is important here. Because the higher the resolution, the more circular the blob is going to look, and the fewer those points are where, the smaller the resolution value, then you're going to start to see more of a hexagon shape or a diamond shape or even a triangle if you go down to three. And that is rotating with values from negative one to one because cosine of the angle, whatever angle that is is going to give me values from negative one to one. So I need to multiply it by the radius to push it out based on how big I want the circle to be. So right now, I want the circle to be a random, a random radius from 10 to 50. So the width or the diameter of this circle is going to be from 20 to a 100. And then for y, we are going to do sine. The angle. Multiplied by the radius. And then to push it to the center, we're going to have, because this is going to draw around the zero-zero point. So we're going to have to push it by center x and center y. So whatever I define those as, that's where the circle center is going to be at the end. And then the angle is going to be defined inside of the, inside of the for loop. And it's going to be I. So each point multiplied by the angle of each of those rectangles inside of the circle. So let's say I have six points for resolution. Then this loop is going to iterate six times, meaning that AI is going to be multiplied by 16 order for it to complete the 360 angle. But initially we don't know what the resolution is going to be, so we don't know what angle to put in here. So for the angle, I'm just going to call it slice. And then I'm going to calculate it up here. And I'm going to just call it slice and I'll define it up here. I'll just add it to the radius. So we don't have too many properties on top of each other. And over here I'm going to divide 360 by the resolution. 360 is the sum of angles in a circle and then dividing it by the resolution is going to give me the angle of each space that point is going to take. And then I have to convert this to radians because cosine and sine need radians to work. And now it's time for the fun part which is displaying and seeing that what we created work. Now in order to draw the circle, we're going to need to loop through the X and Y floats. So I'll go through the same process that we did in the init function. We're going to use co-vertices. The reason why I'm using curved vertices rather than vertices is because they are smoother. So curved vertex takes two values just like a vertex. And then I'm going to give it x and y and I as well. What do you need to know about the current vertex function is that it needs for current vertex functions in order to appear, because the first one is going to be the control point for the first, and then the second is going to be the first of the curve. The third is going to be the second of the curve. And then the last point, which is the fourth, is going to be the second control point. So basically a Bezier curve, but it's created using a curved vertex function, so each point is drawn separately. Now this one is going to take care of part of her curve vertices, control points and the points. But if I display this, we're not going to have a complete circle. We have to see this first before we can solve the issue. So if I go over here and create a blob and then initialize an object. We are going to need a resolution. So I'll just do six because that's the easiest for us to calculate. And then I'll do width divided by two for the center and height divided by 2 for central y. Instead of calling two methods out here, I'm going to call a net in here. Just so every time we initialize an object, it's initialized already. And then I'll just display this one over here. And we need to begin shape and that shape for any vertex basically. And we put it outside of the for loop because we want to begin the shape and then draw all the vertices that we need and then end the shapes. So these are all going to be connected because if you put Begin shape inside of here, inside of the for loop and entry as well. Then every time it's going to begin a new shape for every iteration. Okay, So I'll start with a radius of a 100. I'm not going to start with random, so you can see it clearly. So you can see that we only have 1234 points drawn. We have two more to draw. So five is over here, and six is over here. Or actually it's 1, 2, 3, 4, 5, and finally 6. So let's drop points. So we are able to see it. I'm going to draw it using circles and it's going to be at the same position. And then I'll give it a width of 20. So you can see it clearly. And let's actually remove the fill. How this is working and why we don't have all of the curves is because the for-loop has taking care of the first control point for the first curve. So point number 0 acted as the first control point. And then this one is going to be the first in the curve. And then this is going to be the second in the curve, and this is going to be its control point. Now looking at the second, this is going to be a control point for this starting, for this starting curve. And then this is the end of the curve and this is its control points. And we're going to go round and round. So if you go to this part, then there is no curve over here because this acted as the control point and this is the last point. What we need to do now to fix this as add three more points. So the first one is going to be before the loop. And that is going to be the last point. So resolution minus 1. And then for y also the last point. And now if I run this, you can see that we have a control point for this curve now, which is this part. And because it's drawn before the first one, now it understands that this is also a curve and we need another one after. That is going to be exit 0 and y at 0. Because after this last point, I need this to exist for this curve to be drawn. So now this is a control point for this curve. And now I have one final curve to draw, which is this one. So whereas the control point for this, it's going to be this. So this is number one. And if I draw this curve vertex at x, or not necessarily number one, but at position 1 in the array. Now if I run this, it's complete. So I'm going to stick, let's say with aids because that's nice. Circle it doesn't, you don't see much of the points anymore. Now this is a good point for us to animate this. One of the reasons why I wanted to recreate a circle in the first place is to have a little bit of variation. And to do that, it's extremely simple. All you have to do is just create an update method inside of your class and then create a variable. You can call it whatever. But this is going to be our offset. And we're going to also loop. And we are going into each of the points to move it. So for the first one, it's going to be x at position I plus equal a random value from minus offset to offset. And the same goes for y. So we're incrementing whatever these are by a random value. So it's going to move until it starts to distort the circle. And I felt go over here and I do, well, I have to move it to the draw function. Now I can start seeing it moving. So we first have to reset the background. So it doesn't draw. And you can increase this up to whatever value you want for the offsets. The higher it is, the faster it's going to be distorted it and you won't go back to the circle. So low value like 0.5 is going to keep that circle shape for a long time, but still allow us to have variations in the perimeter of the circle. And you can also not animated, but simply offset the values over here or when you initialize it. No, For this example, this first section is all about creating or recreating the circle. But for the second part, when I talked about actually creating the example, we're going to talk a little bit more about collision detection. So gluten detection is very easy to understand. It's simply, especially for circles. It's simply finding the distance between the center of two adjacent or circles in the same space. And seeing if that distance between the two centers is less than the sum of the two radii eyes. So if there are less than the sum of the two radii, that means they're intersecting, which means they're colliding. So we want to prevent that. The way you can check if two circles are intersecting is. Using the dist function, which basically gets the distance between two points. So let's actually create that over here. I'll create a method inside of our blob class called collide. And that method is going to take because it's checking the distance between itself and another object of the same class, then we need to pass in a blob as well. So this is a cool thing that you can do inside of classes where you can let the object of the current class that you're using to interact with another class or an object from another class. But here we only need it to interact with itself or with objects from the same class. So we don't need to create multiple classes of this because we already have the class itself. And the way we can use this is like so. So if I do float and I will call it d, this is going to take the center x and center y of this one right now. So we can just call it CX and CY. And then it's going to check the distance of this circle. So the x and y of this circle two and x and y of the other circle which we are passing over here. So we can just do other dot c, dx, and we can grab whatever this object has of properties. So we can do dot cx and then other dot see Y. And then if d is less than the sum of the two radii, that means the radius that we have right now, which is R plus other dot r. And then if that happens, then I'm going to return true. That means colliding. So what I need to change over here is the return value because now it's not returning nothing, it's actually returning a Boolean value. And then otherwise, or if this doesn't check out than I needed to return false. And we don't need an else statement over here because return kind of gets out of the function. It returns the function. You won't reach this part anymore. And now if I go over here, I'll remove the blob that I created, and then I will make this into an ArrayList. And I'll share with you why I'm creating an ArrayList instead of an array. So I'm going to call it blobs. I'll initialize it over here. So I'll just do new ArrayList of type blob. And now down here. And this is why I'm using ArrayLists. I can just add blobs without knowing how many I need. So I can just do blogs, dot, add, new blob. And I'm going to make it a resolution six for now. And then I'll have it at random width and random height for center x and center y. And now to display each bond is going to do four in. So for blob, blob, blobs, That's a lot of blogs and display it. So now it's going to just add them because we haven't detected collision yet. To detect collision, we can simply use a for loop to loop through all of the existing blogs against the new added one. How I can do this is by creating a normal loop that goes from 02 blobs size minus one because I don't want to reach the last one. The last one is what? I'm going to check against the other ones in the array. And then I'm going to increment. And in here I will say, I will create the index for the last block that were created inside of that array. So that's going to be blobs dot size negative one. So this is going to go less than this last one. And this is going to be the last one. And now I'm going to check for the blog at position j against each other block. So Bob's dot cat eye. So if the blob at position j, which is the last one added, is colliding with any of the ones that are existing in the array right now that are not the last one, of course, then I need you to remove that blob. Now, each time this is adding a blob, it's going to check if it collides with any of the existing one and then it's going to remove it so it doesn't exist anymore. And then it's going to loop and do that over and over again. And now you can see that nothing actually collides. If I now return to the class and change this to random from 10 to 50. And that's why I use smaller number because they have a very small screen. And now we have a bunch of circles that do not collide. If I remove this, which are the guides, then I can see that they don't collide. The only time that they're going to collide as when they are distorting. We can reduce the speed for that because now they're smaller, so it's more apparent. So you can just reduce the speed and now you don't see them move as much. Now you can just color them randomly. I'm going to grab a bunch of colors that I have. He can choose whatever colors you want. And I also chose a color for the background. So I'm going to use that over here. And over here. If you're resetting by the way over here, you don't need this one. The only reason why I use it over here is because every time this is R1, you can glimpse the background that is in here. So if you have a black background, then you can glimpse it in the beginning. It doesn't matter, but if you're saving every frame, then you're going to see it. And then I have my colors over here. I can simply define color over here, and then color all of designs randomly from the coals array. And then the index is going to be a random one from 0 to colors dot length. And the reason why I'm going up two colors that length is because I'm going to cast it into an integer since we can't have float for indices. And then this is going to floor it. So whatever this number is, it's going to be minus one. And now I'll go over here and the display method, I will do fill color and you'll see the random colors. You can also remove the stroke if you want, or you can make the stroke white. They will also give it a different look. In the next lesson, we'll talk about recreating. Rectangles are one of the ways you can recreate rectangles.
3. Texture 01: Recreating squares: In this lesson, we're going to create a bunch of rectangles using what looks like hand-drawn lines. Instead of using the native function in processing to start understanding how the lines of the rectangles are created. Then we're going to need to start with those lines. First. I'm going to create just a normal function. And here before we create any class for that new object, and I'm going to call it wave. This as well as guarantee use a curved vertex in order to create that flowing movement. Because vertices tend to be very Angular and we'll also need a for-loop because we're going to draw, because co-vertices are basically points and we're going to need multiple points to draw a line. So instead of using the line function, we are using points to draw the line that we are going to use to draw rectangles. For that, we'll also need to have a resolution and will also need to have an x and y position. So now if I call wave over here, I can just use a resolution of six, let's say. And then I can start it at 0 for x and then for y it's going to be at height divided by two, so at the center, vertically. And actually let's start the resolution over here because we're going to use it multiple times as well. And then a wave will also need a width or a line of points is also going to need a width. So I'm going to create a width up here, or a value for width. And then later when we go vertically, we're going to go with height as well. But for now we're only going to draw a line horizontally on the screen so we can see how this is actually working. So I will just define with a v here. So let's make it the width of the screen. And then we're also going to need a gap. The reason why we're going to need the gap, because we have points, but we need to know how far part they're going to be in order to draw the line along the width though we request. So first, draw from 0.02 width, we're going to need to know how much the spacing is going to be between each of the points and that we can find by. So if I just define gap that we're going to find by dividing the width by the resolution. So whatever the width is, if I divide it by the number of points that I have, then I get the amount of gaps to space the points. Basically like drawing a grid. So when you draw grid, you want to know how much the width of each cell is going to be. In order to know how much movement you're going to need to go to the right or downward in order to create those cells in the grid. So we're doing the same thing, but we're going to do it with just a line. So beginning shape and then end shape because we're using curved vertices. And then I'm going to do a loop. And then here it's going to be curved vertex at exactly what we do with grids. So I'll do, I multiply it by the gap, which is usually the cell width. So exactly like a cell in a grid or how you would draw grids. But we need to add x to it because x is not always going to be at 0 like a grid, we're going to move it across the screen. So exactly like we did with Cx and CY for the circle. But this time it's going to be on a line. And then here it's going to be only why? Because we're only moving it on the horizontal line. Now if I draw it, I have the line. But as you notice, it's exactly like what we did with circles. This one is missing a control points and therefore it's not drawing the curve vertex over here. So in order to draw it from the zero-point, I'm going to have to add a current vertex before it to act as its control point. And that is going to be a gap plus x. We don't need to multiply by I because it's going to be the first one. And then for Y, we're just gonna do a y for now. So now we have a point starting over here. And for us to see it will also draw a circle like we did before. And I'm going to put it at the same position. And then I'll make it 10. So you see the points. We see that we have coins everywhere we need it. And then for us to draw the last point as well. Because we only have the gaps. And in a grid usually you're only drawing from corner and then the rectangle or the cell is going to draw us have this last one is going to dry as well. But here we don't have a rectangle, we just need points. So I'm going to also say I is less or equal, raise. Way, I'm going to have a point at the end as well. And then to draw the one at the end that I'm just going to say current vertex at Rey's, which is the last one multiplied by the gap. And then this is going to be y. And now we have this as well. Oh, and don't forget to add the x because right now we're just drawing from 0, so it doesn't matter, but later it's going to matter. So now if I adjust the width, so let's make it a 100 and run this. Then we can see that it's over here. And if I change the x position to width divided by two, now, we can see that it's moving because now we've added x to each one of those. So we're making sure that everything is moving with the X that we need it. So it's in addition to where the axis, this is going to happen. And now it's, you make it more interesting. And to make the wave shape we're going to meet at random offset each of these points. I'll just do it for the y for now. And that is going to be a random value. I'll call it V offset. Actually it's changed it to Y offset. And then in here I'm going to do load twice offset, and let's give it a value of four. So random is gonna go from 0 to any value to four. And I wouldn't recommend copying and pasting, but I will copy and paste, make this video shorter. And actually some of the circles, we don't need them anymore. Now, every time I run this, you'll see that it looks more like a wave. So let's actually make this bigger. Let's make it a width, and let's start it from 0 so you can see it clearer. And because we only have a resolution of six, the points are spaced out too much. So if I make this, let's say 16, just by adding one, we can see it more curvy. And then if I increase the offset to let say 10, and you can see more curves in our line. Now we can use this line to create our rectangles. And that way it's going to look more hand-drawn, but with an offset of tenants too much. So I'm going to reduce it to four. And then I'll also reduce the resolution to something like six because the more spaced out, the more resembles a hand-drawn feel. Because whenever you're drawing it, it doesn't make sense that we're all very shaky and we're drawing with the Tumaini offsets. But generally the way we draw is by doing a fluid movement. So it doesn't always look very shaky like before. Now in order to create a rectangle, I'm going to instead of having just width, to have width and height. And then I'll also have x gap. And why gap. And for this one is going to be x gap. And then for the other one's going to be h divided by Rey's, which is height divided by race. And then the heights, I'm going to make it height divided by two. And for width I'm going to make it also with divided by two so we can see it because if I do the whole screen, then you're going to see just part of the line. And now we'll fix this function by adding the gaps over here. X gap and then why gap. And then finally we're going to have x offset and y offset. You can have the same offset for all of them, but I'm going to have them different because then you can play with them later. And also you can just to clean it up. And so you can see all of the parameters. You can just hit Enter. And then if you do Command T, then it format it for you. So now it has the same indentation as the other one. And now we can fix this to make it x cap for all of these. And then instead of just y, y gap plus y, and in here as well, It's going to be I multiplied by y plus y. And the same goes for this one, but this one is going to be eras, multiply it by y gap plus y. And then we can add the offset, each one of those. So I'll just do plus random X offset. And here plus random Y offset. You can also do the same thing over here. And last one. Now I know we've created the same for x and y. So we are moving kind of diagonal you're at now. But we're not going to use this wave function horizontally and vertically at the same time. We're going to use it for some vertical lines and horizontal lines separately, but we're using the same function. You can definitely do a horizontal line and then a separate function for a vertical line. But you're going to see that it's very similar every time. But this way you're only creating one function and then you're using it for both vertical and horizontal line. And the way you can do this is like so. So let's say I'm trying deaths from the zero-point. And then for this one as well, I'm drying it. So from 00 basically, that's x and y. And then the resolution is going to stay the same. And then for the first one, which is x gap, we're going to use x cap and y gap. And then finally a value for each offset. So I'm going to keep it up for. And now this is the trick. So for now, this is what we have. And if I do this, it's going to be a diagonal line, like a sack because we're using x and y together. So how you can create just a horizontal line or a vertical line is by creating the position of the first in this line. So that's x and y. And then for x cap and y gap, you're only going to use one of them. So for why gap, it's going to be 0 because I don't have anything to divide. And then for the X offset, because we're drawing it horizontally, we don't need an offset for x, we need an offset for y. And now if I draw this, it's going to be aligned at 000. So if I move this the height divided by two. So at the center of the screen, then we can see that it's working to make sure that it works for vertical lines as well. I'm going to copy this and I'm going to leave this as 0. But use wide gap. And then the offset for the x, it's going to be four. And the offset for y is going to be 0. And that's the line over here. So I have to move it to width divided by two so you can see it. And that's the vertical line. So we know that this works for vertical lines and horizontal lines. Now it's time to create our class, to create the rectangle. I'll create a new tab, and I'll just simply call it poly. So for polygon, you can call it whatever. I'm not going to specify this as a rectangle, but feel free to do so. And now you can either define the polygon using only the resolution and then specify the width and height randomly. Or you can use XY, width and height with a resolution. So basically creating a rectangle, I'm going to make both constructors. So the first one is going to be the random one just so we can see how it works. So I'm going to do resolution over here. And of course it has to be visible over here as well. It has to be defined up there as well. Now Raz is going to equal underscore rest for x. We're going to go from 02 widths randomly. And then for y it's going to be random height. And those are going to be defined up here as well. And also define width and height. So these are the properties for any rectangle basically. And width and height are going to be, because I wanted them to be squares for now because I think squares are easier to work with. And then rectangles are simply a different height from the width. I'll do from 20 to a 100. And then for height, I'm going to make it equal to width. After that, I'm going to pull this whole thing to this class. Now we have it over here and then Command T or control T on Windows to format there, just to clean it up. And then ended display method. We're going to create a rectangle as reference. So I'll make this rectangle x at x and y, and then width and height. And then I'll create those rectangles. So I'll grab those. And then I'll define the x gap over here. And why gap as well. And finally, the offset is going to be at four. Now we don't need these anymore. Neither do we need those for now. And instead of using these values, I'm going to use x and y. So for the first one is going to be wherever x and y is. So that's the corner of any rectangle. And this is our reference over here. So X and Y is going to be the corner, then that's where we're going to start. And this is the horizontal one and then it's going to be x gap. And then there are no, No why gaps over here, because this is a horizontal line. And then we don't need an offset for x because. We only need to offset it on the y-axis. And then for this one, we are going to draw the vertical line on the right. So what we are going to do is add the width to x. That's basically going to push it by the width diverse square or rectangle. And then we're going to have 0 for x gap. And then why gap? Again, for every horizontal line, There's going to be an x cap and a Y offset. For every, for every vertical line there, there's going to be a wide gap and an X offset. So offset is going to be for the x and then y is going to be 0. Now for the bottom one, it's going to be at position x because we are going to start it from the same point as the one on top. And then we are going to add the height to y because we're over here and we need to go down here. This will have an x cap because it's a horizontal line. And then it's going to have a y offset. And for the last one's going to have x and y because we're starting from the same beginning corner. Because for the vertical lines we're going from up to down. And then it's going to have no offset or no gap for x and then a wide gap and then Offset and 0. Okay, The Paul polygon over here. And Paul II is going to equal a new polygon or a poly class. And then we'll do the resolution. So I'll simply start with, let's do five. And then we'll draw it at margin, margin. And I'll do this right here. So I'll just create a margin so you can see it. Because if I just do 000, then it's going to be hidden on the sides sometimes. So for it to be clearer, for us to see it, then I'll just do a margin of 50 or even 20 is fine. And then I'll do with minus the margin. So we have the margin on the right side as well. And then the same for height. Oh, I forgot that. I didn't create this constructor yet, so we're just going to do this, the random one. So it will only define the resolution. And then I will draw. I'll display this over here. What you're seeing underneath it is the reference or rectangle, so you can see that it's following it perfectly. Now if I remove this part, then we can see our rectangle. And the smaller it is, the more distorted it's going to look because the resolution is fixed for all of them. So if you just reduce the resolution, then it's going to be more like a hand-drawn look. This is going to work fine. If I have an ArrayList, let's say, of polygons. And then I will add a new list. I have to create a loop. So for, let's say 10, then this is going to work fine. It's, it's not important to know the exact X and Y position or the width and height. However, if I want to create something like this, then I'm going to need to know specifically where the x and y is going to be or if I want to create a grid using those rectangles that I'm going to have to be more specific with setting the x and y and width and height for each of the rectangles. So I'm going to create another constructor, and this time I'll just copy and paste this. And I'll add the x value. And then I'll also add y, width and finally height. So we have the basic properties for our rectangle to be drawn. And now I'm going to change all of these to have width and XOM underscore y. And I'm going to change this to height so it can later define it when we want to create it. And if I go over here and I, let's say I want to create a thread or a line. Rectangles. Then I can just do i multiplied by the width divided by 10. And then we'll do height divided by two for the position of their height. Or if the y position. And then all do width divided by 10. And this one as well as going to be width divided by 10, which is the height of each of the rectangles, which makes them square. And now you have a line of rectangles. Also note that this is being drawn from the corner. So if you need to push it upwards so the height is perfectly in the center. You're going to need subtract the width divided by 10, divided by 2. And that is going to be exactly in the center. Because with divided by 10 is the width and height of these rectangles. And dividing that by 2 is going to just push this corner up by half of the height, which makes the central point now goes across the center of these rectangles. The other half of the lesson you can create by using the recursions course. You don't have to take that course because I'm going to try and explain this as well as I can in a short amount of time. But of course it's a little absurd to take that whole course and dial it down into just this lesson and expect you to understand everything if you don't have an understanding of what recursions are. Also the other parts of some of the lessons are just going to be examples to show you how you can use what we are creating for texture. In other examples that we've created either before or just in your general work. So you can use this using the intro to generative art course. Meaning you can use it to create a grid of these kind of rectangles. Or you can do what I'm going to do right now to substituting what we used as rectangles or the primitive rectangles that we used in the recursive functions course with this rectangle that we just created to add texture to that. So recursive functions in a nutshell is repeating the same code over and over again using nested functions. So instead of using loops, we're just going to call the function inside of itself, which can produce an infinite loop. But if you control it with a condition, then you're fine and you can create really great results with it. We're going to do the simplest example out of the ones in the recursive functions class, and that is the squares example. So what I'm going to do here is remove what I created over here and remove the display method, will just put it in the drawer so it makes more sense that we're drying inside of display. But then I'm going to just call no loop every year. To do this very quickly. What we are going to need is a method that you can call whatever, but we're going to call it generate because it's going to generate new generation every time. And then we are going to give it a number. And that number is going to be the number of generations. And then inside of it, we're going to have an ArrayList that I'm going to call temp for temporary. And then this ArrayList is going to have the polygons that is going to be the next generation. And they're going to be of type Holly or our class that we created. And then because I said that we are going to call the function inside of itself to create that infinite loop. We're just going call it in here. And then I'm going to passing degeneration because we are also going to decrement the generation every time. And then I'm going to do, or I'm getting to ask this function to only do whatever I'm asking it to do inside of this condition if the generation is greater than one. Because I want to avoid the infinite loop. So it's kind of similar to a while loop in a way because a while loop has all of the or has theme variable up here or before it. And then there is a condition, and then there is an increment inside of that loop. And our loop is this whole function. So we're going to put it out here. And we're going to decrement every time. So if I put here five generations, then it's going to do this for the first one. It's going to check if it's greater than 15 is greater than one. That is going to decrement after everything is done in here. And then it's going to be four. And once it reaches one, then it will check if it's greater than one, it's not. So it's going to stop. And now inside of this, we're going to loop through all of the polygons that are inside of her ArrayList. At the moment, we don't have anything, so let's add one to that. Let's give it a resolution. So I'm getting to call, call it Polya resin, call it over here or a defined it over here. And let's make it just three. And then I'll draw a big rectangle from margin, margin to what? Minus margin and height minus margin. Our forgot to add new MyClass. Now we have one of our rectangles and because we're displaying it over here, if I hit run, then we have that. Also. I'm going to have to multiply this by two because I'm pushing this by the margin, and then I'm pushing this by the margin, but it's up here, so I need to push it by margin multiplied by two. And now we have a rectangle or a square. So what I'm doing over here is looping through. So I'll just do Paulie, Paulie in Holly's. I'm going through all of the items in the ArrayList, and I'm going to divide them over here. So now we only have one. We're going to divide it over here. And then later I'm going to do whatever pollicis make it whatever is in temp, because we're going to create everything inside of the temporary ArrayList. And then I'm going to take everything inside of tmp and change or overwrite whatever is in polys. So now we have a new generation and the Pauli's ArrayList. And later we're going to loop through all of those and then divide them again. So it's going to be a loop of division. And the way you can do this is by firstly just do add it to the temporary array, but you are going to add a new polygon. And the new polygon is going to be a fraction of the size of the original polygon from the first generation that we're grabbing. So for that, it's going to be poly eras. And then we're going to, actually, I'm going to change this to just p because this is going to be very, very long. So I'm going to grab the exposition because for the first one I want it to be at the same x and y position. And I'm going to also grab the y position. But then I want to have the width and then height. I'll divide that by two. And then I'm going to call generate inside of the setup. And I'll do it just to, so I'll give it two generations. Okay, So I made a mistake, which is putting this outside of the if conditional, but I said it's like a while loop and the while loop decrements inside of the conditional. So now if I run it, we have that. Now you don't have the first-generation, you only have the second one. If I do this three times, then you'll see that it's not only a quarter of the size of the bigger one, but also of the smaller one. So I'll go back to two and let's create the other four. Because we want to make each of the squares into four different squares. Now for the second one, we are moving by width divided by two of the original one because we're looping through whatever is there in the beginning. It's referring to one over here. So you can see those and we can understand what's happening. So he started the first one over here and then we went only halfway to the width and halfway to the height. So that's only 1 fourth of the original square. And then for the second one it's going to start from here. So half of the width. So I'm going to do whatever x is plus width divided by two. So p dot width divided by two, the rest is going to stay the same. So if I do two generations, then you'll see that it's working nicely. I'll also do no fill. So you can see the lines. And now for the third one, I won't move the width or I won't move horizontally, but I'll move vertically. So that will be y plus the height divided by two. And then the final one is going to push both the width and height. Now we have four. So if I make this three generations, then you'll see that it's cutting that in half. And then if I do four generations, then it's cutting or cutting them to one-quarter of the original square, and so on and so forth. But to make this a little bit more interesting, what you need to do is just not cut every square. So if I do float, rehear just a random value from 0 to one, and then I check if r, So I give it a probability of 50 percent for it to be divided. And then the other 50 percent, the squares going to stay the same. So it's going to stay at P dot SPDY as going to have the full width and full height. So now you can see that it's more interesting because this part was divided for all of the generations. This one was only divide it twice. So one was divided only once. You can run it as many times as you like and you'll always get different results. You can also change the probability over here from 50 percent for each do something different. So let's say you want the majority to be cut, then you'll do 70% for this to be cut. So if r is less than 0.7, then you'll see that more of them will be cut. And if you want to color this, then you can simply add an array of colors to this. So we can just fill this with color because the lines were not actually drawing a rectangle. We're just trying a bunch of lines so you can just draw rectangles and those are going to be colored. You can also add margins to these. So if I do x minus 2 or x plus two actually. So if I come up here and I do plus two for those and then minus 2 for those. So as if I added the margin of two and then I added an extra margin for the one. So if I do this right now you can see there's a little bit of space. And then I can add another margin or extra margin just for the inner rectangles. You can see it a little bit more clearer and you can remove the stroke from this one. Because now we're seeing double the stroke. So you can just do no stroke over here and then stroke of black for this one. And we've got a new made-up rectangle used and recursive functions. That's pretty much all you need to know about this part of texture one. In the next lesson, we'll talk more about color, specifically random color interpolation.
4. Color 01: Random color interpolation: In this lesson, we'll start talking about color, specifically color interpolation. I talked about this in another course. But I wanted to share it here just so we have an accumulation of ways to color your design. So color interpolation basically creates a gradient from one color of your choosing to another color based on your mapping of value. So based on the time, which is the third argument for this function or for this method lip color. However, today we're not going to map the time or the value of the third argument to anything on the screen. We're just going to use randomness to play around with the colors that this method creates. For this lesson will delve directly into the example, because it's not going to be a very difficult example. And we're going to use some of the techniques that we used in the previous examples. So I'll create a new tab because we're going to create an agent class. For this agent Tom going to display arcs and circles and lines. So for that we're going to need an x and y position and a radius. And then we'll definitely use color. So I'm going to create three colors. One, I'll just call call, and the other two, I'm going to call one and culture for the first color and the gradient and the second color. Now inside the constructor, we're going to initialize our x and y and the radius. So x is going to be a random value. And let's do it from margin to width minus margin. And I'll define margin. Right here. Y is going to be the same thing, but with height. This way we have space around the screen. So nothing is crammed to the borders. And then r is going to be just a random value from, let's say, 3200. And now for colors, Let's start with black and white first. That's how I like to start. Whenever a design something new, I'll make the first color, white soldiers to color. And then 255 for white. And then two is going to be black. And now we'll define the color interpolation method. So the method is called Blurb color. And then it takes the first color, the second color, and I takes the time value. So if you want to map this from 0 to the width of the screen, then the colors will change from that point to the other point based on what shapes yet. Therefore, if all of your shapes are crammed to the right side of the screen, then they're going to have the second color. Because this value goes from 0 to 10 is going to be the first color and one is going to be this. And then any numbers in between are going to be whatever colors are in between 255, which is white and 0 which is black. But here I'm going to just say, I want a random value from 0 to one. And that's going to do the trick for us. And now let's display something. Let's start with a circle. And I'm gonna give it x and y. And then the radius. Also, I do use radius and circles even though this is considered the diameter. So even though I am initializing a radius over here, I still use it here as the diameter. So you can also do multiplied by two, but I'm going to just keep it like this. And then the color. So the fill of it is going to be whatever we defined with the color interpolation method. Now let's go back over here and let's define an array of Adrian's or an ArrayList of agents. And then I'm going to go over here. And I'll do agents dot add a new agent. And then I'll go. All of them. So for agent, we'll call it agent agents. And then I'll display that. So as you can see, we're getting a fill that is random from 0 to 255. This is similar to choosing a random color from black to white or from 0 to 255 when you're doing it over here. So saying random from 0 to 255, and we don't need to do the 0. It's the same thing. The only difference is that it's going to flash because we added the fill over here. So if I do it over here, and we're going to have to convert it into an integer because colors actually an integer. And that's the same thing. However, if I'm going to choose different colors from white and black, we're going to get a very different result. So let's define an array of colors. I have one that I'm going to just define up here. And now instead of getting or instead of defining the colors manually, we can just get a random value from the array. So we have a bunch of colors over here that I can choose from. And we'll do this the same way we did the random coloring before. So we're getting a random index for the array. And we have to cast it into an integer because indices cannot be floats. So I can do calls dot length. And now because of this, it's going to be an integer and it's going to work. Now the same goes for the other one. You can also use two different rays for these. Or you can choose manually whatever colors you want. But I'm going to keep it random. And then over here it's going to stay the same. And the fill is going to take this color interpolator. Now if I run this, we'll start to see more colors. Now some of these colors like this movie color or this dark green color are not in my array, but because we're getting one color and interpolating it work creating a gradient from that color to the second color. It's grabbing whatever is in the middle between those colors. So let's say I'm going from pink to blue, then I'm definitely going to get more movie colors. So this and this one is definitely something that goes from pink to orange or yellow. And this way of colorants repletion changes based on your color mode. So if we change the color mode to something like HSB, let's say. And then I run this, we're going to get a different array of colors. The reason for this is because it just speed goes around the color wheel. So in between the two colors is not necessarily what you would consider the accumulation of those two colors. So before with RGB, if I take red and blue, then I'm going to get purples in between them. However, with HSB mode, we're going to go through the color wheel. The only purpose of this technique is to show you that you can use the random method to, with the color interpolation method to get an array of colors from just five colors, which gives it a little bit more interest than the normal array of colors that you choose. So I'm gonna go back to, and you can see the mood changes even when I change it from one mode to another. Okay, now instead of doing it this way, Let's actually continue the example, which is not necessarily important for, for you to learn this lesson, but I wanted this to be a full example showing you how I use color interpolation or how I would potentially use color interpolation in my designs. So one thing I did with this example is get a random value. I'll just call it random because they already have R as the radius. And then I'm going to initialize it over here. And because it's an integer, I'm going to cast random into an integer. And I want five different shapes. So I'm going to just use five. So I'm going to get 0 to four. And now down here in the display method, instead of using just the circle, I'm going to check if random. Equals 0. And I want another shape. And then else, if random equals 1 or random equals 4. So it's actually not five shapes, but I would consider five shapes just because I want the probability of getting a circle to be higher. And I chose whether it's one or four, f equals two, and then three. So a friend m equals 0, I'm going to create an arc. And it's going to be an x and y. Actually it's instead of x and y because later I'm going to also move it. I'm going to push. The styles are adds a push and pop method. To use translate and rotate. Translate is going to define the position of each of these shapes are now we can just use 00 for each of these positions. And then art takes the X and Y position first, and then it takes the diameter, width, and height. So I'm going to just use the radius like I did with the circle for both because I want it to be a circle. I don't want it to be an ellipse. And then I'm going to go from 0 to pi because those last arguments are the start angle and the final angular or where the angle will end. So imagining a circle having two lines perpendicular to each other crossing in the center of the circle. So imagine the east side to be this point, the starting angle. So it always starts from there. So I'm going to go from 0 to Pi, meaning half of that circle. So here we're drawing half a circle. And then over here, I'm going to do the same for the beginning. And then for the second, I'm going to go from 0. This time I'm going to draw three quarter of the circle. So that is going to be pi which is half, and then half Pi which is quarter of the circle. And that way we have three quarters. Finally, I'm going to draw a line. And this line, I want it to go from some kind of like drawing the horizontal line on a circle. So I'm going to go from radius divided by two because I'm acting as if this is the diameter, which I should just call diameter over here, but it's just a habit Rhino. So r divided by two and r divided by two. And that's all we need for this. So if I go right now and run this, we're going to see that we have a multitude of shapes. So we have three-quarters a circle, we have half circles, we have full circles and we have those lines for the lines actually for everything. I don't want a fill. I'm just going to use a stroke instead because I want a different visual. And let's make the stroke weight a big one, so 15. And then I'm also going to make the stroke cap into square. Because for the lines they're going to have round caps. I want to change them to square. It's not important of course. And then I'll also do no fill. And because we have lots of styles over here, we can do style. And I can just remove all of this from here in period over here. And we can even color inside of the push and pop methods. So I can just do style right here. And now if I run this, we're going to have a nicer design actually. But another thing that I'm going to add to this that is going to make it fun is an animation. However, we cannot do that animation because we're not going to be able to see it until I do the collision detection that we did previously. I will show you first the animation. I'll show you how that is not going to look good. For any animation. We're going to need an angle and the speed. So that's going to be angle. And then I'll just call it a speed for angle speed. And then I'll define them over here. So it's going to be angle. And the reason why I'm defining it over here, because I don't want them to all start from the same angle. I want to have a random rotation for each one of them. So I'm going to do random 2 pi. So that is going to give me a random value from 0 to two pi. So full circle basically. And then a speed. Is also going to be a random value that is going to be from minus 0.52.5. And now over here in the rotation or the translation section, I'm going to also rotated or that transform section going to rotate it by angle and then angle is going to move or is going to update and the update method is going to update by the speed. And now we just call update over here. Now all of the methods we're using display an update, and then the style we're using inside of this. By now if I run this, everything is rotating and I have to reset this. So do thank round. Now I can actually see them rotating and not and drawing on top of each other as in whatever is rotating is not drying instead of just resetting and rotating. To me, this is so cool. It looks like a machine working, but I think it looks nicer if we add the collision detection. So we'll do that using the collides method. As we said before, it's going to return a Boolean as gang to take an agent and I'm going to call other. And then we're going to grab the distance from x and y to other other dot y, meaning the center to the center. And then I'll say if the distance is less than the radius plus the other radius, actually it's going to have to be divided by two because we're using radius over here as a diameter. So this is when things start to kind of become messy because of me choosing the wrong variable, return true and then otherwise, or whatever happens, just do false. This ensures that we're returning a value regardless whether this if conditional is mapped or not. And then I'll go over here and I'll define a maximum value. Up here. I'll just do MAX count. And let's do 50. Although for the screen size 50 is going to be a little bit much. So let's do, yeah, let's reduce it to 20. The reason why I added the maximum count is because I don't want it to add or exceed that maximum amount. I don't want it to add more than 20 circles, let's say, or shapes. So I'll say agents dot size is less than maximum count only then I want you to add a new agent. So if it reaches that amount, the maximum count, I don't want it to add agents anymore. And then we'll do a for-loop. For integer I equals 0, I is less than agents dot size because we're using ArrayLists, not an array, so we don't use length. And then I plus, plus. So we're incrementing by one like usual. And then here I will define j as the last agent. Actually, what I'm gonna do over here is loop only through the agent that size except for the last one, because last one is going to be j. So if agents at position j collides with agents or any agent at position i, then I'm going to remove it. And this is where the max count comes in handy because if all of them collide, then we're not going to have anything in here. So it's not just to ensure that we don't exceed the maximum count, whether it's also to make sure that we are reaching that maximum count. We're not just getting too because most of them collided and then we had to remove them. And now if I run this, we'll see that they don't collide. Actually the reason why they're colliding is because of the stroke weight. So we can add that here. I can just say plus the stroke weight if I define it somewhere else. So let's say this. I'm going to just call stroke w. And then here I'll just say stroke w equals 15. And we have to define it up here as well. And now I can add it over here. We can just do plus 15 if you know that you're always be, it's going to be a constant value. And of course here it's going to be other dart because if you want them to have random stroke weights, this is the way to do it. Plus stroke weight for this one and then plus other adult stroke weight for that one. So it grabs the correct stroke weight for each one of those. And now we're not going to see any collision. So because the screen is too small, we're not going to see much for a long time. So let's actually make this a little bigger. Actually double it. And now every time you run it, there is no collision and it's rotating and it's creating nice visuals. And because we have a random starting rotation, you can see that something like this is not actually starting at the same position as this one or at the same rotation is this one. And then because they have random speed, you're going to see different speed. And the reason why I used line as well as because as it rotates, it also creates a circle, gives it a more cohesive look, but it still has some variations. And then you can save the animation if you want. Violence, say a frame count is less than ten hundred, ten hundred frames at, if you specify the frame rate over here at, let's say 30 frames per seconds or 24, then you can specify, or you can calculate how many minutes you want and therefore how many frames you want. And make sure that you do less or equal if you're putting in the exact frame count that you want. And then you'll do save frame. And then output if you want to put it inside of a folder called output for organization. And then I just like to export them as PNGs. And you can do else. Exit. That way. It's gonna go from 0 to 1000 frames. It's going to save all those frames with the digits for that frame. And then once it's done, this is not going to be true. So this is going to be true and then it'll exit. And exit is going to just close this preview screen that's only need to know about this coloring technique. In the next lesson, we'll talk more about texture, specifically background images.
5. Texture 02: Background images: The second texture technique that we're going to talk about is extremely simple. And it's just adding a background image to your design. When I insert this artwork on social media, one of the interesting questions I've got is where did you get that background from? And I never thought such a simple thing as adding a background image of an old paper or any paper rather would be significant to the artwork. But I chose this as one of the texturing technique because I think it's interesting to use blend mode to see how the artwork interacts with the background. So the example is going to be a little complex. We're going to use 3D noise. So basically what we created and flowy noise the course. Yet, instead of putting it on just a regular background, a solid background, we will put it on a background image, which is going to elevate it a little bit and make it more like drawing that you've created by hand. I specifically chose 3D noise with this one because it looks more like you've painted this or you've drawn with pen on paper. But we're using generative art created. Now because this is all about adding background images. We'll start by adding the image. I've chosen image from a website called Unsplash.com where you can get lots of copyright free images, high-quality images. So I researched paper backgrounds and I got a time, and this is what we are going to use today with this artwork. So let's put it in the folder. In the sketch folder. Let's add a data folder. And I'll pull this to here. And I renamed it to paper underscore one. So it's much easier for us to import it later. So we're going to use P image, and I'll simply call it background or BG for short. And we're going to initialize it over here. So background is going to load an image and the image is going to be paper underscore one dot JPEG. And now we're also going to resize it to width and height. This is going to definitely distort the image because we have a vertical paper and this is going to squish it. So if we show it right now, you're going to see that some of the details are a little bit different. If you go back to the original image that we opened, it's not much of an issue here because the details are not major, so it doesn't really show the distortion that much. But if it bothers you that much, then resize it per ratio. If you know the original ratio of the image. And now if you want to draw anything on top of this, so let's say I want to draw an ellipse. And let's put it in the center of the screen. And I'll give it a width of a 100 by a 100. And I'll also add the image over here just to reset it. So instead of background, do not need the background anymore. We're just going to use the image to reset anything over here. And if I run this right now, we can see this on top of it. Now if I change this fill to, let's say red. And then I use the blend mode. Before you use the blend mode, I'll show you first. So that's the regular one. And then if I use the blend mode to multiply, and there are multiple blend modes. So the default is blend and then the rest you can find from the documentation. So there's multiplying screen and if you don't know, multiply keeps the dark colors and removes any white and screen does the opposite. So if you have a black and white image and you do multiply, then you're going to find only the black parts of the image appearing. And then if you do screen with the same image, then you're going to find that only the white parts of the image are going to appear. So now this is going to make this a little bit darker based on the color behind it. And because our backgrounds a little bit dark, It's going to make it a darker red. Now the problem with this one is that the blend mode is multiplying every time for everything. So if I do blend mode. Now you can see this is a little bit see-through so we can see the texture behind it. And the image doesn't get the same blend mode as the fill or the ellipse over here because I resorted to blend. Now let's start with the actual example. So I'm going to remove all of this now that we figured out what we are going to do at this time, we're going to do it with the 3D noise. So instead of that ellipse, we're going to create vertices are planes that are going to run across the screen using 3D noise. So I'm going to just call it agent. And we'll create that class. In this example, we're going to use 3D noise. Therefore, we'll have to define the position and size and speed for the points to move using noise. So in the class we'll add those properties. I'll just do x, y. And because we'll use 3D noise, we're also going to use z or z. And then I'll do your float size and speed. So the size is going to be the size of the points that are moving. And the speed is going to be their speed or velocity. To initialize them, I'm going to add some parameters to the agent. So I'll use the x and y because I want to define them outside of the class. Now assign x to whatever x is going to be and to whatever y is going to be. And then for z, and z is going to be a random value. And let's make it from 0 to 208. I usually go very small with the value of C with three-dimensional noise. And then undefined size in speeds. So size is going to be a random value. Let's make it from 0.5 to three. The center they are, the more they're going to resemble pen strokes. And then we're going to also define or initialized speeds as a random value, as a random value from one to five. And then I added a color array. You can use the same color array that we've been using since the beginning of these lessons or since the beginning of the course. And I'll do what I did before using a random index from the calls array that I just defined. So that will be an integer. From the random values. They're going to go from 0 to calls dot length. And we'll have to define color over here. So dial the color or if type color. And now let's define the styles. I sometimes like to keep styles separate from the display method or separate from the shape that I am going to define in the display method. Especially if I have a lot of things in the style. But here we're only going to have two things. So the first one is going to be stroke weight. And that is going to be the size. So kind of like the size of a pen. And then we'll do stroke. And we'll do no fill over here because we're not going to need it and there's no need for it to be inside over here. So it doesn't get called every time we create an agent. And now inside of this play will draw our point. And we'll also use the style. And the point is going to be an x and y. Very simple. And finally, actually, second to last thing that we're going to create in the class, that is going to be the update method. So this is where we're going to create the noise. And the noise is going to be the rotation of these points. So it's going to be the angle. And that'll be x, y, and z. However, if I just use it like this, noise produces values from 0 to one, and these are very small. So we're going to need to multiply it by noise strength. And if you ever feel like This explanation is a little bit difficult to follow. Or if you feel like this is a little bit too advanced for you, then this is something that I've dealt deeper into in the flowing noise course. So if you want to know more about noise and its function, then I would suggest that you go and watch the flow noise course first and then come back here. But in short, noise strength is going to multiply whatever value is here, and it will complain that it doesn't exist. So we'll create global variables over here, or actually global constants, because I know that noise strength is not going to change. So I'm going to create over here. But before we created and also need to divide x and y by noise scale. And the reason why I'm doing this is because the values or the noise function will produce lots of values. And noise scale is going to scale part of that wave and use it. So it's kind of like zooming in to part of a wave. So if you look at mountains from afar, you're going to see lots of peaks and valleys. But if you go closer than you'll only see the space that you're in. And NoSQL does exactly that. So if I go over here, we can define noise scale and noise strength. And we don't need to repeat float, we can just do comma and then we'll apply or will assign another value to noise strength. So I assigned noise scale, the value of 5049 strength, I did 100. These values you can change as much as you want. The bigger the noise scale is, the smoother the noise is. And The bigger than a strength is, the more rotation you're going to get because we using it with angle over here. So if noise scale is moving or zooming into part of the wave, the noise strength is increasing the height. And the low part of that wave can increment x by cosine of the angle and then multiplying it by speed. So speed is going to act kind of like the radius because this is going to produce values from negative one to one and we're going to need to multiply it by a bigger value. And then for y is going to be sine, the angle multiplied by speed. And we'll also increment the value z by something like 0.005. Again, this value, you can change as much as you want until you find the values that you like or the look that you like. Now the final method that we're going to create is the balance. Now bounces, not going to do much. Right now. It's only going to constrain the x and y values or the points from going beyond the canvases perimeters. What we can do over here is just to constrain x from 0 to width. And why from 0 to height. And you'll see what this does when we create our agents array. So that's all we need for now inside of our agent class, we'll go back to it later to add a few things that is going to make the final example. So for now let's just create an array of agents. I'll just call them agents. And I'll give them a count. Let's start with 10. Now in here we'll initializer, create instances of that agent class. And a rehear in the constructor we only have x and y. So I'm going to just do random from 0 to width, random some 0 to height for now. And then down here we'll do four agents. And agents will display it and date. And instead of creating the or, instead of calling the bounds in the main tab, I'll just call it over here. Just like we did with style inside of display. I did the same inside of update. Now if I run this, we can see our 3D noise. And as you can see, once it hit the 0 on the y-axis, it actually stopped moving and it moved just across that part. So whenever it's in the negatives, it's going to be always 0. And then whenever it's beyond the height, it's going to always be the height. And that's why you're going to see those points on the borders. And if you keep them for long, you're going to see a border in the end with the different colors that we have. And now because the speed is too high, we actually seeing the points are not seeing a smooth line. That's fine. We're going to fix that later when we finish the example. So if we go back to the Main tab, now what we're going to do is create a grid. And instead of creating the bounds between the zero-point and the width and height of the canvas. We're going to constrain them in the cells of our grid. So I'll be creating a grid and then each point is going to take its position in one of the cells. And then it'll be constrained inside of that. In order to do that, we're going to create a method that I'm going to call a net grad. So this will initialize the positions for ourselves. This will be for integer n equals 0. And then n is going to be the area or less than the area. The reason why I'm going by area instead of the number of columns and number of rows is because I don't want to nest loops. I want to reduce the number of flips as much as I can. So I'm going to initialize a variable called area, and that will be count to the power of 2, basically the width multiplied by the height. So the number of rows multiply it by the number of columns. And that will be over here as well. So the number of agents are going to be the same number of cells in our grid. Now I can do I and I can do J as well. So I is going to be n modulo counts, and then over here, n is going to be divided by count. So for the columns, so from 0 to the width, we're going to go from 0 to the number of columns, getting the remainder of dividing N by the count. Then we'll get numbers from 0 to the count. And then for the rows, we're going to divide n, which is the area by the number of rows. We did the opposite of what we did to create the area. And that will give us all of the positions from 0 to the height. And now to initialize it, I'm going to create an array of positions. I'll create it over here. And that's going to be a p vector. And the reason why I'm creating a p vector is to avoid Creating to float arrays one for x and one for y. And that will also be the area or have the length of an area. And then over here I'm going to do position at N is going to equal a new p vector at i multiplied by cell width and j multiply it by a cell height. And now we'll define those. So if I go up here and I do float cell width and sell height. And then in here I'm going to do cell width equals width divided by the float of counts, and then height divided by float of count. And we're going to need float because we need a more precise calculation. Because if they don't do that and this is an integer, f width is not divisible by the count, then we're going to see gaps in our grid. Now that we have this, we shouldn't get an error over here. And I can initialize the grant over here. Let's also add margins. If I do it right now, the greatest going to be on the edges of the canvas and that doesn't look great. So I'm going to add the margins over here. Now just do 50. So now cell width and sell height are not going to be just width divided by the count. It's going to be width minus the two margins. So margin multiplied by two. So that way we're actually subtracting the margins from the width and height. So we're creating a new width and height. Now instead of choosing a random width and height, I want each one of the agents to start from each cell. So for this, we're just going to use whatever we initialized over here. So we already created the points. We can just use it over here. That will be position I dot x and then position I dot y. If I run this, we're going to see points starting from each cell. However, we're not seeing it very well. And also we're going to need to push because if you notice, everything started from here and then stop over here. That's because we deleted the margins. We're going to need to push them over here. So if I do plus margin, and then over here as well, plus margin. Now we're going to see it better and will also need to change this to margin, margin and then width minus margin, right? Margin. So we're doing from margin and then two minus margin because now's the bounds are actually to the edges. So if I run this again, we can see it clear. We can see the margin because it's stopping over here. And now you can see how the bounds are actually working perfectly. Now the fun part is changing the constraints over here to confine the points inside of each cell. To do that too, again, to add a few more parameters. The first one is going to be cell width and sell height naturally, because that's our grid cells. And we'll also add it over here so we can pass it from the main tab, from the grid or from this part over here. So whatever we initialized for the grid, and that will be under scholar cell width and underscore cell height. And we can initialize them over here. So we're not going to do underscore cell width. And the same for cell height. Because this is just giving us the silhouette and sell height, but also need the positions. So wherever we are using over here, so this is going to give us the corners of the cells and then the other two are going to give us the width and height. So we need to add that. Now we can add them over here. So I'll give it the cell width and I'll give it the cell height. Now if we go down over here, I can use cell width over here. And sell height over here because x and y are moving and we're using them for the positions of the points as they're moving, we're going to have to use something else other than x and y because those are not going to work since they're constantly moving. So we'll need just to grab the x value, the starting x value, which we're passing over here and starting y-value. And we'll store them inside of cell x and sell y. And the, and those we can create over here. So that is going to be cell X and sell y. So now we grab the initial values. Now we have them over here. So now we can move this comfortably without worrying about the first position. And then we added the cell width Q, whatever x and y are. And then now over here we're going to use cell X and sell wines that. And now if I run this, we're going to see that they're constrained inside of each cell. It already looks great, but we can also, So they already look great, but we can also change a few things. So instead of point, we're going to use a vertex in order to make them look more connected. And instead of just jumbled points like they are right now, you can see the points because they're not actually connecting to each other. But if we use the Begin shape and, and shape with vertices, then we can connect them so they look more like a line. Actually, before we do anything, let's reset it using the image. Let's add the background image. Now you can see them moving. We can also add some guides so you can see where the cells start and end. And that is just creating a normal grid. I'll call them guides. And then I'll give them an x count and y count for the number of columns and rows. And then I'll create local variables for area. And then I'll also create local cell width and height. But they're going to be the same. So I'm going to grab this over here. But instead of count is going to be x count. And for cell height, it's going to be the same, but y counts, and this is going to be height. And then I'm going to use the same loop that we used over here. But instead of creating a new p vector, I'm just going to use a rectangle function and it'll have the same x and y position, but then know also have a cell width and height. Now we'll need to call it over here. And it will require a count. And because I'm using count over here as the number of rows and columns, then I'm going to just use it over here. I'll add a stroke to that. And I'm using Persian pop just so it doesn't affect my agents. And we can just make it black. And I'll give it an capacity of 50 percent. And now we can see it. I'll also add a blend mode over here so you can see the colors better on top of the paper. And so it looks more like an actual pen writing on the paper. As I said, we're going to have to either use push and pop. To push the styles are to constrain the styles just for the points. Or you can reassign the blend mode over here for these inside of this Persian pop. And I can see that there are a little bit darker, but we're not seeing anything because we're resetting the image over here. So it's actually just moving instead of trying. Now to draw it, the thing that I need to change is this point. So instead of point, I'm going to create a loop. And I'm going to give it a count. And then I'll also do begin shape and shape. Because I will be creating a line using vertices. But instead of putting the vertex over here, I need to put it down here inside of the update method. Because I need each vertex to have a different x and y position. If I put it all over here, it's going to have the same x and y position and then things are going to move, so it's not going to update the vertex. And then I will call the update method over here. So instead of calling it over here, we can just use display and that we'll call style and update. And inside of update, the bounds method is going to be called and count is going to be a parameter over here. So now here inside of display, I can do something like a 100 points. Now if I run this, we can see that it's creating a line, but it's too quick because we're moving by this speed inside of very small spaces. Now the first thing that I like to do, usually when something like this happen, is change the frame rate and change the size of the canvas. So if I do something like 1080 by 1080, you can see that the shape is more spaced out or the cell width is a little bit bigger. So now it has more space to move, and then I can reduce the frame rate. So if I go over here and I can do frame rate, because the default frame rate is, I believe 60 and I'll reduce it down to, let's say 12 or even maybe 24. But even 24 hours too quick. So you can either reduce the speed over here. So if I do from 0.1 to let say 0.5, you're going to see that the movement slowed down, but then you're going to have to change lots of the parameters because changing this speed will also affect the 3D noise. So bring it back to one to five, and then I'll just reduce this to 12. And I actually like it better when it looks more like a stop motion animation. And then I can also increase this because now we have a bigger Canvas, so 100 is not going to suffice to fill out the cells. So I'm going to just do 500. And now we're going to see that it looks much better. And to make it even look nicer because now your eyes going all over the screen. So to limit the movement of your eye across the canvas, we can just fill out some of these cells. So to do that, I'll go back to the agent class and I will create a random variable. That I'll call rand. And it'll be a random value from 0 to one. And then inside of style, this might not be the wisest way of doing this because I'm only going to remove the stroke, because I'm only going to move the stroke color, but I'm actually not removing the instance of the agent. So you can either do it over here so you don't initialize all of the agents, but I'll just do a simple solution over here by simply removing the color of the stroke. So if I go over here and I'll do if friend is, let's say less than 0.7 or 70%, then I'll have a color. Otherwise, I need the stroke or I need actually no stroke. And then if I hit Command T or Control T on a PC, then you'll auto format this. Now if I run this, we can see that not all of them are actually filled out. And that way it's less noisy. Also something that we're going to learn in the third texturing technique is adding background elements. So I already did something over here that is going to be related to that lesson. And that is creating those guides and leaving them. So you can remove those guides if you want, by just eliminating this. But it doesn't look as nice when you see it this way because you don't know why it's behaving this way. However, if you leave your guides than it looks nicer because now you understand why they're moving that way or why they're confined in that space, because there are actually bounds for them to stay that way. Now we can also add something else, and this is one of the reasons why I created the guides with an x and y account, I can create another grid, but this time it can have four times the account. And I can also give it a different color from the array. Let's say I'll give it the second color. And I'll also make it at 50. If I run this, it's not going to look right because we're not doing this way. We have to do x count and y count, or actually they're both going to be x count. I will also change the color for this one to be the first color from the array. Or actually I wanted it to be the opposite. So the pink is going to be inside and this one is going to be outside. And I'm going to put this before because I need the, the bigger cells to be the more prominent ones, since those are confining the screen. And then I can also do blend mode for that one too. Now we can see the pink better and we can see the blue better. Now we can play around with noise scale. So increasing it to a 1000, maybe the more you increase the noise scale, the smoother the design is going to look. So if I go up to 2000, then you're going to see that the lines are much, much smoother. If we go back to 500, you're going to see that there are more rotations. And if we go down to 60 over here than there are less rotations. So I'll just go back to 100 and you can play around with it however you like. Also you can play with the speed or the increments of the speed of the third argument in the noise. So something like this is going to create more rotations. And the slower it is, it's going to create much less rotation. You can also play around with the length over here or the count to the vertices. So if we go down to, let's say 16, it's going to be less prominent. And then if we go back to 500, then we're going to get more vertices and you are going to be able to see the noise a little bit more. This is actually one of my favorite examples of the bunch because it looks more natural with the paper background. You can also play around with the different backgrounds that you can find on the website or any website. You can also photograph your own paper and add it. That will give it more character, especially if you create something more like journal paper with lots of paint and lots of stickers and tape. All of those details can create natural look to your graphic work. Now that's all I have for this texture technique. Next we're going to talk about the next color technique, and that is using background images as a way to color your graphics.
6. Color 02: Color from images: In this lesson, we'll discuss the second coloring technique that I want to show you and that is using images as color. This technique is useful if you, let's say, have an image that you've created on your iPad, let's say on Procreate. And he used things like gradients and brushes that are a bit softer. Ease the liquefy tool to kind of merge the colors. That would be a great image to use and processing as an input for color for your geometric designs, which are a little bit more harsh, but with colors like that, it can elevate the design, the end for me, I'm going to use one of my earlier geometric designs from the recursions course. And I'm going to use it over here for another geometric design. So it's going to give it a different look. The first thing that we're going to need to do is import the image into processing. And I'm going to go to the folder. You're going to have to save your sketch file in order to get to the enclosing folder. And then we're going to create a new folder and that an extra sketch file, and I'm going to call it data because that's how you import images in here or any files rather to your processing file or processing sketch file. And then I'm going to grab it. I put it over here in my Downloads. And simple as that, I called it image underscore 001 just for easy access. And now if I go back here, we can create that image loaded. So I'm going to create a new variable called image using the PMF class. And then in here, I'm going to say that image is going to be loading the image. So load image, and that takes the filename. That's why it's much easier if you have a simple file name. And I'm also going to resize it because if I draw this right now, so if I do, imagine you can dry it using the image method. And then you'll have to just position It's corner. If I draw it right now, it's going to be huge. So if I want to resize it and I'm going to just have to use the resize method inside of the PImage class. And I will just do width and height. Right now. I know for sure that my image or the image that I'm loading in is a square. So it doesn't matter if I just resize it to the width and height of my screen because it won't distort it. And this is the actual image. But if you have a longer image, so vertically or horizontally, then you're going to either have to resize it's width or height depending on what part you want more. And the rest will be cut out by your screen. However, I don't mind if I'm using it for color. Don't mind distorting the image, destroying it basically by just resizing it to the width and height of my screen because I'm only using it in geometric shapes. So my end goal is not to show that image, the underlying image meaning, but for this one, it's going to be very simple. So we're just going to resize it to the width and height. And now we have the image perfectly fitting the screen. And then the next thing is to grab the colors from each of the pixels. Now the way you can get any color from this design is by using the get method. So if I say print whatever is in image ads mouseX and mouseY. And you have to put mouseX and mouseY lie inside of the draw function because we needed to print every time I move the mouse, because mouseX and mouseY, why? We'll grab the details of where the mouse is. So if you put it in side of the setup function, then it will just run once and that will be the zero-zero point. So if I run this right now, we can see the colors changing. And I, if I actually draw, instead of doing it this way, I'll just use it as the fill and then I'll draw a rectangle at mouseX housewife. That will be, let's say, 30 by 30 pixels. And every time it's going to be filled by this one, we're going to see the colors changing every time. So you can see the color of the rectangle changes based on where my mouse is on what pixel. So if it's on the orange pixels, then it's going to be orange, pink, pink, and so on and so forth. Now, onto the next section of this lesson, which is the example. So I'll show you an example where you can use something like this. So I'll create something very geometric, and that usually means me using a grid. So I will create a method that I'm going to call grid. And it will require a count because for this grid, since it's a square, I will need an x count and a white count. And this is going to be the count of my columns and rows. So the first thing that I would create for a grid is the silhouette pencil height, knowing the count and the width of my screen. The first one is going to be so worth it. And I will be width divided by the float of count. Just to get a more precise calculation. Because if I don't do this, if you divide width by a number that is indivisible by the width, then you're going to see lots of gaps. But by converting this into a float, then you are getting the correct or the more precise calculation. And then this is going to be height divided by the float of count. And by the way, you can also create guides. We can create another method that you can call guides. If that helps you out. And this way you can see how the grid is working. The same goes for this one. So let's create both at the same time. So you can see how things work. And you can create a function that calculates these together. And then you can call them inside of these two instead of redefining everything. But I prefer it this way just in case I wanted to change the guys to something else. And then j is less than count. So j is going to go through the height of the screen, and I is going to go through the width. So it'll create the columns for us. And it's up to you if you want to do. I first say you want to go through the width of the screen first, the men, the height. It doesn't really matter here. And then I'll create the x and y positions. So this one is going to be I multiplied by the cell width, and y is going to be j multiplied by the cell height. And then this is going to be the guides. So this is just for us to see that everything is working fine or everything is where it should be positioned. And sometimes it's nice to leave those guides. It can give a nice visual and we're going to talk about that later as well. And now if I draw the guide, so instead of trying the image, I'm going to draw the guides. And let's say I want 10 rows by ten columns. Then I get 10 rows by 10 columns. So I know my grid is working perfectly fine. Now I can copy this and paste it over here. And instead of drawing rectangles, I'm going to draw lines and arcs. So it's kind of like what I'm trying to do is draw a path going from one side of the screen and looping through rows and columns until it gets to the end of the grid. And that I can create by specifying a few scenarios. So I want to go from the top left corner and then I want to go to the right, and then I will go one line down and then to the left, and then one line down to the right and so on and so forth until the last cell in my grid. So for that scenario, I know that I'm only turning at the first column and at the last column. Knowing that I can write an if conditional that checks if it's the first column. And then an else f that checks if fits the last one. And that will be count minus one because we're going one less than the count, or rather here. And then lastly, my else statement is going to be everything else. So it's not the first column, it's not the last column, it's going to be everything else. So for everything else, I'm going to draw a line that's the easiest one. So we'll start with that. It'll go from x and y. So from the left part of the cell. And then for y, because I want it to be at the center of each of these cells. Then I'm going to add to that the cell height divided by two. And then I want it to go to the right side of each cell, so that will be x plus E cell width. And then for the last one is going to be the same because I don't want it to be a diagonal line, I want it to be horizontal. So it'll be the same thing. So cell height divided by 2, so y is going to stay the same. X is going to go from the left to the right. And if I run this, I should see lines if I actually call Greg. So let's call gerd. And I'll do the same count. We can just to make sure that every time the guides are the same as the grid, I'm going to define count over here. We'll make it ten minutes of stupid argument over here with the variable count. And now we can see that the first column doesn't have anything because our F conditional is empty. And then the elsif conditional is empty for the last one, but then the ones in the middle, which is everything else, has a line that goes horizontally from left to right and is vertically centered inside of each cell. Now for the first one, the last one, I know that I want to draw arcs to turn. So that will be a quarter of a circle to turn from one line to another for each cell. So it'll be half a circle for both of the cells, but we're going to have to draw a quarter of the circle and then a quarter of the circle for the other cell. So there are two scenarios for the first column and then there are two scenarios for the last column, and that is odd rows and even rows. The first one we're gonna do is and even row. And that is if j modulo 2 equals 0, meaning if the remainder of dividing j by two is going to equal 0, which means J is divisible by two, then that is going to be an even row or an even number, which means it's an even row. And then else, if j is not even, so the remainder of dividing it by two is not going to equal 0, then it'll give us the odd rows. So if I copy and paste this one, it's going to be the same for both. The only difference is that how we're going to draw the arcs. So we talked about our x in the previous lesson or in the previous color lesson. And we know that for arc in the first two arguments are going to be the X and Y position of its center. So if it's a full circle, then the center is going to be our x and y. So I want the center for this one, for each of the even ones. So 0 is going to be considered an even row for the even ones are not going to be the second tomorrow that we see visually, but it's going to be the third one because we're going 01234. So this is even, this is even. And then this is odd. So I know I want it to go because I know I'm starting over here, so I know I want it to go this way. And then going over here, we're going to go this way and then we're turning. And then going over here, we're going to go this way. So I know these are going to be half a circle for the first one. Actually, you can draw a line, but they'll be even more conditions that you can add to your for-loop or that you will have to add to your for loop. So I'm going to just leave it as a curve or an arc that is going to go upward. So this is going to be x plus the cell width because that's the top-right corner. And then it's going to be y because we're not moving anywhere vertically. And then we're going to have to define a radius. So I'll do a circle. So for width and height, it's going to be R. And I will define r over here. So r is going to be the minimum value of cell width and height. Just in case I wanted to make this into a rectangular grid. This will assure that will always have circles for arcs and not stretching it all over the screen. Because then we're going to these different and they're going to be ellipses. And it's not going to look good unless that's the look that you're going for. So I'm going to just grab the minimum value, whether that cell width or sell high, depending on your screen, whether you want it to be vertical or horizontal, but minus square. So it doesn't really matter right now. So you can just specify the cell width and that will be fine. And now knowing that the arc starts or a circle starts to drop off from the right side. So thinking of the two lines perpendicular to each other in the center, we know that up is north and then down is South. So rate is going to be East and left is going to be West. So we're going to start from the east side. But I know that it's not going from 0. So it's going to start from the South point. And the South point is going to be half Pi because we're moving from 0 by quarter of the circle and that is half Pi. And then I'm going to the west side of the circle, so that will be pipe. Now let's run this to make sure that everything is working perfectly. As you can see, the arcs are drying nicely. And let's change the color of this so we can see it and we can hide the guides right now, or we can color it something different. So let's say now film and then stroke will make it 0 at 50 transparency. And then over here, I'm going to do stroke weight. We'll make the stroke weight variable. So I'll do width divided by the count multiplied by two. Just an arbitrary number. It's what I calculated and it's what I like best. And then we'll also do stroke cap. And I'll make that square. And we'll just make them black for now. And instead of defining no fill here, and in both of the functions, I'm just going to do it over here. Now if I run this, we should see a nicer look. Now for the odd ones over here, we want it to close that gap. So this is going to be x plus cell with 10 and y plus cell height. This is the center. And then for the radius it's going to be the same every time. And now we're going from knowing that this or the circle turns clockwise, we're going to have to go from 0 to half Pi, but we don't need that. And then we're going to go to pi. Still we don't need that. So we're going to go from pi to pi plus half Pi. So half of the circle plus one more quarter. And we'd recommend you experiment with arcs if you feel like it's not making any sense. But just note that half pi is quarter of a circle, pi is half of a circle. And that when you draw an RQ go clockwise. And then if I run this right now, and I actually made both of these events, so it's not going to work. So now we have our even Rosen are odd rows and they're working. Great. Now we're going to do the last column. So for the last column, we're going this way. So you're going to have to go this way. So this point is x, and then y is going the full height. So it's going to be y plus cell height, then the radius is going to stay the same. And now since the centers over here, we're going from half pi plus pi to two pi. And the reason why I'm saying two pies because we're actually going a full circle instead of saying 0, which is going to go backward. And if I run this, you should have the second-to-last. And now further last one. We're going to have the center at x and y. And then this is going to be the radius. And finally it's going to go from, since this is the center, it's gonna go from 0 to half Pi, so only quarter of a circle. And now running this, we have a complete design. Now to the most important part, and that is coloring it using the image that we added or reloaded. And as we know by now, we can do that using the getMethod. So what I would do is just grab the image using the get method. I'm going to use the x and y position. But because I want the center of this grid or the center of the cells and migrant. And I'm going to have to add half of the cell width to the x and then half of the cell height to the y, just to make sure that I'm getting whatever color is in the center of myself. And now get is going to complain that needs integers and these are floats. So I'm going to have to encapsulate it into an int method. Just because casting won't work here since we have a formula. And instead of, so we're going to have to cast x alone and then the cell would alone, or you're going to have to encapsulate them in parentheses, and then this is going to be in parentheses. That's too much so we can just use the methods and to convert them. It's much shorter. Now if I run this, we should get the colors from the image. Now if I show the image, you can see slightly that wherever the lines and arcs are there, grabbing the color from the center of that cell. And to make sure that we're actually grabbing the colors from the image, there is a way we can certify that by creating an animation. And I think it's nice to see how the colors are being grabbed from the images dynamically. So the way you can do this is by leaving the count like this because now it's by default initializing to 0. So if I just go over here and then I do count plus, plus as in increasing it by one. And then I grab these are actually don't mean the guides anymore because they have the image. And now every time this is being incremented, it's going to grab it over here and the greatest going to update based on the count. And then we're going to also have to reset the background. I'll also make it a darker color because it's nicer with the colors that I have. And I'm going to reduce the frame rate because this is going to be blinding. So make it at 24. You can even make it less. 12 would be nice, but it'll look more like a stop motion, any movement, and just making sure that everything is drawn correctly. Now we can run this and you can see the image revealing itself the more cells we have. Because it's going to resemble increasing the resolution of the screen. So having more pixels, meaning having a crisper image. And that's basically what this is. But now we have a really nice design. So you can also save this animation to show people the underlying image of where your colors are coming from. Or you can also share screenshots of your favorites. So my favorites are usually the ones that have two. So if I do something like this, I can use in any graphic design work. Or even one can be something that you can use. I actually use this in code with me video on YouTube where I added titles at the end of the video on a frame like this, but one that is horizontal so it fits the video. But generally, I like the animation better because it shows the image or the underlying image in the end. And if you want to save this, you can say if count or you can use the frame count is less or equal, let's say 120 based on the frame rates and the number of frames. And I'll just use a frame and I'll put it inside of an output folder. And knowing that we are going to stop at three digits, our need more than three hashes, and then PNG or JPEG depending on what format you like. And for else, we're going to exit. So this is going to save the images and then it'll exit or close the previous screen. So that's grabbing colors from images. In the next lesson we're going to talk about another texture technique and that is adding your guides as design elements or simply adding background elements to elevate your design or to add visual interest to it.
7. Texture 03: Background elements: In this lesson, we will work on an example because we've already created to that, implemented it. This technique is somewhat similar to the second one. The second one was about adding a background image. While this is about adding background elements such as guides or texture and details like fake dust and scratches. In the second texturing technique, I combine two grids on tops, the background image to mimic graph paper, especially since we're using an actual paper image in the background. It also seemed like the natural choice to add a gradient first place to show why the design is behaving the way it is. To show that sells bounds can find each agent respectively. However, for this other example, revealing the guides is unnecessary. Adding it can crowd the design or even ruin it since we're grabbing colors from an image, the more cells, the more the guides can be hindering. Imagine your desktop background in all the pixels, edges in white or black, the picture won't look good in our case, however, the designers impact with pixels so we can add subtle guides like points at the cells, edges resembling dotted paper, kinda like those bullet journals that we're seeing out there. It exposes the underlying grid without overpowering the final artwork. This example which will create next gives us the feeling of chaos. Although when I show the guides, I expose that it's actually ordered chaos. It's immune grad with randomly offset shapes. For this example, revealing the background detail is your choice depending on the reaction you want from showing it to others. For instance, in this example, using numbers unveiling the underlying grid gives the viewer insight into the design will adding a type of graphic element. It shows that I created this using a grid while offering the approach of making the grade that I didn't use nested loops which could have displayed duplicate numbers. You can also add background elements that are only for design purposes. This example uses random scratches to mimic paper imperfections. Bromine idea to add texture to a design. It doesn't look prominent from afar, but it's still visible in the overall look, especially when printed on regular plain paper. Also for data visualization, showing some of the background elements relating to the information can be very helpful for the observer. Check Nicholas Felton, work for some ideas on their website fell Tron.com. There are a bunch of examples from the annual reports that they've created throughout the years, some of which are created using processing. Also check their sculpture classes and information design with processing, including graphic design and coding tips relating to the subject. Now it's your time to think of ways to add texture to your background or even foreground simulating scratches or dust particles on a camera lens. That would definitely look really cool. Tried to figure out ways you can bring the physical world into your computer screen. That's all I have for this lesson. If you have more ideas, please share them in the discussion, or even share them in your examples for your projects. I would love to see them. Next, we'll talk about a very interesting concept of coloring our design using a technique similar to collision detection by grabbing color firms and nearest neighbor.
8. Color 03: Color by distance: In this lesson, we'll talk about the third coloring technique. And to me this is one of the most interesting ones that I learned and read about it in one of Tyler hubs articles. He just explained it. There's no codes. I started to experiment and find my way of doing it. So this coloring technique is kind of similar to collision detection. I call this coloring technique coloring by distance because it checks for the closest agent or colored agent to an object and uses that color would can produce something similar to a Voronoi texture with color. To achieve this, we're going to continue from the color one example or the first color technique example, the color interpolation one. However, we're going to change a few things. So we are going to need agents. And agents are going to be positioned in the same way that this one is positioned. For this one, however, we're going to change the behavior of an agent, and we're also going to change the constructor a little bit. So instead of randomness, we are going to create a grid for this. I'm going to add two arguments for the agent constructor. So when we create an instance of the agent class, we can decide the position of it then. So in the for loop that is going to create the grid. So for this we're going to do float underscore x and float underscore y. And then I'm going to change these two to be x, which is our native inside of the class, equals to whatever the parameter x over here is going to equal. And then for the radius, I'm going to also initialize it later on depending on the cell size. And let's make the stroke width three because we don't need it to be huge. And then we won't need an angle in a speed because along updated the same way we used to update the previous one. And we won't need color 1 and color 2 because we're going to use a different agent to color these colors going to be random. So you can keep one of the either kilowatt hour CO2 and then rename it to color because that's what I did basically. And then I can remove that from here. I can also remove that. And then because we're drawing circles mostly so we don't need the stroke cup because we're not going to see any caps anyway. And I'm going to keep those the same and also remove all of this. Now, just have a circle and XY. And it'll have a radius. Actually instead of radius, I'm going to rename this to size. So it's not confusing like previously. Sizes, basically the diameter of the circle because circles and ellipses are drawn using the diameter, not the radius. And I won't need the update for the collide. And now instead of having the stroke weight to be constant, I'm going to make it size divided by eight. And this, or adding points 0 makes it a float. Instead of just doing what I do usually like this. Because it's a number I can easily put 0 and then turn it into a float. So this will give me a more precise calculation. The next thing that I'm going to do is go out here. And instead of an ArrayList, I'm going to use a regular array. Because I want to specify the number based on the count that I specify for a grid. I'm going to make this count. So I can just do integer, can't. Actually this is going to be count multiplied by count because I want the area. While here count is going to represent the number of rows and the number of columns. So let's say I want 10 to begin. Okay, so let's top and I'll explain what I'm trying to do here. So agent is not going to be simply the agents that we're going to see on the screen like before. It's going to be the agents that we see and the agent behind the scenes that are going to be the source of our colors. So in the beginning, I did choose a random color, but that's not what we're going to use for our agent. So this is going to be the colors for our color agents. We are going to be invisible. Now knowing this, I can create another agent array. However, this one is going to be the color agents. And the count for this array for the color agents array is going to be dependent on how much color you want your design to have. So if I say new agent and I put only five colors, then you'll find that the majority at certain areas are going to have one color because there are only five agents to grab color from. However, if I put 50, Then I'll get more variation in color. So let's start with five, and let's display it. So now we can actually delete all of this. We don't have an update because we're not going to move anything. Now we'll start initializing agents over here. So I'll do for integer I or for integer n, because I'm going to use I and j liter equals 0 and n is less than agents dot length. And now for I going to say n modulo count. So it's going to go from 0 to count. So here it's 10, that's going to go from 0 to nine. And then integer j is n divided by count. So it iss doing is getting the remainder of dividing and by counts is going to go from 0 to nine and then again from 0 to nine. So it's going to go through every row because j is being divided by count. Because whatever n is at the time, dividing it by count is gonna go through the rows. And now I can say for floats x, for the x position, it's going to be I multiplied by cell width. And then for y is going to be j multiplied by cell height. And if we initialize or before we do that, we're going to go over here and do cell width and height to define it. And then over here. So width is going to be width divided by float of counts, like we did before. And then cell height is going to be height divided by float count. However, I also want margin, or I like to have a margin at all times. So I'm going to cut it from here and put it over here instead. And then I'm going to subtract it from the width. So the reason why I'm saying margin multiplied by 2s, because what I define as a margin is just one side of it. So from the width, I need one on the left and one on the right. So we're going to have to multiply it by two to get double that. So I can subtract it from the width and the height. And then over here, we're going to need to push it. But before we do that, I want to show you first how the grant looks. Then we can push it by the margin. Now, we can say agents. I was going to equal a new agents. And the constructor requires an x position and y position and a size. So let's also initialize the size over here and I'm going to make kit the minimum, whether it's cell width or cell height, to make sure that we always have a circle, especially that we defined it as a circle here anyway. So if you have, right now we're not going to have a problem because we have a square for Canvas. However, if we do have a vertical canvas or a horizontal Canvas, then this will help us out to only get squares or circles. And now we have it displayed over here. So if I run it, oh, I should have it as n over here. Now if we were in it, we can see the circles. And this is where I said we're going to have to push it. So right now, because we deleted or we subtracted, double the margins from the width. Now we have a 100 pixels over here. So if I push this by margin, by just adding margin to it, it's going to push the whole thing to the right and downward. So you can see the grids perfectly. I'm going to also draw rectangles or squares at position x and y by size and size. So we're also going to need, so you can see why it's not the same over here. And over here. Because we're drawing as if the circles are being drawn from the left or top left corner. While they're actually being drawn from the center. So you can either change the ellipse mode to corner or you can just add it over here. So I can simply add size divided by two. And here, size divided by two. We can choose cell with or sell height. Either one is going to be fine. However, for the same reason that we talked about before, I'm going to use this because it's going to make sure that it's going to give me the minimum, whether it's cell width or height that is smaller. So it always fits inside of my II cells. Actually, instead of doing it over here, I'm going to do it over here. Or you can do it this way just to keep it clean to make sure that it's only being added after all of these are being created once the physician has been established. And the reason why they're not aligning with the rectangles. Circles have been pushed. However, they're not aligning with the rectangles because the rectangles are being drawn from the corner. So we're going to have to, just so we can see that it's working fine. I can just do Centre for their rectangle mode. And now we can see that it fits perfectly. So we're not going to need the rectangles anymore. It was just for us to be able to see that our grid is working fine. So first stroke width, we can make it even smaller by dividing it by 12 because now it's overlapping everything or by 15. And also I'm going to reset the background so we don't see Bs crooked lines. Now it's much cleaner and I'm going to increase the count and decrease the margins. So further margins, I'm going to keep it at 20. And then for this one, I'm going to make it 50 or maybe a little bigger. Because I need some more circles in order to see how these are being colored. Now for the coloring agents, I'm going to initialize it in a loop. So for this one, because it's going to be random, I'm going to duplicate the constructor and create another one that doesn't have any of these. And it's going to be a random between width minus margin too, or between margin and width minus margin. And the same goes for y. And then this as well, I'm going to make it a random between 35 and over here. Now I can use agents at position I is going to equal a new agent. And that is going to be the empty constructor. And if I display this over here, so you can just change color agents and it's going to grab every one and it's going to display it. I did agents instead of color agents. So now if I just to initialize it, we can actually see them on top. So you can see them, they're very small. So if I just increase the size to something like 10 to 50, and actually we don't need them to be that random, so I'm just going to make them 20. And now we can have them invisible just we made sure that they are there. And each one has different color. I'll keep this as a guide so I'm not going to remove it so I can uncomment it whenever I want. So let's say if I add 50, I want to see how it looks. I can comment it out and turn this one on. Now we have our grid. Okay, Another thing that I want to do is not just get the cell width and sell height, I want it to be smaller. So let's say I want to divide it by 1.5. So I can offset it. And now I can go back to the size and change this to eight because they're not going to overlap. So I can see them better. And I can offset this by a random value. And that random values going to be. From 0 to size divided by two. So you can see them, they're a little bit more random and they look a little bit more interesting. And we do the height as well, or the Y position as well. Now we have a little bit more variation and the design, Let's go back to the color, which is more important now that we have our design established, let's create our color transfer method. So inside of our agent class, I'm going to create a method that I'm going to call take color or take call. And it's going to take another agent array. Then I'm going to call agents. And this whole thing is going to return a color. Now, what we're going to do over here is grab the array of agents that have color in them that we're going to use to color a design based on the distance to those agents. So I'm going to combine all of the distance inside of an array or a dictionary. And then I'm going to, then I'm going to sift through all of these colored agents. And then I'm going to check which one has the shortest distance to any of my objects. So whatever is closest to my object, that is going to be the color of my object. To do this, I'm going to use a float dictionary. I'm going to call it digests. And then initializing it is as simple as just doing this. And then I'm going to loop through all of these distances or all of the agents and checking the distance. Each time, I'm going to check the distance between x and y and agents x and y. And now this is going to be set inside of the array or the dictionary. So the way you can do this is just by calling us and then calling the set method. And the set method takes in a key. So I'm going to give it the index, and then it's going to take the distance as the value. So this is the key for the dictionary and this is the values for the dictionaries. And the reason why I'm using a dictionary is because it has a sort values method than 18 years. And this is going to sort them in ascending order. This way, I can grab the first one, and that is my closest color agents to whatever object is specified at the moment. So I'm going to grab all of the keys. And you can grab them using key array. And then I'm going to return the agent at CHI 0 and I'm going to grab the color from that. This is a mouthful. However, if you take it step-by-step, it's very easy to understand. So what I'm trying to do is grab all of the color agents, check its distance with any agent that I'm specifying. So I can call this the color on the agent's array that I have over here, which is this one. And then for every iteration, I'm going to check the distance between that agent in the array of color agents. And then I'm going to grab all of these distances, put them inside of my float dictionary, and then I'm going to sort the values in ascending order so I get the closest color agent to my agent. And then I'm going to grab the keys for this dictionary so I can get the agent at the first key or at the key in the first position of the array and a dictionary. And then I'm going to grab the color from that. So that is going to be the color of the closest color agent to my agent. Now if I go back over here, I can use this inside of my array. So I can do it this way. Agent dot color. So I can grab the color of the agent and I can assign it to agents dot-dot-dot take color from the or looping through the color agents array. So this is going to perform what we just created on every agent inside of the agents array. And then it's going to set it to its color. Now if I run this, we should get completely different results. And now if you want to see the color agents just to see how this is working, you can display it and you can see that this one is closest to these, so it's, it has this color. However, for this one they're closest to this, the, That's why they have the orange color and so on and so forth. And like I said, if you want to have only five of these, you're going to have less color variation because there is less chance that some colors are going to appear since we only have five colors in the first place and you're getting a random color. So right now we don't have a pink, we have two yellows instead. Or you can even choose the probability of choosing one color over the other in your random color choosing. But the way I like to do it is just adds 50 and that way I can get more color variation. And if you display this, you can have more colors. So if I go back to five, we can see that we have less color variation. It still is a nice look, but if you want all the colors to appear, you're either going to have to change the probability of certain colors appearing more than others. Or you can add more agents for the color agents. So the more you add, the more color variation you're going to have. So if you make this one a lot bigger, and then we can add more. You can see the design a lot better. It actually gives you a Voronoi kind of texture. The more colors you have in your array, the more you're going to be able to see it. Also, if you change the stroke over here to fill instead. And no stroke for this one, you can actually see it better. So this is kind of similar to coloring using a background image. However, it grabs the color from the closest color agent instead of just grabbing whatever pixel is underneath that. But if you have a design that you've created to using your iPad or your Wacom tablet or any tablet that he is a pen width. Then you can create gradients or a geometric shapes, just filling the canvas with colors and using that as a background image to color your design. The way you can get more color variation without easing something like this, for instance. That's it for this coloring technique. Next, we're going to tackle the fourth texturing technique and that is adding shadows to your design.
9. Texture 04: Drop-down shadows: This last texturing technique is also very simple because we'll be adding simple shadows to our designs to create some depth in our work. To show you what I mean by a simple shadow. Let's create two circles. And I've also already added the color and the background. So if you want to take those colors, feel free to do so. If you want to use your own colors, I'd actually encourage it. Now let's create the simple shadow. Will do that easily by creating two circles. Now, the first circle is going to be the shadow because whatever comes first is going to be below the second one. So this will be, let's say, width divided by two. Height divided by 2 shall be in the center. And then we'll just give it a width of a 100. And then the same goes for this one. The only difference is that the one at the bottom is going to be offset a little bit. So either offset it just to the right or you can offset to the right and down wherever you choose the light to come from them, just go opposite to that. So I'm choosing the light to come from the top-left corner. Also remember that this is very simple shadow, so it's not realistic. It will just give us depth in our designs. And now to differentiate between the two, I'm going to give this a fill of black. And this afoul of, let's say one of the colors. So I'll give it the first color. And let's do no stroke for now. And this is basically what I mean by a simple shadow. So we can decrease that, let's say make it five. And this way we add a little bit of depth. Now, this won't work here very well. But for the class that we're going to create, once the design is complete, you're going to see a little bit of a difference when it comes to the depths of your design. So let's remove all of this for now and start creating the class. So I'll call that class a spiral. Because we're going to create a spiral shape. The first thing that we're going to need for this spiral shape is the main X and Y position. And that will be float x and y. And because a spiral is basically a circle that moves to create concentric circles. And in order to move around circle, we're going to meet several components. And those are center x, the center y, start radius and angle. So I'll just create those center x, center. Why? And then start radius and an angle. And now I'll initialize start radius and center accent to y and the angle you're first start radius. I'm going to make it a random value from, let's say ten to 30 to start radius is going to be the beginning circle in this spiral. And then center x is getting to be a random value will be from the start radius two with minus start radios. And then for center, why? It's going to be the same exact thing, but with height. And finally, for angle, it's going to be a random value from one to five. It doesn't really matter. And the reason why I'm randomizing angle or initializing and overhears because if I don't do this and then I start creating the spiral, they will all start from the same angle. So I need a little bit more variation in each of the spirals. And you can achieve this by randomizing the starting angle. Let's display the spiral. To create the spiral, we're going to draw points around the circle, but the circle or the radius of that circle is going to increase and that will be creating the spiral. So for that, you can either use points and then use a stroke weight for the size. But here I'm just going to use an ellipse is going to be at x and y, and then it's going to have a size. So I'll also initialize a size. And then I'll add a color. We already have array of colors. So I'm going to use it here. It's also going to be a random color. I will also define no stroke over here. Instead of putting in over here. And finally, we are going to have an update method. So in the update method, we're going to increase the angle for it to move. And then we'll also create our x and y values. And they are going to use the cosine of B angle, B Increasing angle. And then y is going to be the sine of the angle. And then we'll multiply it by the radius. And finally, to push it center to wherever we need, we're going to have to add center x and center y. So epsilon y are going to define the position of the ellipse that is drying around a circle. And then start radius is going to define the radius of that circle. And then center x and center y are going to define the center of that circle and the angle will increment. This is going to draw the same circle over and over around the central point. So what we need to do is increase the start radius. So I'm going to also increment the value that I will call ink. And I will define it up here. And then I will add it to the start radius. But we need to do it before the multiplication. So they go over here and create an instance of a death spiral. Can see how it's actually working to create a new spiral. And then inside of the trial again displayed an update. So spiral dot display glenn uptake because I forgot to initialize the size. So the size is going to be a random value on the kick from 5 to 7. And now we can see the beginning of a circle. So this will have a start radius, and then as it moves, it'll increment the radius, so it creates a spiral. Now this is fun and all, but I think it will look even more interesting if we add a little bit noise to this movement. So instead of creating perfect circles, Let's add some distortion. So if I go back here, I can add two values and I'll call one distort X and the other one line. And before the x and y initialization. Initialize the story x to be noise. And let's make it x divided by a 1000. And then I'll use angle for the second one. And then for the storage. Why? I'm going to make it noise and let's make the scale a little bit different. So I'll make it 3000 for this one. And then we'll use angle for the second one or even angle, multiply it by 0.5, Let's say just to change it a bit. And I can add that to the angle. So I'm distorting and I keep writing this gray because it is actually destroying the perfect angle for that circle. And then I'm going to add distort y to the y position here. Now if I run it, and you can see there is a little bit of noise in the spiral because we added this distortion over here. This gives a more natural feel. So it feels like someone is actually trying it by hand. You can also make both of them the same in terms of the second dimension of the noise. And that won't destroy it as much. So it will still keep the circular shape and it won't become more like an ellipse. So it's up to you how you want to distort the image. So we're going to keep it this way. One more thing we can add to this update method is varying the direction of the angle. So right now everything is going clockwise. We can move it to go anticlockwise as well. But we'll see this if we create an array of spirals. So let's create an array. I'll give it a count of 10. This is getting to the inside of the lip. And the same goes for this one. Now if I run this, we're going to see several spirals. So as you can see, they're all going clockwise. Change this. I'm going to create another variable that I'm going to call, therefore direction. And then it's going to have a random value from 0 to one. And then I'll give it a probability of 50 percent to go clockwise. So if direction is greater than or less than 0.5 because 50% is half. Else, I need the angle to go the opposite direction. But I'll make it the same speed. And now if I run this, you'll see that some of them will go clockwise, while some other are going the opposite. So this one is going anticlockwise, anticlockwise, and these are going clockwise. Now the important part is creating the shadows to create the depth. So as you can see, this is very 2D. And to do that, I'm going to create another method that I'm going to call graphic. So this is going to have an offset, a color. And any here, I'm going to have these two. And I'll have color as this one, which is C. And then I'll also add the offset like we did before to x and y. This way I can call graphic twice a year, once for the shadow and once for the main shape. So for the shadow, I'm going to call graphic with, let's say, an offset of 15 and a color of black. And then I'm going to call graphic again. But this time with an offset of 0 and coal as the color random color that we created over here. Now if I run this, we're going to have a shadow that follows the spiral. Let's actually make it five. So you can see it better. Now you'll notice one thing that is very wrong with this shape because we're drawing the shadow for each point. Some of the times you're going to find that the shadow is going to go over the main shape because they're moving separately. So as you can see over here, it doesn't really look like something underneath the main shape. And to do that, we're going to use P graphics. So it's very easy to fix this because P graphics allows us to create multiple layers that would never intersect. So they literally go on top of each other without ever meeting. So it's kind of like moving on the z-axis, similar to Photoshop and Illustrator and all of these apps that use layers. This is very simple to do. I'm just going to create a peak graphics layer over here. And instead of just using the fill like this, I'm going to use layer for both of these. And then for any p graphics here are going to have to start with beginning. And then and draw. And then we're passing the first layer for this one, which is going to be the shadow layer because we need it to be on the bottom. And on the second layer is going to be the main graphic. And then I'm going to add it over here. So I'll need two layers. First one, I'll call layer 1. Second parameter is going to layer 2. Now in the main tab, this is going to complain. So we're going to also need to create two p graphics layer out here. The first one I'm going to call, and because we have arrays, we're going to have to create an array as well. So the first one we are going to be graphics. So it's holding all of the main graphics. And that is going to be an UP graphics that will have the same count and the same exact thing for the shadows. And then in here as we initialize these spirals, we're going to also create the graphic or each graphic layer for the graphics array. It's going to create graphic or create graphics. We're going to keep all of the layers the same size as the canvas, so width and height, and then the same goes for shadows. This is going to require the two arguments, which are going to be the first one we said is the shadows. And then the second one is going to be the main graphic. But now if I run this, we're not gonna see anything because P graphics only shows if you dry it using image. So the first one is guaranteed shadows at position I. And this image is going to be drawn at 000 because it has the same width and height as the canvas. And then the second image is going to be each of the graphics. And it's also going to be at 000. Now if I run this, we'll see that they all have strokes again. So I'm going to remove the noStroke from here and I'll have to put it inside of here because it requires to be inside of the layer. You can also add it once you initialize the graphics over here. But it's going to be hassled because you're going to have to write, begin drawings and draw again just to add this. So it's much easier to just add it to this because it becomes one more line. And now if I run this, it should work. So now as the spiral goes around, it won't overlap. So the shadow will never overlap the main graphic. Let's add more spirals so it fills the page. So you can see how the shadow effect the whole design. After running this for a bit, you can start seeing a little bit more depth and the design rather than just having something flat without that shadow, even though it's very simple and not very realistic, you still see a little bit of dimension to something like this can add a lot of interests to some of the designs that you have. So if you ever feel like your designs are a little bit flat, then just add some simple shadow by offsetting the same shape and see if that fixes it. That's pretty much it for the last texturing technique. Next, we'll discuss the last coloring technique, and that is using masks.
10. Color 04: Color with masks: For the final coloring technique, we're going to discuss masks. If you're familiar with Photoshop mask, then this should be a piece of cake. Otherwise, just follow along and it'll be easy to understand. Now the idea of using masks as a way to color your design isn't necessarily very conventional. But the way I see it as that you can code anything that you want, any graphics that you want, Let's say just random circles on the screen. And then you can use that to mask a background layer that you created of other random circles. So that way, it looks like the design on top, which is the mask, is being colored by the underlying layer. Reason behind putting this as a coloring technique is because whenever I used masks in Photoshop, I always felt like it is a way to reveal something for my shape or for my mask. So let's say you have silhouette of a dancer and then you want to put a background of stars that is a way of coloring that silhouette. It's not just black or whatever color that the photograph had. So the concept is very simple and the coda is as well. Now for masks, you're going to need either p graphics or images. So let's say you have an image or black and white image that you want to use as a mask. You can import that or load that as an image into processing and use that as a mask. But for this example, we're only going to use P graphics. So we're going to create the mask using generative art and also the background layer, which is going to be our color here. We'll first start with just one shape in each of the layers, just to show you how the mask work. The first one I'm going to call mask, and the second one I'm going to just call G and then we'll initialize it over here. So for mask, and there's going to create a graphics like just we did. The previous lesson is going to be the same width as the canvas and the same height. The same goes for the graphics layer. And now we can draw our shapes inside of each one of them. So to draw in any PPE graphics layer, you're going to need the begin draw method and the draw method. And you'll always have to reference the graphic layer. So the variable, the name of the graphics layer. So here the p graphics layer that we created is called mask. So we're going to have to reference it over and over again. So even for the stroke, for the fill, for the shapes that you're going to draw it. You're always going to have to reference mask. That is, if you want to draw it inside of the mask, if you want to draw it inside of G, are going to have to reference that G. And now I'm going to draw just a circle. And this will require an x position, y position, and then a width. And to dry, we'll just use the image and reference that layer and then position it. And because it's the same width as our canvas, then we'll just put it at 000 so it fits the canvas. Now if I run this, we should see that circle. Next we're going to create this one. So it's also going to start with the beginning draw and then draw. And then I'll also draw a circle. I'll make it a little bit bigger, just so and we mask it, you'll see that it gets smaller because this mask is going to cut it off. And then we'll draw it the same way that we drew the mask. And now this is the graphics layer, the G graphic layer, and it's on top of the mask. Let's change the colors of the two by using one of the colors from my color array. I did use the same one that I've used before in the other lessons. And to add a color to our graphics layer, you just do fill. So the same way as we do it in here, inside of the whole sketch, the only difference is that we're trapping it inside of this layer. Instead of just putting it on the main graphics layer, I'll just choose any of the colors. It doesn't really matter right now. And I'll also do noStroke for both of them. Because for the mask layer, if you use masks before, for white or anything that is white is going to show whatever is underneath it, and then black is going to hide everything else. So if you have a circle that is white with a stroke of black, then. Whatever comes near that stroke is going to be hidden. So I'll just do a no stroke because I don't want it to interfere with a masking. Now that we know how they look or how the mask looks, we can just remove it over here and we can go before we draw the image, I can just do g dot mask. Using the mask. So whatever I want to mask, I'll just use the mask method on that and then I'll use the mask layer. And if I run it, it should be smaller now because the mask has cut this shape. But if you look closely, then you'll see that it's a little chunky. And the reason for this as because we don't have a background for the layer or for any of the layers. So for the mask layer, Let's add a background of black because we want to hide anything there, because if we put it to be white, then everything will be shown. So I'll just do 0 for black now, images much crisper because we've reset the background and we can do the same thing for this one. However, this is not going to show over here because the mask is smaller than this layer which is trying to mask. However, if the circle is smaller than, we'll be able to see the color behind it. So if I put a background that is red, or let's say that as a color from the array. So let's say the second color in the array. And then I'll make this much smaller. So I'll make this bigger, and then I'll make this a 100. So I just switched the sizes. And now if I run it, I actually see the background layer for this graphics layer. So we've colored our circle inside of the mask using whatever is in the background. For this example, it seems counter-intuitive to create all of this just to create two circles of different colors that we could have created using just two lines of code. However, this is going to be beneficial if you have something moving in the background and you just want a mascot with a bunch of random circles on top. So if I go back to each of these layers and instead of just creating one circle for each, I'll create a bunch of circles there. For this one, we'll create an array. And let's give it just a random counts that I will initialize over here. I'll keep them all the same size for now. But you can randomize the sizes as well. So if I just remove the mask for a little bit and randomize the positions from 0 to width and then from 0 to height. Or you can also, if you define this as a radius over here, then he can do from relates to diameter because that's what's it, what it actually is. And then from diameter divided by two to what? Minus diameter divided by two. And the same goes over here. And now we have a bunch of circles. So let's actually give them different colors. And let's make the background color. The one I defined over here, so the blue doesn't hide. Let's increase this to maybe 50. So we have a lot more. Now, if I reveal the mask layer, we should be able to see a different way of coloring that circle. Let's also create the same for the mask. And let's make it smaller. Instead of having just one circle, we'll do random ones and we don't need the random fill because we need them all to be white in order to show what's underneath it. And let's redefine this over here so we don't have duplicates. And I forgot to change this to mask. Now it should work. And the reason why this is happening where you're not actually seeing where things start and end is because my background for the actual canvas is the same color as the background for this graphics layer. So if I change this to, let's say 30, who's going to be a dark gray color. And you'll be able to see the mask and the underlying layer. And let's also create a different count for masks. So this is why I added this as a coloring technique because you can see that whatever shape that you create in the mask layer, whatever design, whether it's moving or static, then you'll be able to color it in unique ways because you're using another layer that can actually move as well if you want it to be animated. But for this example, we're only doing static images. There's another example or another way I want to show you how we can mask this. So instead of just random circles, we're going to create a column of lines. It's not going to be different. It's just a different example that I want to show. Instead of this, we'll go into do line. And it's not going to have a no stroke method on this one, but it's going to have a no fill. But even if I don't put this one because lines only take stroke, this won't affect anything. But I just like to have it in case I change anything or rehear or add anything that will require a fill and I don't want it to have a fill. So I'll create a line or actually let's keep C circle. And then I'll just comment it out and I'll create a line over here. So I want each of the lines to go from 0 to the width and then span across the height of the screen. So I'll only need a cell height or I need to define a cell height based on the counter that I have. So I'll just do float. Cell height is going to equal the height of the screen divided by the float of m count. That is, if I didn't make it float, Yeah, I made them integers. And then for the expositions, it's going to be static. The only thing that is going to change is the y position. So for x, we're going from 0 to the width. And then I'll add the y. For each of the sides are free each point of the line. So we'll do I multiplied by the cell height. And the same goes over here. And because stroke is by default black, so this is not going to show anything. I'll have to change mask to mask, stroke to white. And it will also define the stroke weight based on the cell height. So I'll do cell height divided by two because I don't want it to cover the whole screen. If I put it as cell height bend and we'll just cover the whole screen, show the whole background layer. And then we can also show it over here just to check how it looks before we use the mask. So let's reduce the number of counts. If I make it 10 and add a margin as well. So I'll put it over here. And the reason why I'm putting these on top of my shapes that I'm creating is just because I want it to be closed. So I know that they belong to this one and I know that I won't change them anywhere else. It's going to be only for this one, but feel free to put them over here as global variables. So for margin, let's do 50 and then I'll make this go from margin and then width minus margin. And then I want this to be pushed by cell height divided by two. And the same goes for this. So you can also create a variable for this because we're duplicating now. And to keep our code clean, we should just make it one variable. So I'm going to call it light position k. The merchants are too big, so let's make them 20. And now we don't have to show the mask and let's use the mask method. And voila, using masks is really fun in generative art because you're able to generate the mask and the background layer at the same time and use one to hide the other. I also have a YouTube tutorial on something animated, be in the background behind those masks. So if you're interested in seeing how that is created, then just go and check that video out. But for these examples, I'm trying to make them static just to focus on the techniques more than focusing on the animation or complicate the examples. That's all we have to learn today about these coloring and texturing technique. For the next lesson, we're going to create a project utilizing some of the techniques that we've used the in the lessons.
11. Final Project: Now that we're done with all of the techniques, we're going to dive into a project. So for your project, you're going to combine two to three techniques from the lessons before this, either by using one of many examples from one of the lessons and adding another technique to it or coming up with your own example. So for my project, I'm going to combine shadows and the first texturing technique, which is creating my own shapes. And I'll be creating random papers scattered on the screen. So I'll, papers are not going to be regular rectangles. Some of them are going to be torn papers, knowing that the paper is a rectangular shape, most of the time, I'm going to create a function that has four parameters to start with, and I'll just call it paper. So the four parameters are going to be the same as any rectangle. To float x, float y, floats width, and float left, because I want some of the paper to be torn from the bottom edge. I'm going to create the paper using vertices. And that always starts with Begin shape and ends with an shape. So I'll start with that. And then further vertices. The first one is going to be from the top-left corner, and that'll be our main X and Y position. So that's x and y. And then we will move to the right and then down to the left, and then we'll close the shape. So to go to the right, that means we're going to move by the width from the exposition. So we're going to add W or the width here. Do the exposition and then y is going to stay the same. And then for the third one, we're going to stay where we are at right now, on the x-axis and then on the y-axis we're getting to add the height because we're going down. And finally, I'm going to go back to the left, but we're so Dan, so on the x-axis we're going back to x, but on the y-axis we're going to stick with the same one that we had before. And now let's color up here. So let's put it at 00, and then let's make it a 100 by a 100 and 150. So this is what a rectangular normal paper looks like. But we want to add a tear down here to the paper for that. Remembering from the first lesson, I know that I'm getting to need a resolution to now how many points I'm going to need for the tariffs. And also I require to initialize the positions of each of the points so I can connect them to the first and last because I'm going to use curved vertices instead of vertices. And knowing from the first lesson we're going to need some control points before are some of the core vertices in order to see that point. So I'm going to create a p vector array. I'm going to call it positions or POS. And then it's going to be of length resolution. And this has to be an integer because this won't allow anything but an integer. And then I'm going to need the spacing between each of these points. Kind of like creating a grid. So end the circle. In the first lesson we had to do the angle, but for this one we're just going to do the spaces between each point. And we can simply do that by creating a variable. And it's going to be the width of the paper divided by the float of the resolution. And we're converting those to float because we want a more accurate division. And then we're going to use a for loop to create those positions. So the exposition for each one of these is going to be, I multiply it by the spacing. So exactly like creating a grid. And the y position for this one is going to be the height. This one. Now I'm going to create those positions by creating a new instance of the p vector class and adding each one in their respective x position and y position. Now that this is initialized, we can use it over here. So this will go in the same space as this one. But because I also want this to exist, I'm going to create an if conditional over here. And I'm going to check if resolution is greater than 0, then I want to do the curve vertices. Otherwise, I wanted to do this. So if resolution equals 0, then I want this to happen otherwise. And just eliminates any negative values I'm going to do else, if Raz is greater than 0, you can also do the opposite, but this is just to eliminate any negative values. Now we're going to create a for loop. But because we're going from right to left over here, we're going to go from the last position in the array to the first position. And that will be if I equals resolution minus1. So the final position in the array to I, or the condition is going to be if I is greater equal 0, so we're going to go down to 0, and then we're going to decrement instead of incrementing. This is just going the opposite way of our normal for loop. And now we're going to call the curve red text method. And this is going to be position I dot x and then position I got y. So getting the p vector and then getting the exposition, and then getting the y position for the y. And now let's add the fifth parameter or argument in our paper method. And let's try 0 just to make sure that everything is working fine. And then let's try five also before we continue in and shape because we haven't closed the shape, we can just call clothes. And it'll go from the last point to the first. And now you'll see that it's closing. But we have a problem over here because we don't have a curve vertex at the end over here that connects with this one. So I'll just call curved vertex over here at the end. And that will be position 0, x, and y. And now we have a rectangle. The reason why we don't need one before this one over here, like we did with the circle, is because we already have vertices before it. So B's count as, or this one specifically counts as the other control point for the current vertex or the previous control point for the first curve vertex over here. Now to see that we actually have several points over here, you can either change the color of the vertices over here, or what we're going to do is add a Y offset and we do it over here. So Y offset is going to be a random value from negative two to two. And then we'll add it to this one. Now if I increase this to 15, I'll see more. I want to do something a little bit more fancy. And that is adding a sine wave to the Y offsets. In addition to the randomization. For that, I'm going to add two variables that you usually use with any sinewave, and that will be frequency. And I'll give it a value of a 100 and then amplitude. And I'll give that a value of five. And then adding to this, we're doing a sine wave. Because I want the wave to go across the bottom of the page. I'm going to multiply i by the frequency for the angle. And then I'm going to multiply that by the amplitude. And you don't need to put this in parentheses because multiplication will happen before any addition. So there's a hierarchy here that we don't need parentheses four. And now if I run this, we should have a sine wave. So if I reduce this to five, we get a sine wave. If I increase this to 115, this to 200, and then I increase this to 15. Now, we can see the sine wave a little better. Now if you want the amplitude to be higher, you can just increase this. And the amplitude is basically the height of each of the waves. And then the frequency is how frequent the wave is. So if we have it at 200, then we'll get more waves. And if we have it at 50 will get less waves. I'll keep it at a hundreds and this at five. And our resembles drawn paper. Now let's add more paper and randomize it across the screen. So I'll just couldn't inside of a loop. And I'll initialize count for the positions. I'm going to make them random from 0 to the width and then random from 0 to the height. If I run this, it's going to be a mess because we also forgot to add x and y to these positions. So you can either add over here plus x or you can add up over here. And this is going to add y. And now if I run this, it should work perfectly fine. Now for the shadow, I'm going to add this whole thing again. But with an offset, you can create one function to create the paper shape and then the shadow for it. But I'm just going to do it inside of my paper methods. And as we know, the shadow has to go first because whatever go first, it'll be below the code that comes after. So this is going to be the shadow and I'm going to offset it by using push and pop. And then using the translate methods, some isolating the movement for this or the translation for this one. And then I'll do translate and we'll do an x offset and y offset. So let's do 33. And then also, the reason why you use to Persian not push matrix is because this allows me to push the styles and the translation or the transformation. And then I'm going to add the fill. So for the shadow, the fill is going to be this color. And then my paper is getting to be white. Now if I run this, we should see a shadow forming. And then up here I'll do noStroke for all of them. Also, the shadow makes the paper visible against the background, or kind of increases the contrast between the two. If your background is light color like mine, but if you want to use a stroke, then feel free to do so. Of course. Also I added color over here. If you want to, if you wanted to add different colors for the paper, I'm not going to use it. I just wanted to show you that you can do that if you want to. And then I added a, an array for a text colors if you want to randomize that as well. So I'll add another color to that later. So we can see that you can randomize the color for the text. We can also randomize the height of the paper. I'm going to call it paper height, and we'll add it over here. So paper height is going to be a random value and I'm going to make it from 180 to 30. And the width I'm going to keep fixed at 150. Now let's run this. And because we're drawing the papers from the top left corner, we're not going to see them going over the balance from the top where the left, but we're going to see them go to the right or down. So to eliminate that, I'm going to remove paper width from here and paper height from here. So I'll change this to paper width. It's good practice if you start seeing things repeating to just create a variable for them or a function. And for this, it'll be paper width equals 150. And now they shouldn't go outside the bounds. Now let's create the text inside of the papers. For that, I'm going to create a method called text. And it's going to have a number of lines. And I've sketched all of those beforehand so I know what parameters I need. So alanine a number of lines because I've randomized that. And then I'll also needs an exposition because I want to know where it starts inside of my paper. And then I'll need a y position. And of course, it's going to need a width and a height for each of the lines. And finally, I'm going to need side margins and top margins. And the reason why I'm separating those, because sometimes you see that top margins are a little bigger and some notebooks. So I'm going to have a side margin and then a top margin. And I fill them up with the colors over here. So I created another array that I call text colors. It only had one color before, but now I copied everything that was in here. We don't need this anymore, but if you want to have different colors for the paper as well, you can ads deeper colors. But I'm going to randomize and just the text colors. And I'll remove the background color because this is the same. So we don't have something or a paper like it's been cut out. So I'll just have those colors. And most of these colors are the same as the one that we've used before. You can pause and copy these colors as well. Now going back over here, I'm going to randomize the colors for the text. So each paper has a different color text. And for that I'm going to use exactly what I've used before with the randomization. So it's only going to the randomizing be Index. And it has to be an integer because random produces a float and that will be from 0 to the last position in the array, because we're going to have a bunch of lines. It's going to be similar to creating rows inside of a grid. So we'll create a loop that goes from 0 to the number of lines. Because it's only arose. We're just going to create a variable that I'm going to call text height. And that will be I multiply it by the height that I'd give it. So the height of each line. And they'll just draw a rectangle. So the rectangle is going to go from x plus side margin. So it's kinda of like pushing by the side margin that I initialize or that I will initialize over here with an argument. And then for y, it's going to be y plus texts height plus the top margin. So we're going to push each one of them by the text height. And it's going to be different each time because it's multiplied by the I. And then top margin is going to be the same, so it'll push everything down. And then the width minus side margin multiplied by two, because we're pushing it by one side margin, we're going to have to subtract two side margins from this side because it's going to be pushed by one. And then finally, it's going to have a height that is going to be specified over here. And let's push the width and height down so the code is much cleaner and easier to read. Now I'm going to call it inside of the paper methods. And I'll give it five lines. So I'm not going to randomize it at first. So you can see if there's any problems. And then it's going to take the same exposition as the paper, the same y position as the paper, same width as the paper. And then it's going to have a specific height. So I'm going to make five. And for the side margin, I'm going to make it 10. And then for the top margin, I'm going to make it 30. Now if I run this, we're going to see a slight problem in our code. And that is there's no line spacing. So there is no spacing between the lines. That is usually they're in real text. So we're going to have to multiply the text height over here by two. That will ensure that we have a text height and then a space between each of the lines that is equivalent to the text height. You can also create a different line spacing from the text height that you can specify. You can add it to the parameters over here. If you don't want it to have the same line spacing as the text height. But I'm going to keep it the same. And now if I run it, we're going to see a better text. But I think it will look nicer if I randomize this. So because we have an integer, we're going to have to cast it into an integer and m going to make it a random number from two to seven, let's say. And now it's a little bit more realistic. I mean, it's still very graphic and not realistic. But I think if you randomize something like this, it'll look nicer. And I will also reduce the number of paper over here. And then I'll add some rotation to the paper. Usually if you see a stack of paper on the floor or on a table, It's not going to have the same rotation. So I'm going to do that using push and pop for a transformation. So I'll just do push and you can do push matrix because we're not going to do styles over here. And then also I'm going to clean this up and then I'll add the pop method. And then over here, I'm going to translate first. And I'm going to translate to these positions. So this is going to be 0, 0. Now we can bring this back. And the reason why I'm translating is because rotation is going to rotate from the corner of the page. And if I don't translate for each of the paper, then it's going to rotate from the zero-zero point of the canvas. So what I'm doing over here, I'm pushing the canvas to the corner of the paper instead. So when I rotate, I'm going to rotate the paper from that point. Now if I do rotate and I'll do a random rotation from negative quarter pi. True quarter pi. Because, because I don't need that much rotation, you can also do a full rotation if you want. So let's run it and see what happens. Now it looks more natural. So even if I have 10, it won't look way too crowded. Lastly, I'm going to randomize the type of papers I have to. I don't want them all to have terrorism them. I want some of them to be pristine. So I'm going to create a random number only have two states. So one is going to be if r is greater than 0.5. So it's going to be a 50 percent chance for each type of paper to appear. And this one is going to be the same, but with a resolution of 0. And now I have some full paper and some torn paper, and that's pretty much it. I've used do the techniques that we learned in the lessons. One is adding texture to your shapes and the other one is adding shadows for more depth. Now it's your turn to create your own project. Choose two to three techniques to create one of the examples that we've created in any of the lessons or to make your own projects like I did over here. You don't need to use one coloring technique and one texture technique. But if that's what you wanna do, then please do it. But feel free to choose any of them so you can do sweet extreme technique or even three coloring technique in the end. So in this example, if I wanted to add another coloring technique, I would add the masks and grab a paper image or a paper texture and added to each of the papers. That way you can have a different color for the papers from the white with a little bit of texture. So in the masks coloring technique we used to peak graphics, one for the mask and one for the shapes. But for this example, if I wanted to add a paper texture, then the mask is going to be the P graphic in the shape or whatever is going to be massed is going to be paper or the texture that you're going to load as an image into your projects. If you want to follow this project for your final project, you'll fear to do so, but I would recommend adding another dimension to it. Another thing I could have added to this project is background elements, like a grid, for instance, to create a tiled floor. You can also add a background image of wooden floor or any texture table. And you can definitely color this with any of the coding technique. Maybe not the coloring by the background, but if you want to have different terms for the paper, maybe you can use the color interpolation methods with some randomization like we did in the first coloring technique. Or you can do coloring by distance to maybe give tonal differences in the paper color, but not necessarily with random color interpolation, kind of mimicking sunlight going into the room and coloring some of the papers of different color. And of course, all of these are not very realistic, but still, it's something to add to your artwork. Finally, if you have any questions regarding this lesson or any of the other lessons, please let me know in the discussion below. Otherwise, I can't wait to see your projects. Thank you very much for taking this course, and I'll see you in another one.