Add Chapter 5 Lab
This commit is contained in:
parent
991caf0521
commit
2491b50434
2 changed files with 43 additions and 0 deletions
43
thinkcspy/Chapter-5-Exercises/Lab Plotting a Sine Wave.md
Normal file
43
thinkcspy/Chapter-5-Exercises/Lab Plotting a Sine Wave.md
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
# Lab: Plotting a Sine Wave
|
||||||
|
|
||||||
|
Create and set up the turtle and the screen.
|
||||||
|
|
||||||
|
Iterate the angle from 0 to 360.
|
||||||
|
|
||||||
|
> Generate the sine value for each angle.
|
||||||
|
>
|
||||||
|
> Move the turtle to that position (leave a line behind).
|
||||||
|
|
||||||
|
_My note: the lab encouraged us to try other functions out, so I included a turtle drawing cosign._
|
||||||
|
|
||||||
|
```text-x-python
|
||||||
|
import math
|
||||||
|
import turtle
|
||||||
|
|
||||||
|
wn = turtle.Screen()
|
||||||
|
wn.bgcolor('lightblue')
|
||||||
|
|
||||||
|
turtle.setworldcoordinates(0, -1.25, 360, 1.25)
|
||||||
|
|
||||||
|
fred = turtle.Turtle()
|
||||||
|
fred.speed(10)
|
||||||
|
fred.color('red')
|
||||||
|
|
||||||
|
george = turtle.Turtle()
|
||||||
|
george.speed(10)
|
||||||
|
george.color('blue')
|
||||||
|
|
||||||
|
for angle in range(361):
|
||||||
|
x = angle
|
||||||
|
y = math.sin(math.radians(angle))
|
||||||
|
fred.goto(x,y)
|
||||||
|
|
||||||
|
for angle in range(361):
|
||||||
|
x = angle
|
||||||
|
y = math.cos(math.radians(angle))
|
||||||
|
george.goto(x,y)
|
||||||
|
|
||||||
|
wn.exitonclick()
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
BIN
thinkcspy/Chapter-5-Exercises/Lab/image.png
Normal file
BIN
thinkcspy/Chapter-5-Exercises/Lab/image.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
Loading…
Reference in a new issue