Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168703
Image: ubuntu2004

In this lab we you will get some more experience in using graphics primatives. Before we get started, if you find things running much too slowly, try the server at www.sagenb.com  (You will need to get an account there and search the public documents for lab4.)

 

In this first part I will present some simple commands towards building an interactive clock.  Then you will fix it up.  (When we learn more programming, we will be able to do a better job.)

We start with a thick circle of radius 4.

rim=circle((0,0),4,color="red",aspect_ratio=1,thickness=3) rim

Next I will locate a point on the circle.   Remember that I can do this because cos(t) is the x-coordinate of the point on the unit circle with angle t, while sin(t) is the y-coordinate of the point on the unit circle.    (This is the definition of the sine and cosine when the angle is large.)  I multiply this by 4 since my circle has radius 4.

pt=point((4*cos(pi/4),4*sin(pi/4)),size=50)
pt+rim

Next I will put these two commands into an interact command which allows me to change the angle for the point:

@interact def my_clock(a=slider(-2*pi,2*pi,default=0)): show(circle((0,0),4,color="red",aspect_ratio=1,thickness=4)+point((4*cos(a),4*sin(a)),size=50))

 

Play with the slider.  Note that it starts when the angle is zero ( at (1,0) ) and the angle can be any number between -2pi and 2pi.  Set the dot straight up (what will the angle be?)    Put it over to the left at (-1,0).
Next I want you to change the interact to make it a little more like a clock.

1. Replace the point by a hand from the center to the current point location.
2. Use text to add clock numbers 3,6,9,12 to the clock.

3.  Create a regular hexagon (6 sides).  Use cosine and sine to locate the 6 points evenly around a circle.

4. Repeat, but with the hexagon rotated by π/10\pi/10.

5.  Set up an interact to rotate the polygon as the slider is moved. (Very similar to the interact we did above.)

6.  Create the following graphic.  (Do not remove/use the cell directly below this text!)