Skip to content

Instantly share code, notes, and snippets.

@greenmna
Created January 30, 2018 16:47
Show Gist options
  • Save greenmna/0f9945ae2929bb5c375090241c67e194 to your computer and use it in GitHub Desktop.
Save greenmna/0f9945ae2929bb5c375090241c67e194 to your computer and use it in GitHub Desktop.
The basics of Shapes in SVG
license: mit
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
</style>
</head>
<body>
<script>
// Edit the code below to change me!
var svg = d3.select("body").append("svg")
.attr("width", 960)
.attr("height", 540)
svg.append("rect")
.attr("fill", "blue")
.attr("stroke", "black")
.attr("width", 50)
.attr("height", 100)
.attr("x", 200)
.attr("y", 400)
svg.append("rect")
.attr("fill", "red")
.attr("stroke", "black")
.attr("width", 50)
.attr("height", 100)
.attr("x", 300)
.attr("y", 400)
svg.append("rect")
.attr("fill", "white")
.attr("stroke", "black")
.attr("width", 50)
.attr("height", 100)
.attr("x", 250)
.attr("y", 400)
svg.append("rect")
.attr("fill", "white")
.attr("stroke", "black")
.attr("width", 150)
.attr("height", 100)
.attr("x", 100)
.attr("y", 200)
svg.append("circle")
.attr("r", 25)
.attr("cx", 175)
.attr("cy", 250)
.attr("fill", "red")
svg.append("rect")
.attr("fill", "cadetblue")
.attr("stroke", "black")
.attr("width", 150)
.attr("height", 100)
.attr("x", 400)
.attr("y", 200)
svg.append("rect")
.attr("fill", "yellow")
.attr("stroke", "black")
.attr("width", 150)
.attr("height", 40)
.attr("x", 400)
.attr("y", 230)
svg.append("polygon")
.attr("fill", "black")
.attr("width", 50)
.attr("height", 50)
.attr("points", "485,253 401,299 399,201")
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment