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

Overlapping shapes to create other shapes

There are many flags and many shapes in general that can be created by combining the shapes we created so far. One of the most popular shapes in 82 flags we don't know how to create is the crescent shape like the one in the flag of Turkey. With it we learn a new skill of using subtraction to create more in-depth shapes.

Keynotes:

  • Practice makes perfect
  • Working with arcs.
  • Overlapping shapes to create more complex shapes.

Video Transcript

00:00It's time for us to do something
00:01that is a little bit more simple,
00:03but we'll create with it really complicated shapes.
00:07What we're gonna do is we're gonna overlap shapes
00:09to create other shapes, more complicated shapes.
00:12The way we do that is really practice,
00:14and we're gonna look through
00:16how to work with arcs as well again,
00:18but our process and our main role and our main goal
00:22is to showcase how do you overlap shapes
00:24to create a complicated shape.
00:26So with that said, let's just jump right into it.
00:30I prepared the stage, prepared, I prepared the stage.
00:34It's nice and red.
00:36Guess what flag we're doing now?
00:37You guessed it, did you?
00:39No, you didn't.
00:40Well, we're doing the flag of Turkey now.
00:43Now it's gonna be really easy
00:44because we already created a really complicated shape,
00:47so it's gonna be a little bit easier.
00:49We're really gonna talk about
00:50how do you create this weird-looking shape?
00:53Easier than you think
00:55if you don't really see a solution yet.
00:58We already have a logic
00:59to create the stars.
01:00Let's go ahead and start building this out.
01:01Let's start with the logic of creating overlays,
01:05and that's really what we're gonna do,
01:06because if you think about it
01:08and try to do that when you're creating and drawing things,
01:10you'll see that we have your circle
01:12that is being hidden by another circle,
01:15the crescent shape,
01:15and by the way, with this creation of this shape,
01:18you could create, I think, about 83 flags
01:20that have that shape in them,
01:21which is quite a lot of flags.
01:23All right, so let's break into it,
01:25and in general, shapes,
01:26a lot of shapes that might look complicated
01:29are really just that,
01:30a combination of more simple shapes combined together.
01:34All right, so I already pre-configured our beginning line.
01:36We have already this really beautiful red in the background,
01:40and let's go ahead and start drawing,
01:42and to do that, I'm gonna set a new style color.
01:44This time around, we're gonna go for white,
01:47because we need a drawing white,
01:49so that's our white,
01:51and let's go ahead and start by starting a new path,
01:55and let's move right into our circle,
01:57and we've created circles before,
01:59and we worked with the arc before,
02:01and oh, I'm gonna need a few helper variables,
02:03so let's go ahead and do that.
02:04First of all, let's start with the most basic one,
02:06which is our x and y,
02:07which normally usually is just our width divided by two,
02:11and for our y, our default is the center stage,
02:15the height divided by two.
02:17It gives us a little bit of a reference,
02:18and now our big circle,
02:20that's the radius that I'm looking for,
02:22and if I'm looking at this,
02:23and I'm just eyeing this,
02:24I'm sure you could be more accurate,
02:26what I see here is this larger circle
02:29is roughly the size,
02:30if I put it one next to each other,
02:32I think you would roughly get two circles
02:34to cover the whole area,
02:36so I'm just gonna assume that the radius
02:37is basically a fourth of our height,
02:41so I'm gonna go ahead there
02:42and set the radius to be a fourth of the height,
02:44and it might be not accurate,
02:46so if you're big on to being really, really accurate,
02:49or you need to be really accurate,
02:50then just measure and get it to be really perfect.
02:54Okay, so the first step with our arc,
02:56now that we have our helper variables,
02:58is we wanna go to our x-coordinate,
03:00but not only do we wanna go to our x-coordinate,
03:02which is basically right here,
03:04we wanna push it by our radius,
03:06because we want our circle to actually
03:07be drawn out, aligned to our center,
03:11so I'm gonna go ahead here
03:12and just subtract our radius from our x-position,
03:15our y is exactly in the center,
03:17so we don't have to do anything about it,
03:18our radius, we're already pre-configured,
03:21and this part is kind of like almost automatic,
03:23we wanna go through the full 360 degrees,
03:27so I'm gonna go ahead and call the math pi,
03:29and set it from zero to two pis, two math pis,
03:33and last but not least,
03:34do we wanna go counterclockwise or clockwise,
03:38doesn't really matter,
03:39because in our case, we're creating a full circle,
03:42and we're ready for our closing of the path,
03:46and we're ready to fill it out,
03:49and already we have our first shape,
03:51and if we go ahead and just click on refresh,
03:53we should have our beautiful circle
03:54sitting there exactly where we want it to be.
03:57The next stage is we wanna create a circle
03:59that is somewhat smaller,
04:01that will overlap and sit literally on the side here,
04:04so I'm gonna do that,
04:05and I'm just gonna go ahead here
04:06and just copy this whole logic set,
04:09and what I wanna do is once I've copied it,
04:11I wanna change the background color,
04:13so I already have that pre-configured,
04:15which is basically the same color of our full background.
04:19The next step after that,
04:21we wanna, really the logic here is almost the same,
04:24but I wanna go to my radius right now,
04:26because I'm really done working with it,
04:27and I wanna just go ahead and I'll do a math floor for this,
04:31and what I wanna do is I wanna basically take the radius,
04:33and I wanna duplicate it by zero dot 75,
04:36literally making it a quarter of its size smaller,
04:41that's what I'm doing.
04:42So now that I have a new radius,
04:43more or less the logic here is good,
04:46if I run this and I literally just run it
04:48after that duplication,
04:49I should more or less get the shape that I want,
04:52I'm only a little bit too tight here,
04:54and if I look at my image,
04:56I'll see that really what happens usually
04:58is that we're a little bit more overlapping,
05:00a lot little more,
05:01so our circles are not completely aligned,
05:03but it's a couple of pixels,
05:05I don't wanna manually put here a couple of pixels
05:07because we're gonna be resizing,
05:09so I'm resizing our canvas,
05:10I'm just gonna go ahead and duplicate it by maybe zero dot nine,
05:14literally it's gonna be a couple of pixels
05:16that is gonna be less than I'm going back,
05:18depending on the size of our canvas element,
05:21and if I go ahead here and click on refresh,
05:23I should have here the flag of Turkey almost complete,
05:26we're getting really, really close.
05:28The next step is to add our star,
05:30and I already created the star logic,
05:32so it's gonna be really easy for us to add it in.
05:35I'm gonna go ahead and again,
05:36make our radius smaller,
05:38because our star, when we think about it,
05:40is much smaller.
05:41Now this is, again,
05:42I'm not being an absolutist here,
05:44I'm not gonna be completely accurate,
05:47I'm not even trying to be,
05:48as long as it looks close enough,
05:49that's good for me.
05:50So let's create the star,
05:51we're gonna send in the context.
05:54We wanna send the X and Y coordinates,
05:55in this case I wanna take the X and Y coordinates
05:58that I created,
05:59but I wanna push it by the R,
06:01so we're offsetting,
06:02because if we again look at the image,
06:04we'll see that our star is not exactly centered,
06:06but it's pushed in.
06:08So I'm sending in the radius of our star.
06:11Okay, so now that I'm sending,
06:12send in our core or our larger radius,
06:16the next step is also to send the Y,
06:18which is gonna be the exact center,
06:19I'm not gonna change anything there.
06:21Now we're ready to send in the small radius
06:23and the large radius.
06:24For the small one,
06:25I'm gonna take our regular radius
06:26and just divide it by two by two,
06:28because I played around with it and it worked.
06:31We have five points for our star.
06:34We also know what color we want it to be,
06:36which is white,
06:37so I'm gonna go ahead here
06:37and send the white color as our next property.
06:40And last property,
06:42do we wanna also set here a stroke?
06:44No, so I'm gonna set it to be no.
06:46And do we wanna have a tilt?
06:47Absolutely.
06:48So let's start at first at zero.
06:50And oopsie, if I go there
06:51and I just click on refresh,
06:53our star should be there already,
06:54but it's not tilted correctly.
06:56So we're gonna also add a tilt here
06:58and the tilt,
06:59because I played around with it already,
07:0015 does the trick and voila,
07:04we just created the star of Turkey
07:07and you just created another star.
07:08So you are a star yourself.
07:12In this lesson,
07:12we really wrapped up this section
07:14by learning how to create complex shape
07:17by combining two simple shapes together.
07:20In the next lecture,
07:21which will be in the next section,
07:22the whole section is gonna be dedicated
07:25to curves and gradients.
07:28So we're gonna walk through
07:29and transition from curves into gradients,
07:31a really fascinating section.

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!