/    Sign up×
Community /Pin to ProfileBookmark

Changing sides of a shape (polygon)

I am a new learner in Javascript. I am trying to create a dynamic code to change de sides of a “polygon” in the HTML when I select different number of the sides, for instance, a triangle to square (4 sides), and so on preserving the same space that its on the screen.
<poly id=”shape” <polygon id = “poly” points=”100,10 40,198 160,198 “>
<poly id=”shape” <polygon id = “poly” points=”x1,y1 x2,y2 x3,y3 x4,y4 “>

I read some information related to the shape’s angle, and I tried to apply, but it did not work. (Triangle angle 120, Square angle 90, Pentagon angle 72)

Did anyone face this challenge before?
Thanks in advance!

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMar 02.2020 — Probably would want to use some trig functions. For example, sine and cosine are used in this example: http://scienceprimer.com/drawing-regular-polygons-javascript-canvas -- though instead of using the drawing functions, collect the various points it draws to and instead put them into the list for your polygon points.
Copy linkTweet thisAlerts:
@MangotsrealauthorMar 02.2020 — Hello,

I applied with the knowledge that I own until now, saving in variables x and y. It almost worked as I wished, anyway I have a point to start from...

Thanks for your time and your reply.
×

Success!

Help @Mangotsreal spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...