-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
143 lines (135 loc) · 6.24 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="favicon.ico"/>
<link rel="stylesheet" href="styles/reset.css">
<link rel="stylesheet" href="styles/main.css">
<link rel="stylesheet" href="styles/desktop.css">
<script src="https://code.jquery.com/jquery-3.6.0.slim.min.js" integrity="sha256-u7e5khyithlIdTpu22PHhENmPcRdFiHRjhAuHcs05RI=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/p5@1.3.0/lib/p5.js"></script>
<script type="text/javascript" src="canvg.js"></script>
<script type="text/javascript" src="script.js"></script>
<title>svg2p5 · Convert SVG to p5.js Canvas</title>
</head>
<body>
<div class="all__wrapper">
<section class="infobox">
<header class="topper topper__white">
<div class="title-side title-left">
<h1>svg2p5</h1>
</div>
<div class="title-side">
<h1>Converter</h1>
</div>
</header>
<article>
<p>
svg2p5 converts SVG markup into p5.js canvas code. It is based on <a class="link-inline" href="http://www.professorcloud.com/svg-to-canvas/" target="_blank" rel="noopener noreferrer"> Professor Cloud</a>’s SVG to HTML5 Converter and the <a class="link-inline" href="https://github.com/canvg/canvg" target="_blank" rel="noopener noreferrer">Canvg.js</a> library.
</p>
<div class="bottom-text">
<ul>
<em>What svg2p5 is <span class="pinktxt">pretty good </span> at:</em>
<li>Béziers made with pen tool.</li>
<li>Path elements with many points.</li>
<li>Strokes and fills.</li>
<li>Colors in HEX and RGBA.</li>
</ul>
<ul>
<em>What svg2p5 <span class="pinktxt">sucks </span> at (for now):</em>
<li>Native elements, like circle and rect.</li>
<li>Color gradients, shadows and opacity.</li>
<li>Anything to do with embedded text.</li>
<li>Clipping and masking of any kind.</li>
</ul>
<p>And many more. Consider filing an issue or contributing to the project.</p>
</div>
</article>
<a href="https://github.com/ygev/svg2p5" target="_blank" rel="noopener noreferrer"><div class="link-big"> 🌱 GitHub Repository</div></a>
</section>
<div class="textarea__wrappers">
<section class="svg__wrapper">
<div class="topper-lines">
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
</div>
<div class="topper topper__white">
<label for="svg">
<h1>SVG Markup</h1>
</label>
</div>
<textarea spellcheck="false" placeholder="Paste <svg> or <path> HTML markup and click Convert." id="svg-input" class="html" name="svg" rows="4" cols="50" onkeyup="setConvertButtonState()"></textarea>
<div class="buttons">
<!-- <button id="clear-button">Clear</button> -->
<button id="convert-button" disabled>Convert</button>
</div>
</section>
<section class="p5__wrapper">
<div class="topper-lines">
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
</div>
<div class="topper topper__white">
<label for="p5">
<h1>p5 Canvas</h1>
</label>
</div>
<textarea spellcheck="false" placeholder="Your p5.js markup will appear here!" id="js-output" name="p5" rows="4" cols="50" onkeyup="setCopyButtonState()"></textarea>
<div class="buttons">
<button id="copy-button" disabled>Copy</button>
</div>
</section>
</div>
<div class="canvas__wrapper" id="canvasWrapper">
<div class="topper topper__white">
<label for="p5">
<h1>Canvas Preview</h1>
</label>
</div>
</div>
</div>
<div id="hiddenSvg" style="display: none;"></div>
<canvas id="temp2"></canvas>
<canvas id="temp"></canvas>
<script>
// secretly render SVG so we can rip out the width
let svgSource = document.getElementById("svg-input").value;
let width = 400; // default
if (svgSource) {
try {
document.getElementById("hiddenSvg").innerHTML = svgSource;
width = document.getElementById("hiddenSvg").children[0].width.baseVal.value;
console.debug("determined svg width: " + width)
} catch (e) {
console.warn("Unable to determine width of SVG; falling back to " + width + ". Error:", e);
}
}
// height is based off container
const height = document.getElementById("canvasWrapper").offsetHeight - 64;
function setup() {
myCanvas = createCanvas(100, 100);
myCanvas.parent("canvasWrapper");
background(0);
}
function draw() {
resizeCanvas(791, height);
let p5Code = document.getElementById("js-output").value;
//console.log(p5Code);
if (p5Code)
eval(p5Code);
else
clear();
}
</script>
</body>
</html>