CPSC150A
Scientific Computing

Activity 2

Variables and Expressions

Background

The turtle module doesn't have the ability to change the screen background color. You can, however, do it yourself by first drawing a filled rectangle that is centered in the window and is as big as the screen.

Use the turtle.window_width and turtle.window_height functions to get the size of the screen. Use expressions and variables to compute and store the distances the turtle will use.


Triangle

Write a Python program that uses the turtle module to draw an equilateral triangle. The program should use the following variables to define the size and location of the triangle:

  • center_x - the x-coordinate of the center of the triangle
  • center_y - the y-coordinate of the center of the triangle
  • length - the length of the triangle's edges

The program should use the values of the above variables when using turtle graphics to create the drawing of the triangle. Be sure to test your program by using different values for the variables.