1
00:00:01,430 --> 00:00:07,850
Hi, welcome back in this video, we will drew a D building plan with Python.

2
00:00:09,530 --> 00:00:12,680
The outputs exactly will be this one in here.

3
00:00:12,860 --> 00:00:17,450
So that's a PNG image generated by running the script.

4
00:00:18,470 --> 00:00:20,390
It's a simple one room plan.

5
00:00:20,660 --> 00:00:27,110
So these are the walls of these is supposed to be the window small walls, and this is apparently the

6
00:00:27,110 --> 00:00:27,560
door.

7
00:00:28,520 --> 00:00:34,760
Normally, it has more details, but I wanted to keep it simple not to get the low sense of details

8
00:00:35,060 --> 00:00:39,620
into civil engineering detail so you can expand this if you want.

9
00:00:40,370 --> 00:00:44,570
You can even make this a batch process so you can create.

10
00:00:44,570 --> 00:00:50,000
You can generate multiple multiple P and G screenshots of different dimensions.

11
00:00:50,600 --> 00:00:56,390
And you can also drew all the figures not only in the field of of civil engineering, but you can do

12
00:00:56,390 --> 00:01:02,120
other things because the techniques we will be using are general techniques.

13
00:01:02,240 --> 00:01:05,870
So we'll be using two libraries to implement this.

14
00:01:06,020 --> 00:01:10,880
The first one is point all to gooey, and I covered PI out of the previous section.

15
00:01:11,300 --> 00:01:17,880
So it is used to control the moles so the cursor can be controlled by Python.

16
00:01:17,900 --> 00:01:21,980
It can draw things you can go and double click on a file.

17
00:01:22,160 --> 00:01:24,230
It can copy text and paste it.

18
00:01:25,040 --> 00:01:30,200
You can move the cursor to wherever you want via your Python script.

19
00:01:31,100 --> 00:01:36,950
So in this video particularly, we'll be controlling the cursor to draw on a canvas.

20
00:01:36,960 --> 00:01:38,270
So this is a program.

21
00:01:38,910 --> 00:01:43,690
And this is an online web app, its own as paint dot app.

22
00:01:43,700 --> 00:01:47,600
You can access it on that website and you can draw by hand.

23
00:01:48,800 --> 00:01:49,850
You can get the pencil.

24
00:01:50,420 --> 00:01:53,630
Make sure it's it's a black color and you can draw things.

25
00:01:53,870 --> 00:01:56,870
But we will be doing this drawing of via Python.

26
00:01:57,560 --> 00:02:06,890
And then we will be using a second library to produce the PNG image that a library is assessed and it's

27
00:02:06,890 --> 00:02:08,990
used to capture screenshots.

28
00:02:09,289 --> 00:02:16,430
So will be screenshots in the area where the drawing is, as you can see in the output here.

29
00:02:16,980 --> 00:02:19,790
MSRs was also covered in the previous section.

30
00:02:20,660 --> 00:02:23,060
So with that sets, let's get started.

31
00:02:23,510 --> 00:02:31,220
I have an empty file here where I'll be writing my Python script and here on the side, you should have

32
00:02:31,820 --> 00:02:34,820
an app that allows you to sketch.

33
00:02:35,540 --> 00:02:41,540
So I'll suggest if you don't have any app, I would suggest you go to this free painting app just being

34
00:02:41,540 --> 00:02:45,290
that app and keep it on the health of your screen.

35
00:02:45,290 --> 00:02:50,600
So on one hand, if you have Python, on the other hand, if you have this program or at least just

36
00:02:50,600 --> 00:02:52,130
keep it when you were on the script.

37
00:02:53,000 --> 00:02:58,070
So let's import PI altogether, and let's import from A.S. import.

38
00:02:59,710 --> 00:03:06,140
And assess and tools, these are all the third party functions that we need.

39
00:03:07,490 --> 00:03:12,950
And then we want to know why starting points of the drawing, so maybe it's somewhere in here.

40
00:03:13,730 --> 00:03:17,780
And of course, we want to know what pixels on my screen.

41
00:03:18,350 --> 00:03:19,920
This position has.

42
00:03:19,970 --> 00:03:28,040
So we want to know how many pixels from here to here and how many pixels from there.

43
00:03:29,360 --> 00:03:30,920
To hear someone here.

44
00:03:31,160 --> 00:03:39,980
So that's the ex ambassador, why we can get those using all go that position.

45
00:03:40,100 --> 00:03:43,100
So that's a method that will give us a position.

46
00:03:43,550 --> 00:03:50,240
You can print out the position and now to get the current position of a cursor, the cursor needs to

47
00:03:50,240 --> 00:03:53,660
stay at the position which coordinates you want to know.

48
00:03:54,200 --> 00:03:59,660
So if you put the cursor there and then you should find a way to execute the scripts using keyboard

49
00:03:59,660 --> 00:04:00,140
shortcuts.

50
00:04:00,770 --> 00:04:05,210
You don't want to move a cursor there because it will give us the coordinates for that point.

51
00:04:05,360 --> 00:04:14,360
So I'm going to keep the cursor here and switch to PI charm and then use shift control or in your case,

52
00:04:14,360 --> 00:04:21,200
could be a different shortcuts, depending on your I.D. the shortcut to run your script.

53
00:04:21,800 --> 00:04:28,160
So for me, it was, as you can see here, control or shift commands are as it is in here.

54
00:04:29,630 --> 00:04:33,740
So those are the positions that for now, I can move the cursor.

55
00:04:34,280 --> 00:04:36,830
Using PI automatically does move to.

56
00:04:37,220 --> 00:04:39,740
I can move the cursor to those coordinates.

57
00:04:40,700 --> 00:04:47,510
That's the X and three five five is the Y the duration.

58
00:04:47,510 --> 00:04:53,810
One second is going to be the time that the cursor moves from the current position to that position.

59
00:04:54,020 --> 00:04:59,960
So see now if I execute the scripts using this button, the cursor will move to that position.

60
00:05:00,620 --> 00:05:03,950
So it's important now not to move the windows.

61
00:05:04,400 --> 00:05:10,730
So this window, the drawing area should be staying here, so don't expand it or minimize it.

62
00:05:11,330 --> 00:05:17,060
All you can do is if you are sure that you take, it's about the same position as it is now.

63
00:05:19,260 --> 00:05:24,180
So once we've moved the cursor there, then we want to start drawing, so let's say we want to go down

64
00:05:24,180 --> 00:05:24,510
here.

65
00:05:26,560 --> 00:05:28,660
For that, I'm going to use pie altogether.

66
00:05:29,740 --> 00:05:38,440
First, I want to click with the malls and then pejoratively to drag, so I want to drag zero to hundreds.

67
00:05:39,040 --> 00:05:43,060
You can use whatever dimension you like outside just to just keep my dimensions.

68
00:05:43,300 --> 00:05:45,160
Not to get confused with numbers.

69
00:05:45,790 --> 00:05:53,140
So what that will do is this cursor moves there and then, oops, it's supposed to go down here.

70
00:05:53,140 --> 00:05:54,880
But it isn't because I forgot.

71
00:05:58,360 --> 00:06:06,640
The bottom arguments, which is left, so the left button of the mouse should be pressed.

72
00:06:07,150 --> 00:06:10,840
That's how you draw things in this canvas.

73
00:06:11,110 --> 00:06:13,840
You press the left button and then you drag the mouse.

74
00:06:14,170 --> 00:06:15,670
So that's what this method is doing.

75
00:06:15,670 --> 00:06:21,010
And let's also add the duration of zero point three.

76
00:06:21,010 --> 00:06:24,040
I think it's good, and let's try again.

77
00:06:26,690 --> 00:06:26,960
Yeah.

78
00:06:26,990 --> 00:06:31,550
So now we have a line that we want to go, writes, he writes.

79
00:06:32,600 --> 00:06:34,190
Sixty pixels.

80
00:06:36,260 --> 00:06:37,810
So pilots agree.

81
00:06:39,970 --> 00:06:46,480
So let me orient you a bit by adding some comments, maybe just here.

82
00:06:48,730 --> 00:06:49,150
Down.

83
00:06:50,220 --> 00:06:50,820
It's 100.

84
00:06:52,070 --> 00:06:56,360
Pixels and the next one is drag.

85
00:06:57,650 --> 00:06:58,320
60.

86
00:06:58,790 --> 00:07:05,540
So we're talking about ex going to the right 60 and the zero will not be moving because it's just a

87
00:07:05,540 --> 00:07:06,470
horizontal line.

88
00:07:06,800 --> 00:07:11,900
So 60 zero duration is equal to zero point three.

89
00:07:14,220 --> 00:07:17,600
Button is again left.

90
00:07:19,380 --> 00:07:20,370
And let's see.

91
00:07:22,400 --> 00:07:33,710
Down, left, sorry, right down and write six pixels of an we want to draw the window, so we want

92
00:07:33,710 --> 00:07:36,530
to go up maybe three pixels.

93
00:07:37,430 --> 00:07:39,380
So let me on do that.

94
00:07:40,580 --> 00:07:44,750
And so this was right.

95
00:07:45,950 --> 00:07:48,590
Six pixels and then we want to go.

96
00:07:52,330 --> 00:07:57,550
Down so zero x down would be three.

97
00:07:57,760 --> 00:08:01,390
If you go down or you can also go up and go like that.

98
00:08:01,810 --> 00:08:02,830
So let's go up.

99
00:08:03,010 --> 00:08:05,260
If you want to go up, it would be minus three.

100
00:08:08,050 --> 00:08:12,580
Because the ex or the origin is here and it's up here.

101
00:08:12,610 --> 00:08:15,970
So when you go down, it's plus when you go up, it's minus.

102
00:08:24,680 --> 00:08:28,790
So that's a beat up three pixels, and let's see.

103
00:08:31,070 --> 00:08:35,900
So we go down right up and then after that, we want to go.

104
00:08:36,860 --> 00:08:37,780
Maybe, right?

105
00:08:38,330 --> 00:08:44,390
But we could also go down six pixels, so three four, that's on another three.

106
00:08:45,770 --> 00:08:47,060
And we see.

107
00:08:50,040 --> 00:08:53,610
So zero, six four going down.

108
00:08:57,440 --> 00:08:58,400
Zero point three.

109
00:08:58,570 --> 00:09:05,780
Bottom is left again, so that would be done six pixels.

110
00:09:06,440 --> 00:09:11,450
It's not a problem that you're right, you're going at the same line.

111
00:09:11,450 --> 00:09:15,320
You are over drawing that same line there.

112
00:09:17,900 --> 00:09:24,330
If you prefer, you could also use the move methods to skip the drawing.

113
00:09:25,010 --> 00:09:30,680
But I wouldn't worry about that because we're not having any drawing problems, so I'll just use the

114
00:09:30,680 --> 00:09:31,400
track again.

115
00:09:31,940 --> 00:09:36,200
So down 60 and then once we're here, then we want to go, All right.

116
00:09:36,710 --> 00:09:40,040
So the dimension of the door will be 60.

117
00:09:40,820 --> 00:09:42,710
So let's see point also green.

118
00:09:43,100 --> 00:09:53,630
They'll drag 60 to the right and zero duration 0.3 button is left.

119
00:09:54,560 --> 00:09:55,370
So we're here.

120
00:09:55,370 --> 00:10:01,400
We go in this direction and then we go up six pixels.

121
00:10:01,550 --> 00:10:05,210
So let's do that as well duplicating this.

122
00:10:05,270 --> 00:10:09,230
So up six pixels, that means minus six for going up.

123
00:10:10,640 --> 00:10:14,150
So we should be here and then we should close that by going back here.

124
00:10:14,570 --> 00:10:18,500
So I'm going to duplicate this again and say for going back 60.

125
00:10:21,520 --> 00:10:21,930
Zero.

126
00:10:22,940 --> 00:10:24,110
So let's rise.

127
00:10:26,430 --> 00:10:27,770
We go down up.

128
00:10:28,500 --> 00:10:29,580
Don't go there.

129
00:10:30,030 --> 00:10:36,540
And we close it, so we added three new lines.

130
00:10:39,760 --> 00:10:40,300
Right.

131
00:10:40,810 --> 00:10:48,550
Six the pixels up, six pixels and left.

132
00:10:51,410 --> 00:10:52,550
Six pixels.

133
00:10:54,850 --> 00:11:00,310
So currently, the cursor is here, so we want to go back six the pixels.

134
00:11:01,740 --> 00:11:06,270
And then we want to go down 160 pixels so you can use drag again.

135
00:11:06,630 --> 00:11:08,640
Well, if you prefer, you can also use move.

136
00:11:09,120 --> 00:11:12,300
So with Move, you want to do six a pixel to the right.

137
00:11:15,520 --> 00:11:16,960
Duration zero point three.

138
00:11:17,500 --> 00:11:21,480
It doesn't need to have a bottom argument because it's a move methods.

139
00:11:21,640 --> 00:11:22,870
It's not throwing anything.

140
00:11:22,870 --> 00:11:25,120
It's just going to the right.

141
00:11:25,510 --> 00:11:29,110
And then we go with move, we go down three.

142
00:11:29,800 --> 00:11:32,950
So we are here, we go right and then done three.

143
00:11:33,100 --> 00:11:33,430
Yes.

144
00:11:34,150 --> 00:11:36,310
So zero three four.

145
00:11:36,310 --> 00:11:39,580
Going down duration zero point three.

146
00:11:40,300 --> 00:11:41,530
And yeah, that's it.

147
00:11:43,420 --> 00:11:43,840
That's.

148
00:11:45,720 --> 00:11:46,080
Back.

149
00:11:47,080 --> 00:11:48,520
Sixty pixels.

150
00:11:51,430 --> 00:11:52,540
Don, thank.

151
00:11:54,790 --> 00:11:56,050
Three pixels.

152
00:11:58,120 --> 00:12:00,250
So right back, let's see.

153
00:12:01,110 --> 00:12:10,690
Let's check it with Gordon right up, down, right up, left right, and then we go to the middle of

154
00:12:10,690 --> 00:12:11,260
the window.

155
00:12:11,470 --> 00:12:13,090
So now we want to go right again.

156
00:12:17,330 --> 00:12:19,130
Let's copy one of these.

157
00:12:20,030 --> 00:12:21,650
Copy that pasted in here.

158
00:12:22,190 --> 00:12:23,420
So we want to go right.

159
00:12:25,370 --> 00:12:26,310
I want to go right.

160
00:12:26,340 --> 00:12:27,350
A hundred pixels.

161
00:12:29,000 --> 00:12:29,720
So then.

162
00:12:32,240 --> 00:12:33,080
So that's right.

163
00:12:34,040 --> 00:12:37,640
And pixels, then I want to go up.

164
00:12:39,870 --> 00:12:46,200
So up 120 pixels, so that's a B minus one, 20, so that is up.

165
00:12:48,290 --> 00:12:49,550
One or two pixels?

166
00:12:53,890 --> 00:12:55,510
So that should take us.

167
00:12:58,970 --> 00:13:05,050
In throws, the window goes back and throws the wall and throws the wall up to where, then we have

168
00:13:05,050 --> 00:13:05,590
a window.

169
00:13:05,860 --> 00:13:13,310
So the wind, sorry, a door the door shouldn't have a line should be empty so we can use again ploy

170
00:13:13,330 --> 00:13:15,610
altogether to move up.

171
00:13:17,890 --> 00:13:19,030
Minus 14.

172
00:13:20,800 --> 00:13:22,540
So zero, minus 40.

173
00:13:31,140 --> 00:13:32,220
Skip, 40.

174
00:13:33,630 --> 00:13:44,190
Pixels up, so to say, after we drove door, we want to draw one more line, so we are here, we want

175
00:13:44,220 --> 00:13:52,230
to draw one more line in here, which according to my calculations, it is about 40 pixels, so we go

176
00:13:52,350 --> 00:13:53,460
up 40 pixels.

177
00:13:53,700 --> 00:14:02,880
So this is a drag duration, zero point three, but and we press the left button and let's see.

178
00:14:11,820 --> 00:14:16,310
You go there and then we ready to go back from here to here.

179
00:14:18,860 --> 00:14:20,390
That is.

180
00:14:22,030 --> 00:14:27,160
220 so that some of these is 220.

181
00:14:27,820 --> 00:14:30,070
Therefore, I want to copy this.

182
00:14:31,880 --> 00:14:37,130
And it's here, it's a drag minus 220.

183
00:14:38,300 --> 00:14:42,860
So we go to the left zero virtually, and that's it.

184
00:14:43,880 --> 00:14:53,060
So let's add the comments of this was up 40 pixels and this is left 220 pixels.

185
00:14:56,720 --> 00:14:57,560
And that's about it.

186
00:15:00,650 --> 00:15:03,170
That now should complete all drawing.

187
00:15:09,990 --> 00:15:17,490
Now we were ready to capture the shots of this area before I do that, I would like to change the duration

188
00:15:18,840 --> 00:15:19,710
so you can do that.

189
00:15:19,980 --> 00:15:26,750
If you are in charm, you could use refactoring tools so I can click over this.

190
00:15:27,180 --> 00:15:31,860
All right, click and go to refactor and go to introduce variable.

191
00:15:32,610 --> 00:15:35,820
And to replace all 14th occurrences.

192
00:15:36,480 --> 00:15:38,850
And then I can write down the variable such as do.

193
00:15:40,230 --> 00:15:47,580
So now doer is created here as a variable, and I can just change this to zero point zero zero one,

194
00:15:47,580 --> 00:15:48,150
for example.

195
00:15:48,180 --> 00:15:53,740
And that means all the drag operations will have a duration of zero point one.

196
00:15:53,740 --> 00:15:54,030
No.

197
00:15:56,100 --> 00:15:58,980
So the drawing would be much faster.

198
00:16:00,550 --> 00:16:00,780
Yeah.

199
00:16:02,200 --> 00:16:04,600
So let's go to the screen shots.

200
00:16:06,100 --> 00:16:09,610
Step out for that, we'll use you.

201
00:16:09,640 --> 00:16:10,870
I am as as.

202
00:16:11,590 --> 00:16:16,000
And we did use this previously in the section before this.

203
00:16:16,930 --> 00:16:25,360
So with emphasis, this is the exact code that we use there as screen parts of the screen will be a

204
00:16:25,360 --> 00:16:25,980
dictionary.

205
00:16:25,990 --> 00:16:31,210
It has a top key with its value, which are the rights in just a second.

206
00:16:31,810 --> 00:16:37,180
It has a left key, also with its own value and then its sense of width.

207
00:16:39,450 --> 00:16:42,540
That's also has a value, and finally, the hides.

208
00:16:43,170 --> 00:16:49,980
So these will define the rectangle area where the screenshot will be captured.

209
00:16:51,090 --> 00:16:51,960
So what is top?

210
00:16:52,770 --> 00:17:02,400
But top is the pixels from the opera border over the full screen to where you want to store the screenshot.

211
00:17:02,700 --> 00:17:05,099
So the number of pixels in this direction.

212
00:17:05,310 --> 00:17:10,890
So that means we're looking at the why of this point.

213
00:17:12,180 --> 00:17:18,540
So the starting point here has a why the number of pixels from there to there.

214
00:17:19,050 --> 00:17:25,740
Therefore, we want to put that in here of the why of that was three fifty five.

215
00:17:26,010 --> 00:17:31,860
So you can see three fifty five or you could say three forty five.

216
00:17:33,140 --> 00:17:42,140
Because this is three, fifty five and up to somewhere in the air, but not reaching the point yet as

217
00:17:42,140 --> 00:17:47,580
of both three forty five, so we want to have some area around the screenshots.

218
00:17:47,600 --> 00:17:48,800
About ten pixels.

219
00:17:49,460 --> 00:17:54,260
So that's why I'm saying three, four five here and four left would be the X.

220
00:17:54,800 --> 00:18:02,930
So that's the area from here to here and there to be the X 12 a scene.

221
00:18:03,290 --> 00:18:12,380
So let's say 12 eight to have that's 10 pixel border and the width is well, the width is.

222
00:18:14,820 --> 00:18:24,630
This year, plus 10 pixels, plus 10 pixels, so that plus 20 pixels, the width of that is, as I calculated,

223
00:18:25,950 --> 00:18:28,500
it is to 20.

224
00:18:29,100 --> 00:18:35,670
So that would be 240, adding that's 220 pixels, and then the heights was 200.

225
00:18:36,720 --> 00:18:38,400
And we want to say 220.

226
00:18:41,810 --> 00:18:43,130
Let's make some space.

227
00:18:44,180 --> 00:18:46,640
So those are the borders of the screenshots.

228
00:18:46,940 --> 00:18:50,630
So let's get the image with screen grab.

229
00:18:52,590 --> 00:19:03,150
Part is the argument for this, and then finally, tools that Pete to PNG image and the RG Beam property

230
00:19:03,150 --> 00:19:06,900
to give us the bytes of that image objects.

231
00:19:07,260 --> 00:19:21,480
So we write the points given the size of that area and given an ultimate's file of path output dot,

232
00:19:21,750 --> 00:19:28,290
let's say to that PNG to distinguish it from that's existing PNG file.

233
00:19:28,950 --> 00:19:30,060
So I'm going to run this.

234
00:19:35,740 --> 00:19:36,940
That's a drawing.

235
00:19:36,970 --> 00:19:42,850
And we've got a profile, so that is the final all.

236
00:19:43,240 --> 00:19:54,430
You can see the pencil here is visible, so we can fix that simply by moving the cursor using the move

237
00:19:54,430 --> 00:19:54,870
methods.

238
00:19:55,150 --> 00:19:55,750
We can move.

239
00:19:55,750 --> 00:20:01,270
It's 50 pixels to the left and 50 pixels up.

240
00:20:01,840 --> 00:20:03,100
So the pencil is here.

241
00:20:03,100 --> 00:20:03,910
We can move it here.

242
00:20:04,150 --> 00:20:10,090
So that's it is outside of the screenshot area and saron it again.

243
00:20:12,330 --> 00:20:20,430
Drawing and then the screen shots will replace with override the existing foil.

244
00:20:20,700 --> 00:20:22,110
So that's the final outputs.

245
00:20:22,120 --> 00:20:23,910
Finally, we did it.

246
00:20:24,210 --> 00:20:28,380
I hope you did too, and thank you for following this and I'll talk to you later.

247
00:20:28,440 --> 00:20:28,710
See you.

