aboutsummaryrefslogtreecommitdiff
path: root/oshw_logo.html
blob: 54f3fbde036da572642fc098b1a42a9035a6b3fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title>open source hardware logo generator</title>
	<script type="text/javascript" src="cvlp_lib.js"></script>
	<script type="text/javascript" src="lib/FileSaver.min.js"></script> 
	<script type="text/javascript" src="lib/jszip.min.js"></script>
</head>
<body onload="draw()">
	<script type="text/javascript">
		/*  page for creating an Open Source Hardware logo using the CuVoodoo Land Pattern (cvlp) library
		    Copyright (C) 2015 King Kévin <kingkevin@cuvoodoo.info>
		
		    This program is free software: you can redistribute it and/or modify
		    it under the terms of the GNU Affero General Public License as published by
		    the Free Software Foundation, either version 3 of the License, or
		    (at your option) any later version.
		
		    This program is distributed in the hope that it will be useful,
		    but WITHOUT ANY WARRANTY; without even the implied warranty of
		    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
		    GNU Affero General Public License for more details.
		
		    You should have received a copy of the GNU Affero General Public License
		    along with this program.  If not, see <http://www.gnu.org/licenses/>.
		*/
		// the OSHW logo
		var logo = {
			"name": "open source hardware logo",
			"author": "King Kévin",
			"version": 1,
			"date": "2019-05-13",
			"unit": "mm",
			"elements": []
        }
		// draw logo
		function draw() {
			// get values
			var pad_size = parseFloat(pad_size_input.value)
			var pad_thickness = parseFloat(pad_thickness_input.value)
			var pad_spacing = parseFloat(pad_spacing_input.value)
			var pad_chip_spacing = parseFloat(pad_chip_spacing_input.value)
			var chip_thickness = parseFloat(chip_thickness_input.value)
			var text_thickness = parseFloat(text_thickness_input.value)

			// set values in logo
			var size = pad_size+pad_chip_spacing*2+pad_spacing*5+pad_chip_spacing*2+pad_size
			logo.width = size
			logo.height = size
			var select = document.getElementById("unit")
			var unit = select.options[select.selectedIndex].value
			logo.unit = unit

            // clear elements
		    logo.elements = []

			// draw pads
			for (var i=0; i<6; i++)	{
				if (document.getElementById("pad_layer_copper").checked) {
					var west = cvlp_pad(i + 1, 0 + pad_size / 2, (pad_size + pad_chip_spacing * 2) + pad_spacing * i, pad_size, pad_thickness)
	                logo.elements = logo.elements.concat(west)
					var south = cvlp_pad(i + 7, (pad_size + pad_chip_spacing * 2) + pad_spacing * i, (pad_size + pad_chip_spacing * 2 + pad_spacing * 5 + pad_chip_spacing * 2) + pad_size / 2, pad_thickness, pad_size)
					logo.elements = logo.elements.concat(south)
					var east = cvlp_pad(18 - i, (pad_size + pad_chip_spacing * 2 + pad_spacing * 5 + pad_chip_spacing * 2) + pad_size / 2, (pad_size + pad_chip_spacing * 2) + pad_spacing * i, pad_size, pad_thickness)
					logo.elements = logo.elements.concat(east)
					var north = cvlp_pad(24 - i, pad_size + pad_chip_spacing * 2 + pad_spacing * i, pad_size / 2, pad_thickness, pad_size)
					logo.elements = logo.elements.concat(north)
				} else {
					var west = cvlp_line(0 + pad_thickness / 2, (pad_size + pad_chip_spacing * 2) + pad_spacing * i, pad_size - pad_thickness / 2, (pad_size + pad_chip_spacing * 2) + pad_spacing * i, pad_thickness)
	                logo.elements = logo.elements.concat(west)
					var south = cvlp_line((pad_size + pad_chip_spacing * 2) + pad_spacing * i, (pad_size + pad_chip_spacing * 2 + pad_spacing * 5 + pad_chip_spacing * 2) + pad_thickness / 2, (pad_size + pad_chip_spacing * 2) + pad_spacing * i, (pad_size + pad_chip_spacing * 2 + pad_spacing * 5 + pad_chip_spacing * 2) + pad_size - pad_thickness / 2, pad_thickness)
					logo.elements = logo.elements.concat(south)
					var east = cvlp_line((pad_size + pad_chip_spacing * 2 + pad_spacing * 5 + pad_chip_spacing * 2) + pad_thickness / 2, (pad_size + pad_chip_spacing * 2) + pad_spacing * i, (pad_size + pad_chip_spacing * 2 + pad_spacing * 5 + pad_chip_spacing * 2) + pad_size - pad_thickness / 2, (pad_size + pad_chip_spacing * 2) + pad_spacing * i, pad_thickness)
					logo.elements = logo.elements.concat(east)
					var north = cvlp_line((pad_size + pad_chip_spacing * 2) + pad_spacing * i, pad_thickness / 2, (pad_size + pad_chip_spacing * 2) + pad_spacing * i, pad_size - pad_thickness / 2, pad_thickness)
					logo.elements = logo.elements.concat(north)
				}	
			}
			// draw chip outline
			var chip = cvlp_rectangle(pad_size + pad_chip_spacing, pad_size + pad_chip_spacing, pad_chip_spacing * 2 + pad_spacing * 5, pad_chip_spacing * 2 + pad_spacing * 5, chip_thickness, pad_chip_spacing)
			logo.elements = logo.elements.concat(chip)
			// draw O letter
			var x = pad_size+pad_chip_spacing * 2
			var y = pad_size+pad_chip_spacing * 2
			var text = cvlp_polyline([[x, y],
			                        [x += pad_spacing * 2, y],
			                        [x, y += pad_spacing * 2],
			                        [x += pad_spacing * -2, y],
			                        [x, y += pad_spacing * -2]], text_thickness)
			logo.elements = logo.elements.concat(text)
			// draw S letter
			var x = pad_size + pad_chip_spacing * 2 + pad_spacing * 5
			var y = pad_size + pad_chip_spacing * 2
			var text = cvlp_polyline([[x, y],
			                        [x += pad_spacing * -2, y],
			                        [x, y += pad_spacing],
									[x += pad_spacing * 2, y],
									[x, y += pad_spacing],
									[x += pad_spacing * -2, y]], text_thickness)
			logo.elements = logo.elements.concat(text)
			// draw H letter
			var x = pad_size + pad_chip_spacing * 2
			var y = pad_size + pad_chip_spacing * 2 + pad_spacing * 3
			var text = cvlp_line(x, y, x, y + pad_spacing * 2, text_thickness)
			logo.elements = logo.elements.concat(text)
			var text = cvlp_line(x, y + pad_spacing, x + pad_spacing * 2, y + pad_spacing, text_thickness)
			logo.elements = logo.elements.concat(text)
			var text = cvlp_line(x + pad_spacing * 2, y, x + pad_spacing * 2, y + pad_spacing * 2, text_thickness)
			logo.elements = logo.elements.concat(text)
			// draw W letter
			var x = pad_size + pad_chip_spacing * 2 + pad_spacing * 3
			var y = pad_size + pad_chip_spacing * 2 + pad_spacing * 3
			var text = cvlp_polyline([[x, y],
			                        [x, y += pad_spacing * 2],
			                        [x += pad_spacing, y += pad_spacing * -1],
			                        [x += pad_spacing, y += pad_spacing],
									[x, y += pad_spacing * -2]], text_thickness)
			logo.elements = logo.elements.concat(text)

			var svg = json2svg(logo)
			var div = document.getElementById('svg')
			div.textContent = ""
			div.appendChild(svg)
		}

		function download() {
			var select = document.getElementById("filetype")
			var filetype = select.options[select.selectedIndex].value
			switch (filetype) {
				case 'cvlp':
					var blob = new Blob([JSON.stringify(logo, null, '\t')], {type: "application/json"})
					saveAs(blob, "oshw_logo.cvlp")
					break
				case 'svg':
					var blob = new Blob([new XMLSerializer().serializeToString(json2svg(logo))], {type: "image/svg+xml"})
					saveAs(blob, "oshw_logo.svg")
					break
				case 'pcb-rnd':
					var blob = new Blob([json2subc(logo)], {type: "text/plain"}) // there is no mime type for pcb-rnd yet
					saveAs(blob, "oshw_logo.lht")
					break
				case 'pcb':
					var blob = new Blob([json2pcb(logo)], {type: "application/x-pcb-footprint"})
					saveAs(blob, "oshw_logo.fp")
					break
				case 'kicad':
					var blob = new Blob([json2kicad(logo)], {type: "application/x-kicad-pcb"})
					saveAs(blob, "oshw_logo.kicad_mod")
					break
				case 'eagle':
					var xml = new XMLSerializer().serializeToString(json2eagle(logo))
					xml = '<?xml version="1.0" encoding="utf-8"?>'+xml
					xml = xml.replace(/(>)(<\/*)/g, '$1\n$2') // eagle does not like one liners
					var blob = new Blob([xml], {type: "application/vnd.cadsoft.eagle.board"})
					saveAs(blob, "oshw_logo.lbr")
					break
				case 'zip':
					var zip = new JSZip()
					zip.file("oshw_logo.cvlp", JSON.stringify(logo, null, '\t'))
					zip.file("oshw_logo.svg", new XMLSerializer().serializeToString(json2svg(logo)))
					zip.file("oshw_logo.lht", json2subc(logo))
					zip.file("oshw_logo.fp", json2pcb(logo))
					zip.file("oshw_logo.kicad_mod", json2kicad(logo))
					var xml = new XMLSerializer().serializeToString(json2eagle(logo))
					xml = '<?xml version="1.0" encoding="utf-8"?>'+xml
					xml = xml.replace(/(>)(<\/*)/g, '$1\n$2') // eagle does not like one liners
					zip.file("oshw_logo.lbr", xml)
					var file = zip.generate({type:"blob"})
					saveAs(file, "oshw_logo.zip")
					break
				default:
					console.log("unknown file type: "+filetype)
			}
		}

		function change_unit() {
			var select = document.getElementById("unit")
			var unit = select.options[select.selectedIndex].value

			if (logo.unit==unit) {
				return
			}

			// get values
			var pad_size = parseFloat(pad_size_input.value)
			var pad_thickness = parseFloat(pad_thickness_input.value)
			var pad_spacing = parseFloat(pad_spacing_input.value)
			var pad_chip_spacing = parseFloat(pad_chip_spacing_input.value)
			var chip_thickness = parseFloat(chip_thickness_input.value)
			var text_thickness = parseFloat(text_thickness_input.value)

			// set converted values
			pad_size_input.value = convert_unit(pad_size, logo.unit, unit)
			pad_thickness_input.value = convert_unit(pad_thickness, logo.unit, unit)
			pad_spacing_input.value = convert_unit(pad_spacing, logo.unit, unit)
			pad_chip_spacing_input.value = convert_unit(pad_chip_spacing, logo.unit, unit)
			chip_thickness_input.value = convert_unit(chip_thickness, logo.unit, unit)
			text_thickness_input.value = convert_unit(text_thickness, logo.unit, unit)

			// save unit and redraw
			logo.unit = unit
			draw()
		}
	</script>
	<h2>Open Source Hardware logo generator</h2>
	<p>This is the logo I use for the hardware I design in my <a href="https://www.cuvoodoo.info/">electronics projects</a>.<br/>
It is simple, and more suited for being included in board layouts as it only uses lines and arcs.
Here you can customize it, generate your own version, and save it for your favorite CAD tool (coralEDA pcb-rnd, gEDA pcb, KiCAD, or EAGLE).<br/>
I hold no rights on this logo, or withdraw any if applicable, and you can do whatever you want with it.
It is intended to be used for open source hardware projects (which ever definition and licence you are using).<br/>
The source code for this generator can be found <a href="https://git.cuvoodoo.info/oshw_logo/about/">in this git</a>.<br/>
	</p>
	<div id="svg"></div>
	<p id="control">
		<form onchange="draw()">
			pads on:
			<input type="radio" name="pad_layer" id="pad_layer_copper" value="copper">copper
			<input type="radio" name="pad_layer" id="pad_layer_silkscreen" value="silkscreen" checked="true">silkscreen
		</form>
		unit: <select id="unit" onchange="change_unit()">
			<option value="mm">millimeter (mm)</option>
			<option value="in">inch (in)</option>
			<option value="mil">mil/thou (mil)</option>
		</select><br />
		pad size: <input id="pad_size_input" type="number" step="any" value=3.0 min=0 onchange="draw()"/><br />
		pad thickness: <input id="pad_thickness_input" type="number" step="any" value=1.0 min=0 onchange="draw()"/><br />
		pad spacing: <input id="pad_spacing_input" type="number" step="any" value=2.0 min=0 onchange="draw()"/><br />
		pad-chip spacing: <input id="pad_chip_spacing_input" type="number" step="any" value=1.5 min=0 onchange="draw()"/><br />
		chip thickness: <input id="chip_thickness_input" type="number" step="any" value=1.0 min=0 onchange="draw()"/><br />
		text thickness: <input id="text_thickness_input" type="number" step="any" value=1.0 min=0 onchange="draw()"/><br />
		 <button type="button" onclick="download()">save</button>: <select id="filetype">
<!--
			<option value="cvlp">CuVoodoo Land Pattern (.cvlp)</option>
-->
			<option value="svg">Scalable Vector Graphics (.svg)</option>
			<option value="pcb-rnd">coralEDA pcb-rnd sub-circuit (.lht)</option>
			<option value="pcb">gEDA pcb footprint (.fp)</option>
			<option value="kicad">KiCad s-expr. footprint (.kicad_mod)</option>
			<option value="eagle">EAGLE XML component library (.lbr)</option>
			<option value="zip">all (.zip)</option>
		</select><br />
	</p>
</body>
</html>