Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I can only use loops and the API from https://sites.google.com/a/asmsa.org/turtle/class-documentation/documentation I could really use the solution for this. a) Create a method drawPolygon(Turtle turtle, int

image text in transcribed

I can only use loops and the API from

https://sites.google.com/a/asmsa.org/turtle/class-documentation/documentation

I could really use the solution for this.

a) Create a method drawPolygon(Turtle turtle, int sideLength, int numsides) that will draw a regular polygon with numSides sides (i.e. a polygon where all numSides sides are of equal length given by the argument sideLength). You should be able to see from Question01, that there is a pattern in drawing both the equilateral triangle and the square. In this method, you should use a loop (e.g. FOR loop) in order to instruct the turtle to draw the polygon. The recipe (algorithm) for drawing a polygon is summarized in Fig.3. Note that the POLYGON algorithm shows a recipe for drawing a polygon with N sides, each oflength 1. The angles between each of the sides is thus 2T/N (radians), which is equivalent to (360/N degrees). If heading clockwise, the turn should be to the right within each repetition. POLYGON N REPEAT N TIMES FORWARD I TURN 2/N Fig. 3 Create a turtle in your main method, and invoke the drawPolygon method several times to draw several polygons for N-3, 5, 8 (with side lengths: 200, 200, 100 respectively) You should see the following results for each

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Medical Image Databases

Authors: Stephen T.C. Wong

1st Edition

1461375398, 978-1461375395

More Books

Students also viewed these Databases questions