Created
February 5, 2026 14:39
-
-
Save neerajadsul/b25819bbac46d796b0722909cecab943 to your computer and use it in GitHub Desktop.
Python SVG Diamond Sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import svg | |
| from dataclasses import dataclass | |
| @dataclass | |
| class Diamond: | |
| top_node: tuple[int,int] = 0, 0 | |
| height: int = 50 | |
| width: int = 150 | |
| def polygon_points(self): | |
| height, width = self.height, self.width | |
| # North point | |
| x, y = self.top_node | |
| x = x + width // 2 | |
| self.north = x, y | |
| # West Point | |
| self.west = (x - width // 2, y + height // 2) | |
| # South Point | |
| self.south = (x , y + height) | |
| # East Point | |
| self.east = (x + width//2, y + height // 2) | |
| points = [self.north, self.west, self.south, self.east] | |
| return points | |
| print(svg.SVG(elements=[ | |
| svg.Polygon( | |
| points=Diamond( | |
| top_node=(0,0), height=200, width=400).polygon_points(), | |
| stroke="blue", stroke_width=2, fill="white" | |
| ) | |
| ])) | |
| # Output | |
| # <svg xmlns="http://www.w3.org/2000/svg"><polygon stroke="blue" stroke-width="2" points="200 0 0 100 200 200 400 100" fill="white"/></svg> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment