WEBVTT

00:00:00.030 --> 00:00:02.639
hi and welcome to modeling with turtle

00:00:02.639 --> 00:00:05.370
graphics in this video we'll be learning

00:00:05.370 --> 00:00:09.690
about graphing with Tracy the turtle so

00:00:09.690 --> 00:00:12.660
this is Tracy Tracy is a turtle and

00:00:12.660 --> 00:00:14.849
Tracy is really good at drawing lines

00:00:14.849 --> 00:00:17.760
and shapes on the screen we'll see some

00:00:17.760 --> 00:00:21.480
examples of that in a second you can

00:00:21.480 --> 00:00:23.880
tell Tracy to do things using commands

00:00:23.880 --> 00:00:26.939
Tracy understands commands written in a

00:00:26.939 --> 00:00:30.390
programming language called Python right

00:00:30.390 --> 00:00:32.489
above Tracy is an example of a command

00:00:32.489 --> 00:00:35.550
this command tells Tracy to move to the

00:00:35.550 --> 00:00:39.780
location X Y and Tracy's world as Tracy

00:00:39.780 --> 00:00:42.300
moves to this point Tracy will draw a

00:00:42.300 --> 00:00:44.370
line on the screen that represents the

00:00:44.370 --> 00:00:47.670
path the Tracy took programming or

00:00:47.670 --> 00:00:50.160
coding is giving commands to a computer

00:00:50.160 --> 00:00:53.219
will be writing programs for Tracy where

00:00:53.219 --> 00:00:55.500
we give Tracy sequences of commands to

00:00:55.500 --> 00:00:59.160
follow let's learn about some things

00:00:59.160 --> 00:01:03.239
that Tracy can do Tracy lives in a world

00:01:03.239 --> 00:01:06.930
called a canvas because we'll be using

00:01:06.930 --> 00:01:09.479
Tracy to create graphs we'll want to set

00:01:09.479 --> 00:01:11.970
up some axes and labels this will be

00:01:11.970 --> 00:01:16.020
done for us in our programs to graph

00:01:16.020 --> 00:01:18.479
with Tracy will be using the set

00:01:18.479 --> 00:01:20.580
position command the set position

00:01:20.580 --> 00:01:23.939
command takes two arguments X and Y and

00:01:23.939 --> 00:01:26.009
then sends Tracy to the place on the

00:01:26.009 --> 00:01:30.390
canvas with the coordinates x and y 2sin

00:01:30.390 --> 00:01:32.729
Tracy to a specific location we need to

00:01:32.729 --> 00:01:35.579
set x and y to be numerical values like

00:01:35.579 --> 00:01:40.590
0 and 5 or 10 and 10's Tracy moves to

00:01:40.590 --> 00:01:42.869
the coordinate point Tracy will leave a

00:01:42.869 --> 00:01:44.909
trail showing the path taken which is

00:01:44.909 --> 00:01:49.409
going to be the line in our graph so to

00:01:49.409 --> 00:01:51.840
draw a graph we'll use the set position

00:01:51.840 --> 00:01:55.619
command to send Tracy to a series of XY

00:01:55.619 --> 00:01:59.070
coordinates to do this we'll use a

00:01:59.070 --> 00:02:02.820
for-loop code inside a for loop will

00:02:02.820 --> 00:02:05.820
execute repeatedly we set how many times

00:02:05.820 --> 00:02:08.399
the code executes by putting a number in

00:02:08.399 --> 00:02:10.800
parentheses so if I wanted to run

00:02:10.800 --> 00:02:13.830
something 100 times I would say

00:02:13.830 --> 00:02:17.010
X in range 100 making sure to put the

00:02:17.010 --> 00:02:19.290
number 100 in parenthesis and then

00:02:19.290 --> 00:02:21.870
ending with a colon then whatever code I

00:02:21.870 --> 00:02:24.210
put indented below that line will repeat

00:02:24.210 --> 00:02:28.950
100 times the value of x will start at 0

00:02:28.950 --> 00:02:31.590
and each time the for loop runs it will

00:02:31.590 --> 00:02:33.990
increase the value of X until it reaches

00:02:33.990 --> 00:02:36.150
the maximum value which is the number we

00:02:36.150 --> 00:02:39.440
put in parenthesis so in this case 100

00:02:39.440 --> 00:02:42.270
so to graph an equation we can make it

00:02:42.270 --> 00:02:45.240
so every time X updates we calculate the

00:02:45.240 --> 00:02:47.460
value of y and then use the set position

00:02:47.460 --> 00:02:50.220
command to send Traci to the position X

00:02:50.220 --> 00:02:53.870
comma Y let's take a look at an example

00:02:53.870 --> 00:02:56.670
so this is the editor page and the

00:02:56.670 --> 00:02:58.950
editor page is set up so that our

00:02:58.950 --> 00:03:01.080
program or our code is written on the

00:03:01.080 --> 00:03:03.810
left side and then our canvas where we

00:03:03.810 --> 00:03:05.970
can see Traci run the code is on the

00:03:05.970 --> 00:03:08.520
right side and anytime we want to run

00:03:08.520 --> 00:03:10.230
the code we can just click this green

00:03:10.230 --> 00:03:14.670
Run code button so you can see that this

00:03:14.670 --> 00:03:16.650
code that's written already sets up

00:03:16.650 --> 00:03:19.170
Traci with axes and labels on the canvas

00:03:19.170 --> 00:03:21.780
so I'm going to click stop to clear the

00:03:21.780 --> 00:03:24.540
canvas while we code our graph so we

00:03:24.540 --> 00:03:26.070
want to make sure not to modify any of

00:03:26.070 --> 00:03:28.340
the code that sets up Traci's axes and

00:03:28.340 --> 00:03:32.430
we'll just graph below all of that so

00:03:32.430 --> 00:03:35.190
I'll start with a for loop for X in

00:03:35.190 --> 00:03:39.420
range 50 so I want to make sure that the

00:03:39.420 --> 00:03:41.610
number 50 is in parentheses and that I

00:03:41.610 --> 00:03:45.989
put a colon after this statement now I

00:03:45.989 --> 00:03:47.820
want to make sure that all the code I

00:03:47.820 --> 00:03:49.830
want repeated is indented under this

00:03:49.830 --> 00:03:53.310
loop every time my x value updates i

00:03:53.310 --> 00:03:56.310
want to recalculate my y value and go to

00:03:56.310 --> 00:04:00.239
the position x comma y let's say i want

00:04:00.239 --> 00:04:03.900
to graph the equation y equals x divided

00:04:03.900 --> 00:04:07.410
by 4 so i've written my equation and now

00:04:07.410 --> 00:04:09.930
i need to use set position to send traci

00:04:09.930 --> 00:04:15.540
to the coordinate pair XY ok let's try

00:04:15.540 --> 00:04:18.100
running our program now

00:04:18.100 --> 00:04:20.950
okay so we got an error here and so the

00:04:20.950 --> 00:04:23.050
issue here is that I used set position

00:04:23.050 --> 00:04:25.690
with a capital S when I should have used

00:04:25.690 --> 00:04:28.450
a lowercase s Python is very picky and

00:04:28.450 --> 00:04:30.280
so if you make a small typo like

00:04:30.280 --> 00:04:32.020
forgetting to close your parentheses or

00:04:32.020 --> 00:04:34.420
using upper case instead of lowercase it

00:04:34.420 --> 00:04:36.220
won't work and it's going to give you an

00:04:36.220 --> 00:04:36.610
error

00:04:36.610 --> 00:04:39.040
luckily on the left hand side of our

00:04:39.040 --> 00:04:41.500
editor page we have some documentation

00:04:41.500 --> 00:04:43.990
and this just has a list of the commands

00:04:43.990 --> 00:04:46.390
we might use so if you forget exactly

00:04:46.390 --> 00:04:48.880
how to write something just check here

00:04:48.880 --> 00:04:50.530
and so I can see that set position

00:04:50.530 --> 00:04:53.680
should have a lowercase s now let's run

00:04:53.680 --> 00:04:58.840
the code again awesome so this graph is

00:04:58.840 --> 00:05:01.060
linear but Tracy can plot all kinds of

00:05:01.060 --> 00:05:03.640
two variable relationships here you can

00:05:03.640 --> 00:05:06.040
see Tracy is plotting a sinusoidal wave

00:05:06.040 --> 00:05:09.460
graph now it's your turn to make graphs

00:05:09.460 --> 00:05:12.090
with Tracy
