forked from codepo8/logo-o-matic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rip.html
85 lines (74 loc) · 2.03 KB
/
rip.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>C-64 charset logo generator</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link rel="stylesheet" href="styles/logogen.css">
</head>
<body>
<img src="img/canvas.png?xx" alt="" id="fonts">
<script>
window.addEventListener('load', function(){
var c = document.createElement('canvas');
document.body.appendChild(c);
var ctx = c.getContext('2d');
var img = document.querySelector('img');
var width = img.naturalWidth;
c.width = width;
c.height = img.naturalHeight;
ctx.drawImage(img,0,0,width,img.naturalHeight);
var startpoint = [0,3251];
var green = {r:62,b:67,g:255,a:255}
var letters = 'abcdefghijklmnopqrstuvwxyz'.split('');
var fontdata = {};
function getfonts() {
var letter = 0;
var letterwidth = 0;
var boundaries = [];
for (var i = 0; i < width; i++) {
var currentcolour = pixelcolour(i, startpoint[1]+5);
if(isgreen(currentcolour) === -1){
letterwidth++;
} else {
if (letterwidth > 0) {
if (letters[letter]) {
fontdata[letters[letter]] = [i-letterwidth, letterwidth];
letter++;
}
}
letterwidth = 0;
}
}
var out = JSON.stringify(fontdata);
console.log(out.replace(/"|\{|\}/g,''));
}
function getheight(startpoint) {
var hy = 0;
var currentcolour = pixelcolour(startpoint[0], startpoint[1]);
while (isgreen(currentcolour) === -1) {
hy++;
currentcolour = pixelcolour(startpoint[0], startpoint[1]+hy);
}
return hy;
}
function isgreen(col) {
return (col.r === green.r &&
col.g === green.g &&
col.b === green.b) ? 1 : -1;
}
function pixelcolour(x,y) {
var pixeldata = ctx.getImageData(x,y,1,1);
return {
r: pixeldata.data[0],
g: pixeldata.data[1],
b: pixeldata.data[2],
a: pixeldata.data[3]
};
}
fontdata.height = getheight(startpoint);
getfonts();
}, false)
</script>
</body>
</html>