The Palau flag and the perfect circle
This lecture is dedicated to our Palauan viewers and to the perfect arc (also known as circle). In this lecture we continue the flag creation we started in the last lecture. By the end of this lecture will will have the complete flag of Palau and will create a perfect arc %u2013 more commonly known as a circle.
Keynotes:
- Working with the arc method.
- Creating a perfect circle.
- Creating the Palau Flag.
Video Transcript
00:00In the last lesson we started drawing out a simple shape but that simple shape is going to be used to create the flag of Paolo and the next step for us is to learn how to work with the arc method and create the perfect circle.
00:13Through that we're going to create the flag of Paolo. So let's jump right into it.
00:18So let's continue and actually create the full actual flag.
00:22And we're getting very close. If we take a peek at the flag itself we have the rectangle and within we have here the circle so let's go ahead and create a circle.
00:32To create a circle before we even do that we're going to go ahead and change the color and we're going to change the color to be the color of the flag.
00:39So the color of the circle and the flag I already have that pre-saved is that yellowy tone and there we go that's that yellowy tone color.
00:48Last contrary to the first item where you saw the method that we were creating which was a fill rectangle which literally filled out the object.
00:57There is no method or built-in method that's called fill circle.
01:01What we do have is something that's called an arc. Now an arc does not fill anything and we're going to take a look deep look at that shortly.
01:08But what we're actually doing is we're just defining the region that we want to paint in.
01:13To define this region we're going to accept a few properties.
01:16The first two properties are the coordinates where we're going to start from, the x and y coordinates.
01:22In our case where do we want our image to start from? Our x position is a little bit offset to the middle while the y is slapped right exactly in the middle.
01:33So to do that I'm going to go ahead and take the full width and just divide it by 2.4 so it's a little bit offset of the middle.
01:40And I'm going to go ahead and set my h, my height itself, or my y position to be half of the height.
01:46So that way I'm slapped there in the center.
01:49The next coordinate, the next property that we're going to be looking into is the radius.
01:54So that's the third property.
01:56The radius itself that we want if we take a peek into our design again is roughly, we're talking about just this edge,
02:03then we're talking about roughly maybe a fifth of our height.
02:07So if we have your half a circle, we have another half a circle here, maybe another half a circle here, so it's really a quarter.
02:13Yeah, it's more like a quarter of the height of our element.
02:17So if it's about a quarter of the height, let's go ahead and find the height and we're going to divide it by 4.
02:23And we're going to play around with those values shortly.
02:26The next two properties, just bear with me on this, is zero for angles, the starting angle and closing angle.
02:34Now, a lot of times you'll see in programming that angles are not defined in angles literally 360, which is zero to 360,
02:41which is what we humans tend to look at things and think of them in that way.
02:46In programming many times, you will have your definitions sorted by a pie.
02:52Now, a pie is basically half a circle.
02:56So two pies would be a complete circle.
02:58If I set it only to half a circle, then I would create there a half a circle.
03:02In this case, I want to basically go through the full gamut really from zero to zero or from zero to 360,
03:08but more accurately twice pie, which would be the value that we'd use in programming.
03:12And last but not least, I'm going to set here false, which is a property for counterclockwise,
03:17which doesn't really matter for us too much here.
03:19It doesn't really matter if we set here true or false because we have a closed shape.
03:22But in general, what it does is defines to what direction does our animation go.
03:28Is it going from right to left or left to right clockwise, which is our case, or counterclockwise?
03:34Now, if I go ahead and save this and just refresh, nothing will happen.
03:38The reason nothing will happen is because we did not actually fill out that drawing.
03:43Contrary to the rectangle, which when we created it, we immediately drew it out.
03:48I'm going to go ahead and just delete that changes that we did up there.
03:51Contrary to that, when we created an arc, we don't also draw it at the same time.
03:55And to do that, we have one last thing left to do to call a function, which is called fill a method.
04:01And literally, the fill fills out whatever lines we just filled out.
04:06So this imaginary circle we created at this stage.
04:09Now we're ready to draw it, which literally means that we could draw a lot more complex things
04:13and then draw them out, which is definitely something we're going to see throughout this title.
04:17So let me go ahead and click on save and click on refresh.
04:20And I believe that at this stage, we'll have the flag of Palau, not 100% accurate, but quite close to that.
04:26Maybe the circle is a tad too small.
04:28So if we're looking at this, we maybe would want to maybe grow it a little bit further.
04:33So we might want to, instead of defining it to be a fourth, we might try it out and say,
04:38hey, let's try it to be a third of the height and let's give that a try.
04:42But really, the right size is probably going to be around that area.
04:45So I'm not going to be too accurate.
04:48This is going to be accurate enough for me.
04:50And we've just created the flag of Palau.
04:53And with it, we were introduced to how to work with the basics of Canvas.
04:58In this lesson, we completed creating the flag of Palau, the first operational example of Canvas.
05:05In the next lesson, we're going to be creating Canvas elements dynamically,
05:09going back into that wrapper API, seeing how do we generate a new Canvas dynamically.
