git ssb

0+

dinoworm 🐛 / solarpunk-icon



Commit fc704a02d1ed48331ea440f2de8a5ec2def88696

add gear (with hexagon for free!)

Michael Williams committed on 2/6/2019, 10:31:07 AM
Parent: 833c11d6f60087413d4aef03eba96ff9cb0e516d

Files changed

icon.svgchanged
index.jschanged
package.jsonchanged
icon.svg
icon.svg
index.jsView
@@ -1,43 +1,80 @@
11 module.exports = solarpunkIcon
22
33 function solarpunkIcon () {
44 return `
5-<svg
6- xmlns="http://www.w3.org/2000/svg"
7- xmlns:xlink="http://www.w3.org/1999/xlink"
8- viewBox="-1 -1 2 2"
9->
10- ${moon.style}
11- ${range({ start: 0, stop: 1, step: 1/8 })
12- .map(index => moon({
13- radius: 0.1,
14- center: rotate({ angle: index * 2 * Math.PI, point: { x: 0, y: 0.5 } }),
15- phase: index
16- }))
17- .join('\n')
18- }
19-</svg>
20-`
5 + <svg
6 + xmlns="http://www.w3.org/2000/svg"
7 + xmlns:xlink="http://www.w3.org/1999/xlink"
8 + viewBox="-1 -1 2 2"
9 + >
10 + ${moons({ moonRadius: 0.1, centerRadius: 0.7 })}
11 + ${gears({ centerRadius: 0.15, toothLength: 0.3, toothWidth: 0.2 })}
12 + </svg>
13 + `
2114 }
2215
23-function gear ({ center, numThreads, threadLength, centerLength }) {
16 +function gears ({ centerRadius, toothLength, toothWidth }) {
2417 return `
25-<g>
26-
27-</g>
28-`
18 + <style type="text/css">
19 + .gear {
20 + stroke: black;
21 + stroke-width: ${toothLength / 20};
22 + }
23 + .gear-tooth {
24 + fill: purple;
25 + }
26 + </style>
27 + <g class="gear">
28 + ${range({ start: 0, stop: 1, step: 1/8 })
29 + .map(index => gearTooth({
30 + angle: (1/16 + index) * 2 * Math.PI,
31 + offset: centerRadius,
32 + length: toothLength,
33 + width: toothWidth
34 + }))
35 + .join('\n')
36 + }
37 + </g>
38 + `
2939 }
3040
31-function rotate ({ center = { x: 0, y: 0}, angle, point }) {
32- const a = Math.atan2(point.y - center.y, point.x - center.x)
33- const r = Math.sqrt(Math.pow(point.x - center.x, 2) + Math.pow(point.y - center.y, 2))
34- return {
35- x: r * Math.cos(a + angle),
36- y: r * Math.sin(a + angle)
37- }
41 +function gearTooth ({ angle, offset, length, width }) {
42 + return `
43 + <g
44 + class="gear-tooth"
45 + transform="rotate(${angle * 180 / Math.PI})"
46 + >
47 + <rect x="${-width / 2}" y="${offset}" height="${length}" width="${width}" />
48 + </g>
49 + `
3850 }
3951
52 +function moons ({ moonRadius, centerRadius }) {
53 + return `
54 + <style type="text/css">
55 + .moon {
56 + stroke: black;
57 + stroke-width: ${moonRadius / 20};
58 + }
59 + .moon-front {
60 + fill: white;
61 + }
62 + .moon-back {
63 + fill: purple;
64 + }
65 + </style>
66 + ${range({ start: 0, stop: 1, step: 1/8 })
67 + .map(index => moon({
68 + radius: moonRadius,
69 + center: rotate({ angle: index * 2 * Math.PI, point: { x: 0, y: centerRadius } }),
70 + phase: index
71 + }))
72 + .join('\n')
73 + }
74 + `
75 +}
76 +
4077 // inspired by https://github.com/tingletech/moon-phase
4178 function moon ({ radius, center, phase }) {
4279 var sweep = []
4380 var mag
@@ -62,29 +99,11 @@
6299
63100 // http://www.w3.org/TR/SVG/paths.html#PathDataEllipticalArcCommands
64101 // http://www.i-programmer.info/programming/graphics-and-imaging/3254-svg-javascript-and-the-dom.html
65102
66- /*
67- var d = "m100,0 ";
68- d = d + "a" + mag + ",20 0 1," + sweep[0] + " 0,150 ";
69- d = d + "a20,20 0 1," + sweep[1] + " 0,-150";
70- */
71-
72103 var r = radius / 5
73104
74105 return `
75- <style type="text/css">
76- .moon {
77- stroke: black;
78- stroke-width: ${radius / 20};
79- }
80- .moon-front {
81- fill: white;
82- }
83- .moon-back {
84- fill: purple;
85- }
86- </style>
87106 <g class="moon">
88107 <path
89108 class="moon-back"
90109 d="M ${center.x},${center.y - radius / 2}
@@ -98,12 +117,20 @@
98117 a ${r},${r} 0 1,${sweep[1]} 0,-${radius}"
99118 />
100119 </g>
101120 `
121 +}
102122
103- // d="m100,0 a20,20 0 1,1 0,150 a20,20 0 1,1 0,-150"
123 +function rotate ({ center = { x: 0, y: 0}, angle, point }) {
124 + const a = Math.atan2(point.y - center.y, point.x - center.x)
125 + const r = Math.sqrt(Math.pow(point.x - center.x, 2) + Math.pow(point.y - center.y, 2))
126 + return {
127 + x: r * Math.cos(a + angle),
128 + y: r * Math.sin(a + angle)
129 + }
104130 }
105131
132 +
106133 // https://stackoverflow.com/a/44957114
107134 function range ({ start = 0, stop, step = 1 }) {
108135 return Array(Math.ceil((stop - start) / step))
109136 .fill(start).map((x, y) => x + y * step)
package.jsonView
@@ -3,23 +3,17 @@
33 "version": "0.0.0",
44 "description": "a solarpunk icon generated from JavaScript code",
55 "main": "index.js",
66 "scripts": {
7- "start": "node-dev example",
87 "style:format": "prettier-standard '**/*.js' '**/*.md'",
98 "style:lint": "standard",
109 "style": "npm-run-all -s style:format style:lint",
11- "test:deps": "dependency-check . && dependency-check . --extra --no-dev -i es2040",
10 + "test:deps": "dependency-check . && dependency-check . --extra --no-dev",
1211 "test:node": "ava",
1312 "test:coverage": "nyc npm run test:node",
1413 "test:coverage:report": "nyc report --reporter=lcov npm run test:node",
1514 "test": "npm-run-all -s test:node style:lint test:deps"
1615 },
17- "browserify": {
18- "transform": [
19- "es2040"
20- ]
21- },
2216 "lint-staged": {
2317 "linters": {
2418 "*.js": [
2519 "prettier-standard",
@@ -51,14 +45,10 @@
5145 "ava": "^0.25.0",
5246 "dependency-check": "^3.1.0",
5347 "husky": "^0.14.3",
5448 "lint-staged": "^7.0.5",
55- "node-dev": "^3.1.3",
5649 "npm-run-all": "^4.0.1",
5750 "nyc": "^11.7.1",
5851 "prettier-standard": "^8.0.1",
5952 "standard": "^11.0.1"
60- },
61- "dependencies": {
62- "es2040": "^1.2.3"
6353 }
6454 }

Built with git-ssb-web