-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
142 lines (125 loc) · 4.14 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">
<title>36 days of challenge @opheliagame</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://unpkg.com/acorn"></script>
<script type="text/javascript" src="libs/paper.js"></script>
<script src="https://unpkg.com/[email protected]/dist/paperjs-offset.js"></script>
</head>
<body>
<div>
<label for="letter-type">Select the letter type: </label>
<select name="letter" id="letter-type">
<option value="moving">moving</option>
<option value="master1" selected="selected">master1</option>
<option value="master2">master2</option>
</select>
</div>
<div>
<label for="letter-select">Select the letter to display: </label>
<select name="letter" id="letter-select">
</select>
</div>
<div>
<a style="cursor: pointer; border: 1px solid black;" onclick="saveSVG(this)">Save SVG</a>
</div>
<div style="display: flex;">
<canvas
style="background-color: white;"
width="600px"
height="600px"
id="canvas"
>
</canvas>
<div id="svg"></div>
</div>
<script>
function getBlobURL(content, type) {
return URL.createObjectURL(new Blob([content], {
type: type
}));
}
let letterData = {}
const letterSelect = document.getElementById('letter-select')
const letterType = document.getElementById('letter-type')
const files = fetch('./data.json')
.then(response => response.json())
.then(data => letterData = data)
.then(() => {
const selectNode = document.getElementById('letter-select')
// population in beginning
console.log(letterType.value)
letterData[letterType.value].forEach(element => {
let optionNode = document.createElement('option')
optionNode.value = element
optionNode.innerText = element
selectNode.appendChild(optionNode)
});
})
letterSelect.addEventListener('change', () => {
const fileName = letterSelect.value
executePaper(fileName)
})
letterType.addEventListener('change', () => {
const options = letterData[letterType.value]
letterSelect.innerHTML = ''
options.forEach(element => {
let optionNode = document.createElement('option')
optionNode.value = element
optionNode.innerText = element
letterSelect.appendChild(optionNode)
});
})
const saveSVG = (element) => {
console.log('saving..')
let loc = ''
switch(letterType.value) {
case 'moving':
loc = './font/Moving/'
break
case 'master1':
loc = './font/Master1/'
break
case 'master2':
loc = './font/Master2/'
break
}
const fileLoc = letterSelect.value.split('/').reverse()[0]
var svg = scope.project.exportSVG({ asString: true });
element.href = getBlobURL(svg, 'image/svg+xml');
element.download = fileLoc.split('.')[0] + '.svg'
}
</script>
<script type="text/javascript" canvas="canvas" id="papertest">
var scope
window.onload = () => executePaper('./src/m1src/क.js')
const svgNode = document.getElementById('svg')
const executePaper = (fileName) => {
fetch(fileName)
.then(response => response.text())
.then(data => {
if(scope) scope.remove()
scope = new paper.PaperScope()
scope.setup('canvas')
scope.execute(data)
var strokePath = PaperOffset.offsetStroke(
letterPath,
10,
{ cap: 'butt' }
);
strokePath.fillColor = 'transparent';
strokePath.strokeColor = 'blue';
strokePath.strokeWidth = 0;
letterPath.visible = false;
var svg = scope.project.exportSVG()
svgNode.innerHTML = ''
svgNode.appendChild(svg)
})
}
</script>
</body>
</html>