Probably really easy, but i´m a newbie in coding. So I want to write a code which asks the user to define the variable n. After that the program should draw a polygon with n corners. Any examples?
Asked
Active
Viewed 216 times
-1
-
What programming language do you use/have you used? – emporerblk Nov 04 '17 at 19:29
-
You should target one programming language and then search this implementation in that programming – Hafiz Mujadid Nov 04 '17 at 19:34
-
look at this link. it has what you want. https://stackoverflow.com/questions/7198144/how-to-draw-a-n-sided-regular-polygon-in-cartesian-coordinates – babyStep Nov 04 '17 at 19:36
-
I´m using Java for programming. – NicoBecker Nov 04 '17 at 19:39
1 Answers
0
Here’s some pseudocode that might help you (I don’t know what language you are specifying):
1) Ask the user for the number of sides, and store it to variable s. 2) For each side, increment the variable n, and run the next line of code. 3) Draw a line between (cos(n*360/s), sin(n*360/s)) and (cos((n-1)*360/s), sin((n-1)*360/s)
You will have drawn a regular polygon with “s” sides and angles!

iPhoenix
- 719
- 7
- 20
-
No problem! This is really all I could do, not having any programming language specified. – iPhoenix Nov 04 '17 at 19:41
-
-