The iconic image of Captain America rendered in high-quality SVG

Is there a way to create this star shape using SVG? I have tried using points but it's not working for me. I cannot use the path element. Any suggestions would be greatly appreciated. Thank you.

<!DOCTYPE html>
<html>

<body>
    <svg width="100" height="100">
       <circle cx="50" cy="50" r="45" fill="white" stroke="red" stroke-width="10" />
       <circle cx="50" cy="50" r="30" stroke="red" stroke-width="10" fill="blue" />
       <polygon points="50,25 30,80 75,40 25,40 70,70" style="fill:white;"/> 
    </svg>
</body>

</html>

Answer №1

To obtain the most precise points for the pentagon shape, you can easily retrieve them from the underlying pentagonal structure.

https://i.sstatic.net/gT5tf.gif

An uncomplicated JavaScript function to acquire these points would look something like this (REPL, which can be used for polygons with any number of edges n):

var n = 5;
var points = [];
for (var i=0; i < n; i++) {
    var x = 50;
    var y = -50;
    var r = 25;
    points.push([x + r * Math.sin(2 * Math.PI * i / n),
                 y + r * Math.cos(2 * Math.PI * i / n)]);
}

The resulting array represents the pentagon's points in a clockwise direction, starting at the top (all values are positive):

[ [ 50, -25 ],
  [ 73.77641290737884, -42.27457514062631 ],
  [ 64.69463130731182, -70.22542485937369 ],
  [ 35.30536869268818, -70.22542485937369 ],
  [ 26.22358709262116, -42.27457514062632 ] ]

The correct order for these points would be

points[x], where x = 0, 3, 1, 4, 2
.

These points can then be utilized in your example, ensuring they are rounded to the nearest pixel:

<!DOCTYPE html>
<html>
<body>
<svg width="100" height="100">
<circle cx="50" cy="50" r="45" fill="white" stroke="red" stroke-width="10" />
  <circle cx="50" cy="50" r="30" stroke="red" stroke-width="10" fill="blue" />
 <polygon points="50,25 35,70 73,42 26,42 65,70" style="fill:white;"/> 
</svg> 
</body>
</html>

Answer №2

This appears to be moving in the right direction.

<!DOCTYPE html>
<html>
<body>

<svg width="100" height="100">
 
<circle cx="50" cy="50" r="45" fill="white" stroke="red" stroke-width="10" />
  
  <circle cx="50" cy="50" r="30" stroke="red" stroke-width="10" fill="blue" />
  
 <polygon points="50,25 35,70 73,42 26,42 65,70" style="fill:white;"/> 
  
</svg> 
 
</body>
</html>

Updated with the reference to @frhd's code, set as community wiki,

Please refer to his solution for computations

Answer №3

Welcome to the path

<svg width="100" height="100">

  <circle cx="50" cy="50" r="45" fill="white" stroke="red" stroke-width="10" />

  <circle cx="50" cy="50" r="30" stroke="red" stroke-width="10" fill="blue" />

  <!-- <polygon points="50,25 30,80 75,40 25,40 70,70" style="fill:white;"/> -->
  <path fill="#fff" d="m50,25 5,17h18l-14,11 5,17-15-10-15,10 5-17-14-11h18z" />
</svg>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using Cordova for mobile applications to play local video files

Our iOS app, developed using PhoneGap / Cordova 4.3.0, loads an external website directly utilizing <content src="http://example.com/foo" /> in the config.xml file. All functionality resides within this website, eliminating the need for local HTML or ...

The eval() function does not run scripts from external sources with a src attribute

Instead of using eval() to execute all <script> tags after completely rewriting a div, I have encountered an issue. The following code snippet works for inline-scripts, but it doesn't have the same effect on external scripts like: <script sr ...

changing the name of a variable within ng-include

Here is some important HTML code: <ng-include src="'app/views/order.html'"></ng-include> Within the scope of this ng-include, there is a variable called trade. The structure of the trade variable is as follows: var trade = { or ...

Obtain the value of the background image's URL

Is there a way to extract the value of the background-image URL that is set directly in the element tag using inline styling? <a style="background-image: url(https:// ....)"></a> I attempted to retrieve this information using var url = $(thi ...

Create a cookie using the JavaScript option

Can you specify cookie settings in JavaScript like CookieOptions in C#? var options = new CookieOptions { IsEssential = true }; I am aware that you can set a cookie in JavaScript using document.cookie = cookieString, but is there a way to include opti ...

Having trouble getting the alert text on the left side of a Bootstrap button with the alert class

Hey there, I managed to create two buttons aligned on opposite sides of my webpage - one on the left and one on the right. Each button, when clicked, displays an alert text on its corresponding side, similar to what you see in this picture https://i.sstati ...

Is there a way to modify the header color in LESS? I attempted to do so, but unfortunately, my changes were unsuccessful

I have encountered an issue with my HTML code. Here's a snippet of it: <html> <head> <link rel="less/less.js" href="css/style.less"> </head> <header> This is a header. </header> </html> Within style.less ...

Designing a carousel-style menu list with navigation buttons for moving forward and backward

I'm running into some trouble while attempting to create a carousel. Firstly, the issue I am facing is that when you continuously click on the Next button, the function keeps working even after reaching the last item. I'm not sure how to make th ...

What is the best way to create a list using only distinct elements from an array?

If I have a collection of different colors: Red Blue Blue Green I aim to extract only the unique colors and store them in an array. Subsequently, I plan to incorporate each color from that array into an existing color list. The desired outcome would l ...

Django positions the save button

Is there a way to update the data in this column using a form, display and save the data, and also add a delete button? I'm seeking a solution for this issue. models.py class Employe(models.Model): Matricule = models.CharField(max_length=10, null=Fal ...

Specialized express Validator for 2 particular fields

I currently have 2 custom validators set up for the fields email and phone. check('phone') .not() .isEmpty() .withMessage('Phone should not be empty') .custom(async phone => { const phoneCheck = await ...

Utilize Vue.js - Link computed properties with data()

I am currently working on an input field that needs to be either blank or pre-populated based on certain conditions. Condition A: If the user is a new student, the field should be blank Condition B: If the user is an existing student, the field should be ...

Unveiling the Truth about Svelte Transitions

Recently, I attempted to incorporate the guidance provided in this repl () for implementing flying and fading effects on divs. However, it seems that I may have a slight misunderstanding regarding the concept... To tackle this, I designed a component rese ...

Disabling the child element from triggering the parent element's onclick function, while still allowing it to respond to its own content

My list elements have onclick-functions that change the display of each element and its child div, moving them to the top of the list. Clicking again reverses this effect. The issue arises because the child div contains search fields, clickable pictures, ...

Display HTML content using JavaScript only when a checkbox is selected

Currently, I am updating an HTML form to show additional subsets of questions based on the selection of a "parent" checkbox. The current implementation works well, but I am wondering if there is a more efficient way to achieve this without having to rewrit ...

What is the best way to create a more compact Select component in React?

Working on React's Select component has been quite the challenge for me. I'm in the process of creating a simple dropdown button, also known as a ComboBox, similar to what can be seen on GitHub Insights: https://i.stack.imgur.com/J9Bcd.png Belo ...

Guide on implementing Regular Expressions in Directives for validation in Angular 8

Managing 8 different angular applications poses its unique challenges. In one of the applications, there is a directive specifically designed for validating YouTube and Vimeo URLs using regular expressions. Unfortunately, once the RegExp is declared, ther ...

The value of a variable remains constant even when it is assigned within a function

I developed a dynamic image slideshow using HTML and JS specifically for the Lively Wallpaper app. This app offers various customization options, which are stored in the LivelyProperties.json file along with input types such as sliders and text boxes. To ...

Searching for data in Node.js using Mongoose and dates

I'm in search of a way to execute a specific query with mongoose. In my mongodb database, I have data structured like this: "startDateTime" : ISODate("2017-03-22T00:00:00.000Z"), "endDateTime" : ISODate("2017-03-27T00:00:00.000Z"), My goal is to r ...

Svelte components loaded with no design aspects applied

I encountered an issue while trying to integrate the "Materialify" and "Carbon Components for Svelte" libraries into my Sapper project. The components seem to be loading, but without any associated styles. I followed the installation commands provided on t ...