1
00:00:05,240 --> 00:00:10,220
Hi, welcome to this new
video on our Python course.

2
00:00:10,220 --> 00:00:13,820
Today we're going to continue
talking about primitives.

3
00:00:13,820 --> 00:00:16,740
It's something that we
introduced in the last video.

4
00:00:16,740 --> 00:00:19,560
We've called this one
advanced primitives.

5
00:00:19,560 --> 00:00:22,440
But it's not necessary that
they're very advanced.

6
00:00:22,440 --> 00:00:24,100
It's just starting to think of

7
00:00:24,100 --> 00:00:26,460
primitives that might
require a series of lines

8
00:00:26,460 --> 00:00:27,760
of code to actually

9
00:00:27,760 --> 00:00:30,435
construct the totality
of the primitive.

10
00:00:30,435 --> 00:00:31,800
There again, very open

11
00:00:31,800 --> 00:00:36,100
ended constructs that are
kind of available for us.

12
00:00:36,100 --> 00:00:37,775
Let's see what we mean by this.

13
00:00:37,775 --> 00:00:39,650
Let's imagine that we

14
00:00:39,650 --> 00:00:41,790
want to construct
something like a polyline.

15
00:00:41,790 --> 00:00:43,230
Something that is
not necessarily

16
00:00:43,230 --> 00:00:45,850
a particular line that is
established between two points,

17
00:00:45,850 --> 00:00:48,950
but rather something that
has an x number of points,

18
00:00:48,950 --> 00:00:50,340
maybe more or less points,

19
00:00:50,340 --> 00:00:51,830
so how would we do that?

20
00:00:51,830 --> 00:00:54,090
Well, we have a
keyword here within

21
00:00:54,090 --> 00:00:56,430
the processing
environment that's begin

22
00:00:56,430 --> 00:00:59,410
shape that would open

23
00:00:59,410 --> 00:01:03,750
up the possibility to start
introducing vertices.

24
00:01:03,750 --> 00:01:07,045
Vertices will represent
points in this line,

25
00:01:07,045 --> 00:01:09,450
and as you can see
here, we can actually

26
00:01:09,450 --> 00:01:12,290
describe one point with
one line called vertex.

27
00:01:12,290 --> 00:01:14,010
But then the system is

28
00:01:14,010 --> 00:01:16,130
understanding that
this is a sequence.

29
00:01:16,130 --> 00:01:17,870
We will be talking about

30
00:01:17,870 --> 00:01:20,525
sequences of data in the
future, but for now,

31
00:01:20,525 --> 00:01:23,770
our very first is starting
to understand that

32
00:01:23,770 --> 00:01:25,630
the construct of
this polyline is

33
00:01:25,630 --> 00:01:28,330
actually a sequence of vertices.

34
00:01:28,330 --> 00:01:29,530
The vertice is a point.

35
00:01:29,530 --> 00:01:31,190
Then we go to the second point,

36
00:01:31,190 --> 00:01:34,910
again thinking coordinates
x and y in each one of

37
00:01:34,910 --> 00:01:37,470
those cases and then
we finally go through

38
00:01:37,470 --> 00:01:39,000
four points and then whenever

39
00:01:39,000 --> 00:01:40,820
we feel like we are
done with this line,

40
00:01:40,820 --> 00:01:42,475
we can do end shape.

41
00:01:42,475 --> 00:01:44,970
The end shape is
also a keyword that

42
00:01:44,970 --> 00:01:47,240
would close not
necessarily close,

43
00:01:47,240 --> 00:01:50,920
but end the operation of
constructing this poly line.

44
00:01:50,920 --> 00:01:53,370
How many points can we have?

45
00:01:53,370 --> 00:01:56,840
We can have a very
large number of points.

46
00:01:56,840 --> 00:02:00,120
That number is quite arbitrary
in the sense that we could

47
00:02:00,120 --> 00:02:01,620
decide to do just a simple line

48
00:02:01,620 --> 00:02:03,500
between two points or
something more complex.

49
00:02:03,500 --> 00:02:05,420
Obviously, we have
a shortcut for

50
00:02:05,420 --> 00:02:08,190
a straight line that
doesn't require vertices.

51
00:02:08,190 --> 00:02:11,260
But perhaps it's
something that changes

52
00:02:11,260 --> 00:02:14,720
and we'll talk about adaptation
in the future as well.

53
00:02:14,720 --> 00:02:17,280
This construct is quite
open for us to add

54
00:02:17,280 --> 00:02:21,275
more vertices if we want to
or perhaps a smaller number.

55
00:02:21,275 --> 00:02:23,555
There's also some options,

56
00:02:23,555 --> 00:02:25,550
and I'm going to show
you one of them.

57
00:02:25,550 --> 00:02:27,250
You can actually look
in the reference files

58
00:02:27,250 --> 00:02:29,030
and you'll see that
there's a series of

59
00:02:29,030 --> 00:02:33,845
options regarding of how
polylines actually behave.

60
00:02:33,845 --> 00:02:37,590
But for instance, if we
specify the variable

61
00:02:37,590 --> 00:02:41,265
close in the end shape,
like the last line,

62
00:02:41,265 --> 00:02:44,830
we will see that the
segment of the line

63
00:02:44,830 --> 00:02:46,790
between the last point and

64
00:02:46,790 --> 00:02:50,480
the first point automatically
gets generated for us.

65
00:02:50,480 --> 00:02:55,070
We could go around this
rule and basically repeat

66
00:02:55,070 --> 00:02:59,070
the first vertex towards

67
00:02:59,070 --> 00:03:00,870
the end of the sequence
and in that way,

68
00:03:00,870 --> 00:03:02,950
basically we don't
need to specify close,

69
00:03:02,950 --> 00:03:05,410
but the close keyword
would actually allow us

70
00:03:05,410 --> 00:03:08,820
to automatically not
duplicate vertices,

71
00:03:08,820 --> 00:03:13,240
and suggest that the
polyline closes in itself.

72
00:03:13,240 --> 00:03:17,280
We can use that
form with fields.

73
00:03:17,280 --> 00:03:18,950
We can actually
add a field to it,

74
00:03:18,950 --> 00:03:21,490
so it actually has a
very specific shape

75
00:03:21,490 --> 00:03:25,905
that could have a background
and also the stroke weight.

76
00:03:25,905 --> 00:03:31,240
Let's go into processing and
write some of this together.

77
00:03:31,240 --> 00:03:33,890
We're going to start here
on what I would call

78
00:03:33,890 --> 00:03:36,840
the boilerplate for
our programming.

79
00:03:36,840 --> 00:03:39,230
We will most often need

80
00:03:39,230 --> 00:03:42,430
a set up and a canvas size
which we can leap behind.

81
00:03:42,430 --> 00:03:44,780
You can save this as a template.

82
00:03:49,080 --> 00:03:51,170
We're going to be working

83
00:03:51,170 --> 00:03:53,545
within the draw
function this time.

84
00:03:53,545 --> 00:03:55,675
There's no real reason for this.

85
00:03:55,675 --> 00:03:58,430
But as we go along,

86
00:03:58,430 --> 00:04:00,050
we're going to be
working more and

87
00:04:00,050 --> 00:04:01,790
more with dynamic
content and that

88
00:04:01,790 --> 00:04:03,930
dynamic content makes most sense

89
00:04:03,930 --> 00:04:06,790
to be working on it
within the draw loop.

90
00:04:06,790 --> 00:04:09,840
Let's do begin shape,

91
00:04:12,050 --> 00:04:17,500
and we can skip a few
lines and do end shape.

92
00:04:19,610 --> 00:04:22,490
Between these lines we

93
00:04:22,490 --> 00:04:24,505
know that we have to
add some vertices,

94
00:04:24,505 --> 00:04:27,055
so the keyword is vertex,

95
00:04:27,055 --> 00:04:32,735
and you can do any value
you want within the Canvas.

96
00:04:32,735 --> 00:04:35,690
You can actually do points
outside the Canvas,

97
00:04:35,690 --> 00:04:38,310
but they might not
really be visible.

98
00:04:38,310 --> 00:04:42,100
So you will see your shape
going outside the Canvas.

99
00:04:44,030 --> 00:04:47,020
Sorry, I know I misspelled that,

100
00:04:47,020 --> 00:04:50,480
but we can actually
go ahead and copy

101
00:04:50,480 --> 00:04:56,610
that line a few times
as you can see here.

102
00:04:56,610 --> 00:04:59,820
Then we can actually start
going through the numbers.

103
00:04:59,820 --> 00:05:02,720
Sometimes I really
like sketching

104
00:05:02,720 --> 00:05:04,380
many times when I'm thinking of

105
00:05:04,380 --> 00:05:06,420
coordinates and I'm starting
to think of a figure,

106
00:05:06,420 --> 00:05:08,360
sometimes I even
use a cat package,

107
00:05:08,360 --> 00:05:10,540
something like rhino or

108
00:05:10,540 --> 00:05:12,260
any kind of drawing package that

109
00:05:12,260 --> 00:05:14,240
would allow you to
see coordinates.

110
00:05:14,240 --> 00:05:16,800
If you want to create
a specific geometry

111
00:05:16,800 --> 00:05:19,145
that then later you might
want to manipulate.

112
00:05:19,145 --> 00:05:23,720
It might be worth considering
measuring those things

113
00:05:23,720 --> 00:05:26,220
in another software
package where you can

114
00:05:26,220 --> 00:05:29,965
just pre-draw those shapes,
know your coordinates.

115
00:05:29,965 --> 00:05:31,660
Later in this series,

116
00:05:31,660 --> 00:05:32,900
we'll actually see how to

117
00:05:32,900 --> 00:05:34,900
export and import things
from other content,

118
00:05:34,900 --> 00:05:37,160
from other kind of
different forms of

119
00:05:37,160 --> 00:05:40,410
information that could
be read by processing.

120
00:05:40,410 --> 00:05:43,740
If you have knowledge
in other kind of

121
00:05:43,740 --> 00:05:45,540
software packages that might

122
00:05:45,540 --> 00:05:48,280
offer you those capabilities
of exporting material,

123
00:05:48,280 --> 00:05:50,035
perhaps that would
be also useful.

124
00:05:50,035 --> 00:05:51,920
But let's just do

125
00:05:51,920 --> 00:05:54,060
some shape attributes here

126
00:05:54,060 --> 00:05:57,000
and let's see what
options we have.

127
00:05:58,560 --> 00:06:00,500
Again, here I'm trying to

128
00:06:00,500 --> 00:06:01,740
go for something that I couldn't

129
00:06:01,740 --> 00:06:10,355
do with just a rectangle.

130
00:06:10,355 --> 00:06:14,815
You can see here, this geometry.

131
00:06:14,815 --> 00:06:17,415
It's quite arbitrary.

132
00:06:17,415 --> 00:06:20,200
Eventually when we start
learning about animation,

133
00:06:20,200 --> 00:06:21,760
we'll see that maybe

134
00:06:21,760 --> 00:06:24,400
one vertex is something
that we want to maybe move

135
00:06:24,400 --> 00:06:26,865
this vertex or let
it wander around

136
00:06:26,865 --> 00:06:28,480
perhaps and you'll see that

137
00:06:28,480 --> 00:06:31,070
you'll start getting an
animation of the geometry.

138
00:06:31,070 --> 00:06:33,000
Sometimes when you
have constructs

139
00:06:33,000 --> 00:06:34,060
and primitives that are already

140
00:06:34,060 --> 00:06:36,960
established to be a circle
or to be a rectangle,

141
00:06:36,960 --> 00:06:38,840
you're locked into thinking of

142
00:06:38,840 --> 00:06:40,620
that geometry like
that all the time.

143
00:06:40,620 --> 00:06:42,560
But when you're actually
creating your own custom,

144
00:06:42,560 --> 00:06:44,160
perhaps more advanced geometry,

145
00:06:44,160 --> 00:06:45,980
like a polyline, in this case,

146
00:06:45,980 --> 00:06:47,520
like the geometry
that emerges out

147
00:06:47,520 --> 00:06:49,690
of drawing this polyline,

148
00:06:49,690 --> 00:06:53,580
you have a lot of flexibility
and it really opens up

149
00:06:53,580 --> 00:06:57,900
design possibilities that
are quite interesting.

150
00:06:57,900 --> 00:06:59,400
Similarly to other primitives,

151
00:06:59,400 --> 00:07:01,490
you can actually style and color

152
00:07:01,490 --> 00:07:05,595
these geometries with fill.

153
00:07:05,595 --> 00:07:07,440
We could say, well,

154
00:07:07,440 --> 00:07:16,580
fill(0,200,200,50) just to
give it some transparency.

155
00:07:16,700 --> 00:07:19,505
Let's see how that looks.

156
00:07:19,505 --> 00:07:26,530
You see we have some CN
slightly transparent.

157
00:07:26,530 --> 00:07:34,350
Maybe we want to have a white
stroke that would be 255.

158
00:07:34,350 --> 00:07:36,730
Let me just scroll down
a little bit here so

159
00:07:36,730 --> 00:07:39,685
we have a bit more room to see.

160
00:07:39,685 --> 00:07:47,240
Also the stroke weight of two.

161
00:07:48,440 --> 00:07:51,855
As you can see, we can style

162
00:07:51,855 --> 00:07:54,090
these geometry is
the same way we

163
00:07:54,090 --> 00:07:56,880
would do a rectangle and
any other primitive.

164
00:07:57,650 --> 00:08:00,195
There's a lot of flexibility.

165
00:08:00,195 --> 00:08:02,870
As you can see, we're not
getting the line as much as

166
00:08:02,870 --> 00:08:07,060
the geometry fill
that it's closed.

167
00:08:07,760 --> 00:08:11,830
Let's just actually do a
no field for a moment.

168
00:08:11,830 --> 00:08:15,410
Let's comment this out because
the fill is suggesting,

169
00:08:15,410 --> 00:08:17,270
or it's giving us
the wrong impression

170
00:08:17,270 --> 00:08:19,910
that in fact that
geometry has been closed,

171
00:08:19,910 --> 00:08:22,170
so let's do a no fill.

172
00:08:24,530 --> 00:08:26,800
You see that we actually

173
00:08:26,800 --> 00:08:29,760
haven't closed
that geometry yet.

174
00:08:29,840 --> 00:08:34,540
Let's just do the
option close here.

175
00:08:34,540 --> 00:08:40,090
You'll see that now the line
appears on the other side.

176
00:08:40,090 --> 00:08:42,890
Again, I really like
this technique,

177
00:08:42,890 --> 00:08:47,940
you'll hear it a lot from
me during this course,

178
00:08:47,940 --> 00:08:50,295
like commenting out a line,

179
00:08:50,295 --> 00:08:52,010
lines that I know that it

180
00:08:52,010 --> 00:08:54,685
might want to evaluate
while I'm designing,

181
00:08:54,685 --> 00:08:58,340
so you might just have
a version of that line.

182
00:08:58,340 --> 00:09:00,220
Maybe you're still
deciding if you want

183
00:09:00,220 --> 00:09:02,530
to use a fill or no fill,

184
00:09:02,530 --> 00:09:05,320
and that's something
that you can

185
00:09:05,320 --> 00:09:07,560
evaluate later as you can

186
00:09:07,560 --> 00:09:11,280
intuitively work through
your design iterations.

187
00:09:11,280 --> 00:09:13,400
You'll see me doing
this quite a bit.

188
00:09:13,400 --> 00:09:17,215
Leaving lines that I
might use as a comment,

189
00:09:17,215 --> 00:09:20,195
so commenting out a
line, it's very useful.

190
00:09:20,195 --> 00:09:22,650
Again, this is what we're

191
00:09:22,650 --> 00:09:25,030
doing with more
advanced primitives.

192
00:09:25,030 --> 00:09:26,750
There's a series of even

193
00:09:26,750 --> 00:09:28,550
more advanced
primitives, I would say,

194
00:09:28,550 --> 00:09:32,590
that allow you to base your
type of curves that you could

195
00:09:32,590 --> 00:09:34,890
specify not only vertices but

196
00:09:34,890 --> 00:09:37,790
anchor points and create
curvature between those.

197
00:09:37,790 --> 00:09:40,570
I'll leave those
for you to explore.

198
00:09:40,570 --> 00:09:44,550
It really behaves the same
way we can see here with

199
00:09:44,550 --> 00:09:47,230
the polylines but I'll continue

200
00:09:47,230 --> 00:09:49,230
showing you more content

201
00:09:49,230 --> 00:09:51,670
in the next video.
I'll see you then.