How do I create more sides to a polygon - SVG | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

How do I create more sides to a polygon - SVG

How do I create more sides to a polygon to make a Hexagon...

22nd Dec 2016, 7:03 AM
Edi Ferreira
Edi Ferreira - avatar
10 Answers
+ 4
Argh ! It seems to the SoloLearn website as a bug: my code type on app is "web", but on web page it appears ( and open ) as "c++" :( I'll would try to correct... Whatever, you can look at https://code.sololearn.com/W97381dA23Ip/#html in addition ( it's a starting project, from wich I extract the previous snippet )
23rd Dec 2016, 1:26 AM
visph
visph - avatar
+ 4
New ( interactive ) version of my SVG polygons generator, with improvments: https://code.sololearn.com/WFoLMH3mo91T/#html - interactive settings ( always basic parameters radius and number of vertices ) - new parameter: choice between <path> or <polygon> tag to generate - new parameter: formatting precision ( nb max digits after floating point )
23rd Dec 2016, 5:08 AM
visph
visph - avatar
+ 2
What do you means by "more sides" ? SVG's polygons ( <path> tag ) have no limit: <path d="M 100,0 L 50.000000000000014,86.60254037844386 L -49.99999999999998,86.60254037844388 L -100,1.2246467991473532e-14 L -50.00000000000004,-86.60254037844385 L 49.999999999999936,-86.6025403784439 Z"/> Above is an hexagon, radius 100, centered on svg origin ( top left -- with an id attribut, could be set as <defs> and <use> for transforms )... I write a little script to generate it ;) ( https://code.sololearn.com/W6u7XyB817ff/#html )
23rd Dec 2016, 12:04 AM
visph
visph - avatar
+ 2
Nope: it's just quiet simple, and directly output the poliygon code, without querying user from parameters... If you want to use it, edit the JS code ( instructions on comments in the HTML code ;) )
23rd Dec 2016, 12:51 AM
visph
visph - avatar
+ 2
Well, the js snippet his just for auto-generate the tag: here's is implementation with <path> tag, who's like the <polygon> tag must be a child of a <svg> tag... So, the <path> tag can easyly be converted in a <polygon> one: <polygone points="100,0 50.000000000000014,86.60254037844386 -49.99999999999998,86.60254037844388 -100,1.2246467991473532e-14 -50.00000000000004,-86.60254037844385 49.999999999999936,-86.6025403784439"/> ( retrive the letters, and replace "d" attribute by "points" )
23rd Dec 2016, 1:15 AM
visph
visph - avatar
23rd Dec 2016, 1:23 AM
Edi Ferreira
Edi Ferreira - avatar
+ 2
Solved the buggy display on browser ( web site code playground ) by recreation of the project, link edited in previous post...
23rd Dec 2016, 1:36 AM
visph
visph - avatar
0
your code has some kind of bug... because all I can see is your code on the output
23rd Dec 2016, 12:37 AM
Edi Ferreira
Edi Ferreira - avatar
0
I just wanted HTML code, not javascript... Using the polygon tag
23rd Dec 2016, 1:04 AM
Edi Ferreira
Edi Ferreira - avatar
0
When said sides I wanted to say points... polygon points... How that works I couldn't understand on the tutorial...
23rd Dec 2016, 1:14 AM
Edi Ferreira
Edi Ferreira - avatar