Pygame Draw Triangle

Python has a simple pen drawing library called turtle. Using simple movement commands, we can draw shapes using the python turtle library. When teaching python to children, turtle is a good library to introduce to get children excited about the language and its features.

The basic actions used in the following examples are,

Syntax

With this function you can draw either an outline of a triangle or a filled triangle. Example: drawsetcolour(caqua); drawtriangle(50, 50, 200, 50, 50, 200, 0); This will draw a filled aquamarine-coloured isosceles right-angled triangle, with its first corner at. Draw a trigon/triangle: pygame.gfxdraw.aatrigon. See the pygame.draw pygame module for drawing shapes module for alternative draw methods. The pygame.gfxdraw module differs from the pygame.draw pygame module for drawing shapes module in the API it uses and the different draw functions available.

  • Draw a line with pen – forward() command
  • Move without drawing – penup(), pendown() commands
  • Turn the pen to an angle – left(), right() commands

The following python program draws a simple equilateral triangle,

Pygame Polygon

The following python program draws a right angled triangle,

The following python program draws a star shape by drawing two identical isosceles triangles,

A. Write a triangle solver that takes 3 inputs consisting of angles in degrees and length
of sides in arbitrary units and, if possible (your program has to determine this),
supplies all other angles and side lengths. There will be either 0 triangles, 1 triangle,
2 triangles or an infinite number of triangles – you program must determine which
possibility. Classify the type of triangle (right triangle, isosceles, equilateral, acute,
obtuse – see any good geometry book. Finally, use the Turtle module to draw the
triangle(s) with correct relative dimensions.

  • 7 Contributors
  • forum6 Replies
  • 17,178 Views
  • 4 Years Discussion Span
  • commentLatest Postby JamesCherrill

Recommended Answers

The first paragraph here will help get you started:
'>http://docs.python.org/py3k/library/turtle.html

This will help understand triangles:
'>http://www.freemathhelp.com/feliz-angles-triangle.html

Pygame Draw Polygon

The key part is understanding that all triangles will have …

Jump to Post

All 6 Replies

The first paragraph here will help get you started:
'>http://docs.python.org/py3k/library/turtle.html

This will help understand triangles:
'>http://www.freemathhelp.com/feliz-angles-triangle.html

Pygame Draw Triangle Syntax

The key part is understanding that all triangles will have a total of 180* as the sum of all angles. That means, given your 3 inputs, if they don't add up to 180* then it's not a triangle.

Pygame.draw.polygon Triangle

You have a lot of choices on how to start. A better way for us to help you is to start writing some code, and when you have trouble or get stuck, then ask. Homework is meant for you to learn, not for people on a message board to do it for you.