Download presentation
Presentation is loading. Please wait.
Published byEugenia Evans Modified over 9 years ago
1
Increase the number of lines before coming back to the origin … triangle square Draw a circle
2
We need to calculate 1) How many lines? (= how many angles?) N 2) The value of each angle?A Any relationship between them??? N = 3 4 5 6 7 8 A = 60 90 108 120 ? ?A =
3
How to calculate an angle…? Use the fact that “The sum of all angles in a triangle is 180 degree” How many triangles in square, pentagon, … etc? T N = 3 4 5 6 7 8 T = 1 2 3 4 5 6
4
N = 3 4 5 6 78 T = 1 2 3 4 56 The number of lines (= number of angles) The number of triangles in each shape S = 180 360 540 720 900 1080 The sum of all angles in each shape A = 60 90 108 120 128135 An angle in each shape
5
N = 3 4 5 6 78 T = 1 2 3 4 56 The number of lines (= number of angles) The number of triangles in each shape S = 180 360 540 720 900 1080 The sum of all angles in each shape A = 60 90 108 120 128135 An angle in each shape N – 2 (N – 2) * 180 (N – 2) * 180 / N
6
A = (N – 2) * 180 / N Given N, the number of lines of a shape Each angle in the shape, A is So, a turtle should turn its face 180-A dgree A AA One more thing we have to be careful …
7
// this method will draw a n-polygon // n will be specified by a user public void drawPolygon( int n, int len ) { int angle = (n - 2) * 180 / n; for(int k=0; k<n; k++) { forward( len ); turn( 180 - angle ); } }
8
Paint a shape There is no method to paint in Turtle class One way to paint is to increase pen width by using a method setPenWidth( int size );
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.