I wanted to show you a bunch of
interesting curves that you can draw; and
actually I wanted to get my plotter
machine
working on some Numberphile brown
paper and do some of the drawing for us.
Well I wanted to talk a bit about
something called turtle graphics - which
is something you said you're familiar
with from school right?
Where you
are basically controlling a little
turtle robot as it moves around on
screen drawing pictures. What are the
instructions you can give to the turtle?
You can go forward some distance - d, say.
You can turn an angle
theta,
and then the other thing you can do is
you can say pen
down
and pen up.
Pen down is you're imagining this little
turtle has a pen in the middle of it
and when pen is down and it goes forward
it will end up drawing a line as it
moves;
but if the pen is up it will just move
over to that new location no line drawn.
So you do like a little example I
suppose of a simple program that you
might give the turtle; we'll start
we'll go forward
1 unit,
I will turn
90 degrees,
forward 1,
turn
90 degrees,
forward 1
turn
90 degrees,
forward 1.
(Brady: Even I know what's going on there)
Yeah? - (I reckon you've drawn a square)
Yeah. I think so. Shall we check? - (All right)
Cool. So I've made this little turtle
thing out of a
top of a pringles can, a can of
hyperbolic paraboloids. Our first
instruction was forward 1, that means
we're going to end up there; and the pen
was down so we've drawn that line behind it.
And now we're turning 90 degrees
which would be like this. So our new
point is going to be there when we go
forward 1,
and the pen drew behind us. Turn 90
degrees again, forward 1,
forward 1; pen was drawing the whole
time. You're right - we drew a square. - (And you)
(can get more elaborate than this?) - Yes, but
I'm interested in things that are still
quite simple programs
but make more elaborate curves. I've got
a version of this running
on Mathematica. So if I do 90 degrees
we can visualise what the turtle was doing.
So it started off going forward,
turn 90,
forward, turn 90, forward,
turn 90, forward. I turned right 90, that's
turning left 90. So from now on I'm
going to just assume that after every
turn there's a- there's a forward 1
and I'm always going to just assume the
pen is down the whole time.
So actually this program we wrote here we
could just write as 90,
90, 90.
So it's even simpler right? We're just
gonna have a list of angles
and see what we can draw with a list of
angles. So for example let's let's say
theta is 1 degree,
and our program is just going to be
theta,
2 theta,
3 theta,
4 theta,
5 theta - just keep doing that again again
like what what do we get? So I could do
that manually, I could just put in 1
degree, 2 degrees, 3 degrees, 4
degrees, so I would just put in in here
and see what we get. Okay it's gone- it's
going to be slightly curving up as it
goes.
Kind of makes sense I guess, so that's
1 degree above now it's going another
2 degrees turn, another 3,
very gradual.
So let's let's make this more automatic;
so let's do like 180 steps and we
multiply by what a degree is. And this is
what we end up with: as it gets tighter
and tighter
it spirals into the middle.
Let's do more steps, let's do 360 of
these steps. So what's happened here is
that the turtle's gone into the middle
and then it's ended up spiraling
back out the way it came.
So at the end, it's very small,
but at the end it's
pointing
back from where it started, it's rotated
180 degrees.
So now it's ready to go up and do the
same thing over here.
So if we set this theta to 1 degree
we're just going to get this repeating
thing
where the turtle's going to go around,
spiral, come back exactly the way it came,
go in spiral, come back exactly the way
it came. This is very similar to
something that's called an Euler spiral,
also called a Cornu spiral; but those
spirals are defined like in a continuous
way whereas this is all by taking
discrete turns.
What happened here is because we're
doing exactly 1 degree, and 1 degree
is a 360th of a full turn, so we ended up
going back to where we started; but we
can get more interesting pictures if we
make it not a-
like nice multiple, a nice divider of a
full turn. Now what if we turned 1.02
degrees each time? And now
we end up
not quite coming back where we started,
we do all these
dancing around. And it's very sensitive
to what you you change that number to, so
this is 1.03, it's a totally different
picture.
It's kind of like getting back to ideas
of chaos
where this
is very sensitive where you're going to
end up after a long time, it's just very
sensitive on that
little number there because you can come
out the spiral kind of in a new random
direction. So we could we could play with
this a little bit maybe; so I'm going
to say we're going x degrees each time
and I get- going to vary what x is. So
this is going 1 degree each time, this
is the original picture,
and then as I change this slider I'll be
changing number of degrees. So here we go,
a different picture each time as it
increments. - (Wow)
Yeah
(Very cool.) - So
shall we get the machine to draw one of
those for us? - (Yeah!)
So here I've got code that does
the same thing in Python, and it's- what
it will do is it will generate
instructions which will send over this
USB to the machine and it will tell the
pen what to do. In this code I've called this
dth which is d theta, like the change in
theta each time. And looks like I've set
d theta to
this number here. This is a number I
figured out is good because it stays on
the paper, right, you don't have a
guarantee that you're not just going
to go off and like go off the paper.
Here's the final product - well we
actually cut it off a little bit early
because we got
impatient -
but this is the first few spirals of
this one here.
Let's have a look at what it would have
been if we let it run for for a bit
longer: here is what it would have done
if we did it for ten thousand steps.
So yeah let's see,
can we match that up a little bit?
We got some of these guys going but then
it was going to kind of come out and go
out here. We basically stopped after
roughly a thousand steps it looks like.
If we did ten thousand
then like it's kind of making a spiral
of
spirals itself.
You can see this pattern,
it's kind of recreating itself and going
out there;
so let's do a hundred thousand. So there,
there you go.
So now this is starting to look like
its own- it's kind of macro scale
version of of an Eu-
it's an Euler spiral of Euler spirals. But
we didn't manage to get the next level,
this looks kind of chaotic. - (That would)
(have been a huge piece of paper) - Yeah,
yeah it would be.
Can you- yeah look at this, so it's the
side by side scale comparison.
(So that thing you're holding, where's)
(that on the big picture there? It's one)
(of those little-) - It's gonna be one of
these little, yeah, hubs. So now
I want to draw a Sierpinski triangle
picture. This one's actually called the
Arrowhead Curve. So this is the kind of
picture that we're going to kind of try
and end up with, and it's nice for the
plotter because it draws a whole kind of
Sierpinski shape all in one path. So you
can see it starts up here, it'll end up
drawing you know this triangle and this
triangle this triangle, and it ends up here.
(You never have to do pen up?) - That's right,
it's all it's all pen down and each
step size is the same, and it's all just
turning left and right.
It's always either turning right um 60
degrees or left 60 degrees. And so it's
just how do you come up with the list of
left, right, right, right, left, right, left,
left, that comes up with this picture?
And there's a kind of interesting way of
deriving what those instructions should
be. We're going to do something called
like a substitution system, where we're
going to- making repeated substitutions.
And we'll just have two rules;
so we're going to have every time we see
an x we're going to substitute it with y plus x plus y,
and every time we see a y we're going to
replace it with
x minus y
minus x.
And
here these aren't actually pluses and
minuses, plus means you know turn right
and minus means to turn left 60
degrees. And we're just going to start,
you know, iteration one, we just start
with x. This doesn't have any
instructions in it but we're just going
to keep applying these rules and see
what happens.
So at step two,
you know, we're reading this and we see
an x so we replace it with
what we're supposed to replace it with: y
plus x
plus
y.
And so now if we were to do this
instructions it just says turn right 60,
turn right 60, which is not a super
interesting
picture
but you know, we'll say we've go-
we've gone forward,
we turn,
turn right 60 I mean we go down like
this,
and then we do another turn right 60,
and I've just drawn this picture.
Not very interesting yet.
Let's do it again. So now we're going to
use this other rule for y.
So we're reading y,
we replace it with what we're supposed
to replace it with: x minus y minus x.
We see the plus that doesn't have any
replacement rule so we just copy it down.
We see an x
so we replace this y plus x plus y;
we see a plus so we copy it, we see
a y so we
bring down x minus y minus x, which is
the rule for y.
So now we could try and draw what this
is like; I'm not going to do any- I don't
want to do any more turning right and
left by 60 degrees
by hand, so what I've done is I've
prepared a grid that should help.
So this isn't cheating right? This is
using a pen on brown paper, I just-
we used the machine to create this, so
this is fine. - (Okay, it's fine)
I didn't- I didn't print this, this is within the
rules of Numberphile. I'm going to say
like we'll- let's start going forward
first
and then we'll- and then we'll do these
instructions.
So we're going to turn left.
and then turn left again,
now we have to turn right,
turn right again,
turn right, turn right,
turn left,
turn left.
So we've created this
image here.
It's kind of getting closer to a
triangle maybe, it's kind of triangular
shape; but it's still not got the detail
of this Sierpinski triangle.
Yeah let's do it again.
This this one had one
x, this had three x's and y's, this had
nine x's and y's,
next one's gonna have 27 x's and y's.
So let's do it one more time.
There we go,
I think that's right.
And yeah, if we did it another time we'd end
up with 81 which is not going to be good
to do by hand.
But I think we can try and draw
this iteration by hand? And then
maybe we'll recruit the plotter to help
us with the next step.
And
what were we saying? Minus was turning left
and plus was turning right?
So
so we've gone forward 1, turning right
means that we're gonna turn right along here.
Ah, phew.
So that looks like getting closer to
this triangles inside triangles look of
the Sierpinski fractal.
We got up to was this n equals three
picture here.
I've just programmed this- this what we
were doing by hand into Mathematica here,
you've got a substitution system
where x and y, there's a rule for x
and y.
Instead of plus and minus I've just
put in the angles
directly in radians of pi by 3, pi by 3,
for the where we had pluses and minus pi
by 3, minus pi by 3 for where we had
minuses. The next step up would be n
equals 4.
So, you know,
we've got our what we just drew by hand
copied three times in each side.
And n equals 5,
getting more and more detailed.
n equals 6 is nice.
And here's a picture for n equals 7
which might be a good one to
plot
with the machine.
Okay so we've stopped the machine
exactly halfway through drawing this
Sierpinski turtle program; just wanted to
show you something about
how it's doing the drawing.
So here is halfway and maybe if you
look at it like this; because if we
reflected this whole thing over here
we'd have the full picture right?
And this is just the vertical
half of the picture.
But yeah looking at from here I can
see each of the previous iterations kind
of lined up one after the other right? So
we drew
this one and this one by hand, then we
bailed and we started going to the
computer.
And you know these are the previous
iterations, now we're going to draw the
one on top of that.
So what we've seen is that
the next iteration of this arrowhead
curve, this arrowhead Sierpinski
curve,
you could do it just by taking all the
previous iterations lining them up and
then reflecting it
in sort of vertical axis.
So shall we make it draw the rest of the
picture? - (Yes please!)
Yeah cool.
So now I want to show you another type
of turtle program we can send to the to
the plotter machine, like what if I just
start sending the digits of pi?