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

Using the Builtin Shapes

use the built in shapes and reduce your work load there are many predefined shapes such as squares and ovals.

Video Transcript

00:00Now, we've seen all these good stuff, and don't worry, I've saved everything, so you could always go back and actually look at it again.
00:05I'm going to keep the lines that are the same. I'm going to do the begin fill again the same way,
00:09but I want to create a really perfect circle to do that. Luckily for me, there's actually a built-in option of doing that.
00:16So I could go to my graphics.draw, and I could find between a circle and a clips,
00:24and other graphical data, which our interest right now is a rectangle, a round rectangle.
00:31We're not going to go into every single example. Let's start with draw circle.
00:35Draw circle is very simple. It asks me for a coordinate. Let's say I want to go to 100 and 100, and I want to give it a radius of 10.
00:43That's all I had to do. I could end everything with a nice little end fill, run my application,
00:51and I've just created a little small circle. No issues at all. Very, very easy.
00:56Next step that I want to do after I created my fill is to actually add to it maybe more stuff.
01:04So let's add maybe also a rectangle. To add a rectangle, I'm just going to make sure that I'm changing a color.
01:11I'm going to begin fill all over again. This time around, we're going to pick another random value.
01:19Let's see what value that gives us. And this time around, we could create a draw graphic.
01:27We're going to do a rectangle. Rectangle is very similar. We're going to first give it the position where we want to start from.
01:33Let's say this time we want to start from 300. Well, our X of 100, but 400 for our Y, and we want our width to be 10.
01:41We want our height to be 20. That's all we really had to do. And if we run our application one more time,
01:46we're going to see that we should have a square somewhere. Maybe it's out of the screen. There we go.
01:53It's out of the screen. So let's make sure we make it smaller, our Y position, so we could actually find it.
01:59So let's change actually. Instead of that, we'll make an X position of 250, and we'll keep our Y position in the exact same spot.
02:08There we go. So here's our rectangle. And just last examples, I'm going to do another fill.
02:13And this time around, I'm just going to make sure that the color is actually dramatically different.
02:17So let's go for a completely black box. And now, well, then we won't be able to see that, right?
02:24So maybe not. So let's make it RGB blue. We haven't done a complete blue one yet. So let's try the next one.
02:30Let's try it. This is the last built in ones that we're going to look at. Obviously, I encourage you to take a deeper look into them.
02:36They're very easy to work with. Let's go and try maybe the round rectangle.
02:42Round rectangle works very similarly to rectangle. It expects a starting position, so let's give it 200, 200.
02:51For our XY positions, let's give it a width of 40, a height of 40. Now we want to know what will be the width of the ellipse,
02:59which is basically the corners of our rectangle. The bigger it is, the more dramatic the curve will be.
03:06So let's start with zero just to see that in action. So for the width and the height.
03:10If we run it, we shouldn't see anything dramatic in the curves, right? We maybe see a little bit of a hint that there are curves there.
03:17But let's start making it more dramatic. So let's give it an equal value first. Let's say 5, 5 for the curves.
03:22And you could start seeing the curves getting more interesting. Let me make even the square bigger.
03:28So we're going to come here and make our square 100 by 100. Obviously, the curves remain the same.
03:35And let's make our curves now even bigger. Let's say 25 by 25, which is still doable, but almost not doable, right?
03:42Because 25 times 4 is already 100. 25 times 2 is 50. It seems about right.
03:47So it should take about half of our square in area for the curves themselves, but it looks beautiful.
03:57Now what happens if we make it even bigger? This is just me tinkering around.
04:03So obviously, it still works. You could play with it, figure out the number that makes you the happiest.
04:09And that's all we really have to talk about. The built-in one is very easy to work with.
04:14And we should move on to the next topic.

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!