00:01
Okay, so for this one, we're asking to do something very similar to the previous question, but instead of asking if two circles are intersecting, we're looking at two rectangles.
00:15
So i've copied over some of the boilerplate code from problem number six.
00:21
We're still going to create our window.
00:23
We've changed the title, so it's two rectangles now.
00:27
We create a label, and we initialize it to say two rectangles do not interpret.
00:31
Intersect, we create a canvas, packet, and then we bind to clicks and bind to motion, and we're going to call our little click handler down here.
00:48
To make the actual rectangles, we're going to specify the center points, x and y.
00:56
And then we're also going to have, i'm going to use half heights and half widths as the basic use units of measurement.
01:04
Since that'll allow us to find the corners easier.
01:07
We actually correct the rectangles, though.
01:09
We'll double those to get the actual height and width.
01:12
So let's put this first one at 100.
01:16
100.
01:18
We'll give it a half height of 25 and a half width of 40.
01:29
And we'll call it self.
01:30
1 equals rectangle 2d, x, y, height equals half height times two equals half width times two.
01:56
Okay, and then we're going to need to create the canvas rectangle.
02:01
So we're going to call that self dot x1 equals a rectangle.
02:13
We're going to pass x minus height width, half width, y minus half height x plus y plus half height and then we're going to create our little text label for it dot t1 equals self .canvus .crate text xyxx y at x equals r1 and for the second rectangle we are going to copy that we'll move it over so it's at 300.
03:08
Sorry, the x is at 300.
03:13
And we'll make this one slightly narrower.
03:23
Okay, that's going to be the same.
03:26
We're going to change all this to r2, r2, r2, and everything else will be the same.
03:40
Now for our click handler, again, i'm going to create a couple utility functions here.
03:47
We're going to have one that's called inside rectangle that takes a rectangle 2d parameter and then we're going to this function is going to check if the event happened inside the rectangle.
04:09
So to do that we're just going to find the distance from the center and then determine if that is less than half the height and half the width...