02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

Creating the Flag of Guyana

In the last lecture we created a utility function that could create triangles for us. In this lecture we will take advantage of this new utility function to create the flag of Guyana. In the process we will learn how to create relative designs that can easily scale.

Keynotes:

  • Creating relative resizable designs.
  • Utilizing our new fillTriangle function.
  • Creating the flag of Guyana.

Video Transcript

00:00Now that we have a triangle utility it's time for us to draw something really complicated with it
00:05And we're moving on to the most complicated creation
00:08We've made so far the flag of Guyana in the process
00:12We're going to also talk about how to create a design that is resizable because our canvas right now
00:18Although it has a specific size
00:19We kind of want it to be resizable and we're going to look at how to create resizable designs very very fascinating material
00:26We're going to utilize the fill triangle function, which we've created in the last lecture
00:32So let's go ahead and create the flag of Guyana
00:37Okay, now that we have our utility function
00:39It's time for us to start creating the flag of Guyana
00:42And you'll see that it's really contrived out of a lot of triangles
00:47Which is perfect because we've just created a triangle generator
00:51Let's go ahead and start creating it starting with creating this background color
00:55Alright, so I'm going to go into my code and let's go ahead right into our create Guyana
01:00And I'm just going to go ahead and delete our fill triangle function
01:03And I'm going to go ahead and start with defining inside of my context
01:09I'm going to go ahead and set my fill style
01:12And I'm going to set that style to be a shade of that green
01:16So I'm going to go ahead here and just paste the pre-configured color that I've set here previously
01:20And the next step is I'm going to go to my context fill rectangle
01:25And I'm going to fill up that rectangle
01:28Literally filling out the width and the height
01:30Creating a full bound of that color
01:33So if I go ahead here and click on refresh
01:35We'll see we'll have the full color taking the full screen width
01:39The next step for us to do if we take a look at our code
01:42We'll see the next step for us is to create a white triangle
01:45That would take through the whole section of the stage
01:49So let's go ahead and do that
01:50So I'm going to go ahead and create the fill triangle
01:53So I'm just going to go ahead here and just copy that method signature
01:57And I'm going to go ahead and start
01:59So fill triangle
02:00Step one is the context already have that sent
02:03The next step is we need to figure out and define our points
02:07So I'm going to start from our X coordinate
02:09The first coordinate will be zero, zero
02:11The next coordinate would probably be on the other side of the screen
02:15And that would be
02:17That would be roughly around the width of our screen
02:22And the next step would be half of our height
02:26So we're going to the center of the screen
02:28Next step, we're going to go all the way travel back
02:31And as we travel back, we're going to want to make sure
02:33That we're going back into that initial zone
02:36Initial area where it's going to be basically zero for our X
02:40And staying all the way to the bottom with our Y coordinate
02:44Literally sending in our Y
02:46Or really in this case, it's not Y
02:47But we want our height, full height, full height
02:50And the color that we're going to have defined
02:52They're already pre-configured, but it's actually white
02:54So that's easy enough
02:55One, two, three, four, five, six
02:57And we have ourselves a white triangle
02:59If I go ahead here and save this and just click on refresh
03:02We should be seeing now a triangle
03:04That's going to take over that full zone, that full section
03:08Beautiful
03:08The next step is another triangle
03:10That's just a smidgen smaller than the previous triangle
03:14That is a yellowy type of color
03:16All right, so let's go ahead and create it
03:17We're going to go right into my code there
03:19I'm going to copy this triangle
03:20Because it's literally basically the same triangle
03:23The only difference is that instead of starting from a zero coordinate
03:27We're going to want to start from for our X coordinate
03:29It's fine to stay at zero because it's invisible
03:32But for our, because it's behind the scenes
03:34If we take a look at it, we don't see the beginning of it
03:37But we want to do, we want to start from the beginning
03:39They're just pushing ourselves in by 10 pixels
03:41And in this one pushing ourselves probably double that amount
03:45So whatever width we define here
03:46We'd probably want to duplicate it
03:48So I'm going to go ahead here and just create a helper variable
03:51And I'm going to call this line width
03:55Because it's really our gap
03:56Let's call this gap
03:58And our gap itself
03:59I'm just going to for now hard code it to be the value of 10
04:02So let me go ahead here
04:03First of all, if our gap is 10
04:05I'm going to go ahead here for our next triangle
04:07What do I want to do?
04:07I want to take it from the zero zero coordinate
04:11Instead of taking it to the full width
04:13I want to take it to that full width minus that value
04:16Minus that gap
04:18The next step again
04:19So we have here the X coordinate
04:21Minus the gap from the height perspective
04:23Do we want to change the height?
04:24No, it's the same height
04:25We want to take it to the same region
04:28OK, when we're traveling back
04:30Do we want to change anything beyond that?
04:32Not really
04:33But question is, do we want to start from the zero zero?
04:36Not really
04:36Because we don't want to have an overlap
04:38Again, if we take a look at our code
04:40We don't want it to start all the way from here
04:42We want to start it pushed down a little bit
04:44So we want to move down our Y coordinate
04:46Maybe around that 10 pixels as well
04:48Let's give it a shot
04:49So for our element here
04:50For our X
04:51For our Y coordinate
04:53We want to start with that gap
04:55And once we return
04:57We also want to make sure that we account that gap as well
05:00So again, so we're starting off with a gap of 10 pixels
05:03We're ending our width with a gap of 10 pixels
05:06And we're coming back with a gap of 10 pixels
05:08Now, I don't think this is going to be exactly accurate
05:11But we'll take a look and then we'll monitor it
05:13And we'll modify it
05:14Oh, and we have to make sure that we're also changing a color
05:17And let me just make sure also that in my view
05:20I have a word wrap so we could actually see everything
05:22And, you know, I mean, even I'll break a line here and just push it in
05:25So we'll have it all in one mega line more or less
05:29And I'm going to go ahead here and just add in the color of this yellow
05:33I'm going to copy paste already a color that I had pre-configured
05:36Which is FCD 116
05:39And I'm going to go ahead and save this and refresh
05:41So we could see the actual new triangle
05:43That was added in
05:45So you could see that we're very close
05:47But our problem is is that we're getting way too close here
05:50Our tip of our edge is getting too close to the rim
05:53Making our triangle get smaller in size as it's getting closer to the end
05:58Because we're creating here an angle that isn't accurate
06:01Now, I don't want to be overly accurate
06:03I'm going to go ahead here and instead of that just with my eye
06:07Go ahead and just play with it
06:08So I'm going to give it a shot with two and a half
06:11So basically making it 25
06:13A gap of 25 here in our last position of our width
06:18And I'm going to go ahead here and click on refresh
06:20And that should more or less work
06:21And I think it does
06:23And you could play around with that value further
06:26But let's continue down our path
06:27And notice how I made it dynamic
06:29But not really because I have here a hard-coded value gap
06:32Making it easier for you down the line to make this dynamic as well
06:36Maybe based on the width or the height
06:37And then you could find the really perfect ratio
06:43And it's not that hard to find that perfect ratio
06:45You could literally just go to the image
06:48Scale the image
06:49Check to see
06:49So if I'm on a Mac
06:50I'm just going to use your Command-Shift-4 to just define the width here
06:55So I see here
06:56I'll see here the color is about five
06:58The size is about 500
07:00And I could go ahead here and I could see that this is about 50
07:05So we're talking about 10% of our screen size
07:08And in this case, I could say, OK, if it's 10% of the screen size
07:11Then I want that duplication size to be 10% of the screen
07:16So if I grabbed a calculator really quickly
07:18Let me see if I have one here, a calculator
07:21And I'll grab a calculator
07:23I'm going to take the actual width itself
07:25And what do I want to do with it?
07:27Well, I could actually calculate this even without much more mathematics than this
07:31What I want to do is my gap itself would actually be the width
07:34Divided by 10
07:36But in my case, that is the width for this 2.5 one
07:40So I'm going to go ahead and also duplicate this
07:42Or more accurately divided by another 2.5
07:45Or by another 2.5
07:48Now, by doing this, I should roughly get the same proportions
07:51And if I go ahead here and click on refresh
07:53I should get the right proportions, which will be a lot more accurate than they were previously
07:58Making it really easy for me
07:59As I change the size of my canvas to stick to the same ratios
08:03Which obviously is an important thing
08:06Okay, so now that we've broached that
08:08Let's move on to the next triangle
08:10And the next triangle is a much more strict triangle
08:13It looks like it goes to the center of the screen
08:15And we're starting with a black triangle
08:18So let's go ahead there and create that black triangle
08:21So I'm going to go ahead and copy this triangle
08:24And let's go ahead and do that
08:26All right, so what are the next coordinates that we're going to use?
08:29The next coordinates are going to be roughly, again
08:32We have the beginning place will be our x coordinate and y coordinate
08:36We'll start from the top all the way on the top of our screen
08:40The end coordinates are going to be without a gap as well
08:43It's going to be with the zero and the full height
08:45And really all that's left for us to do is to play with the center point
08:48And our center point is quite simple
08:50We want to go to the center of our full application
08:52So our width and height would be slam smack in the middle
08:56And I'm going to go make sure that I'm sending here black
08:59And if I go ahead and click here on refresh
09:02I should get a little bit closer
09:03And now I'm going to have a triangle that's basically taking half of our screen
09:07Going exactly to that center point
09:09And again, all that's left for me to do is to create that internal triangle
09:13Which is red and will be basically done with this flag
09:17Not only basically will be done creating our third flag
09:20So let's go ahead here
09:21Let's add that last triangle
09:23And in this last triangle, the ratio is again
09:25We could go and look at it more accurately
09:29Just by looking at our element, looking at our design
09:33If I look at the flag itself, the flag here
09:35This is half of the size of the width
09:37Already we're in the half zone
09:39And then what is the value inside of here?
09:41I could go ahead and do a small measurement
09:43And I see here that this is roughly 25
09:46Or maybe a little bit more
09:48No, 23
09:49It's roughly I'm going to say it's 25
09:50Just for the sake of because if this was 50, let's say it was 25
09:54Now, if it was 25 and we have half of the screen
09:57Then I think roughly and we're really going through here
10:00If this was the gap and the gap
10:02Initial gap here was about 50
10:04Then it would be half of the gap
10:06So I'm going to go ahead and just assume that I want to half a gap
10:09Everything
10:10So I'm going to go ahead here and for my gap
10:12I'm just going to give it a try here
10:14I'm going to go first of all, starting from our 0, 0 coordinate
10:19And in our 0, 0 coordinate
10:20What I want to do, I'm going to go ahead and first
10:22Let me start with just putting the gap in, OK?
10:25So the last coordinate here would be the gap itself for our y coordinate
10:29Pushing us down a little bit
10:30And in our last item, I'm going to push the gap as well
10:33Basically the same thing that we've done above
10:36In the middle zone, contrary to that
10:38I want to make sure that I end my width minus that gap
10:42But not times 2 because that would be way too much
10:44Let's go ahead there and start just from a gap itself
10:47Literally not doing something too sophisticated
10:50And let's go ahead and see this and then tweak it
10:53So what I was doing here again
10:54I made sure that my y coordinates on both edges
10:57were taking into account
10:58Basically, if we look inside, we're basically pushing our y coordinate here
11:02Pushing our y coordinate here
11:04And last but not least, we want to push also the x coordinate
11:06Which will be the most important to be accurate
11:09So we have here a good balance
11:11So let's go ahead and let's save it
11:12And let's see what came out of it
11:14And I'm just going to make sure also that I'm sending in the right color
11:17Which was a shade of red
11:18And I'm going to go ahead here and put that in there pre-configured
11:23And let's go ahead and test this out
11:25And we'll see that again, our rectangle is almost perfect
11:28We could see that we're a little bit too generous here
11:32Or a little bit too generous with the size that it's going through
11:35Now we could play with this with our eye
11:37But I think more or less, if I go ahead in this gap
11:40And I just do times 1.5
11:43It should roughly be accurate
11:44And you could go ahead and be more accurate if you want to
11:47But I think this would more or less do it
11:50And we're going to have here our flag looking really fabulous
11:53Now, because everything here is relative
11:54Even if it's not 100% accurate
11:56Which it doesn't really matter many times
11:58As long as it's more or less accurate
12:00As we were done with this flag
12:02And we're going to start working on another flag
12:04If I go back up to that area where we create flags
12:07Inside of our create canvas
12:10Oh, not create canvas
12:11Inside of our do canvas
12:13And I'm going to go ahead here and just duplicate that creation process
12:17Only sending in another one of those smaller canvases
12:20If we go ahead and click on refresh
12:22We should see now our new extra canvas should be working
12:25And it should look really nicely and proportionate
12:28Even when we resize it and make it smaller
12:31So there we go
12:31We've just created another flag
12:33And with it, you now know how to create the flag of Guyana
12:38In this lecture, we created the flag of Guyana and threw it
12:41So how to create designs that are relative to the actual size of the canvas
12:46Making it easier for us to resize our canvas whenever we need to
12:50In the next lecture, we're going to take a look at an even more complicated shape
12:54A multi pointed shape
12:56Which is the kingdom of Bahrain

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!