CPSC150A
Scientific Computing

Activity 0

Introduction

Diamond

Write a Python program that uses turtle graphics to draw a diamond.

Example


Centered Square

Write a Python program that uses turtle graphics to draw a square that is centered in the window.

Example

Note, it is difficult to see if the square is correctly centered when the square is small and the window is large. Draw the square large so that it takes up the majority of the window to make it easier to tell if it is perfectly centered.


Star

One of the first shapes you learned to draw in grade school was probably a star. It is a pretty easy shape to draw, looks pretty cool, and can be done entirely with straight lines. The only tricky part is determining how to go from one point of the star to the next. Today, you will figure that part out.

Details

In Emacs, create a Python program in a file called star.py. Your program should use the turtle module to draw a five-pointed star.

Example

  • Drawing the star is much easier if you use the functions turtle.forward and either turtle.left or turtle.right.
  • Note that the turtle will need to turn once for each point of the star and that it will turn a total of 720°. So, you can calculate the number of degrees in each turn.
  • Finally, drawing the star is simply alternating between moving forward and turning.

House

One of the great advantages to using a computer for drawing is that it is possible to draw precisely. It makes creating something perfectly symmetrical very easy.

Details

In Emacs, create a Python program in a file called house.py. Your program should use the turtle module to draw a simple house. The house should be a square with a triangle for a roof, and a rectangle for a door. The house should be symmetrical about a vertical line.

Example

The trickiest part of the house is getting the roof to fit perfectly. To get it to fit perfectly, you need to calculate the angle of the roof and the length of the roof edges. If you use a 45-45-90 triangle, then the roof angle 45 is degrees and the roof length is the house width divided by the square root of 2.

Challenge

Spruce up the house. Add things like a chimney, the sun, a tree, a mailbox, a fence, whatever you want, as long as it impresses me.