-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
252 lines (228 loc) · 8.12 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
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
246
247
248
249
250
251
252
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Colour a LANCER_01</title>
<link rel="icon" type="image/x-icon" href="./favicon.ico">
<meta name="theme-color" content="#65849f">
<meta property="og:title" content="Colour a LANCER_01">
<meta property="og:site_name" content="GitHub">
<meta name="twitter:site" content="@github">
<meta name="author" content="Dinir Nertan">
<meta name="twitter:creator" content="@DinirNertan">
<meta name="description" content="Recolour the player sprite of Jet Lancer with your choice.">
<meta property="og:description" content="Recolour the player sprite of Jet Lancer with your choice.">
<link rel="canonical" href="https://dinir.github.io/colour-a-lancer/">
<meta property="og:url" content="https://dinir.github.io/colour-a-lancer/">
<meta property="og:image" content="https://dinir.github.io/colour-a-lancer/image/open-graph-image.png">
<meta property="og:image:type" content="image/png">
<meta property="og:image:width" content="978">
<meta property="og:image:height" content="500">
<meta property="og:image:alt" content="Three colour sliders for hue, saturation, value are in the left side. Right side has a preview of a zoomed sprite of a jet, and a preview of all sprite strip below it.">
<meta property="og:type" content="website">
<meta name="viewport" content="width=552">
<meta name="google-site-verification" content="Giwp1vVm5mdTEbNFZEphTPtCn2VKV85F2LIDoSrCsCk">
<link rel="stylesheet" href="./css/main.css">
<link rel="stylesheet" href="./css/picker.css">
<link rel="stylesheet" href="./css/canvasPreview.css">
<script src="./js/iro.min.js"></script>
<script src="./js/ColourChanger.js"></script>
</head>
<body>
<header data-nosnippet>
<h1>Colour a LANCER_01</h1>
<div>
And right-click on the strip of sprites
then save it as <code>player_custom.png</code>
in <code>%localappdata%\JetLancer</code>
<sub>(type this in the file explorer)</sub>.
</div>
</header>
<div id="container" data-nosnippet>
<div id="colour-picker">
<div id="text-input">
<label>
<span>RGB</span>
<input id="hexString" class="listenToChange iro-style-text-input"
type="text" minlength="6" maxlength="7" placeholder="#ffffff">
</label>
</div>
<div id="slider-container">
<!-- div#sliders.IroColorPicker -->
</div>
<div id="slider-text-display">
<label>
<span>H</span>
<input id="hueString" class="listenToChange iro-style-text-input"
type="number" max="360" step="1" placeholder="360">
</label>
<label>
<span>S</span>
<input id="saturationString" class="listenToChange iro-style-text-input"
type="number" max="100" step="1" placeholder="100">
</label>
<label>
<span>V</span>
<input id="valueString" class="listenToChange iro-style-text-input"
type="number" max="100" step="1" placeholder="100">
</label>
</div>
</div>
<div id="preview">
<div id="big-moving-picture">
<canvas class="pixelated-on-zoomed-view" width="256" height="256"></canvas>
</div>
<div id="raw-strip">
<canvas class="pixelated-on-zoomed-view" width="512" height="32"></canvas>
</div>
</div>
</div>
<footer data-nosnippet>
<div>Made by <a href="https://github.com/dinir" target="_blank">Dinir Nertan</a> with ♥ for <a href="http://jetlancergame.com/" target="_blank">Jet Lancer</a>.</div>
<address>
<a href="https://github.com/dinir/jet-lancer-repainter" target="_blank">GitHub Repository</a>
</address>
</footer>
<!-- define common values -->
<script>
const sliderWidth = 256
const sliderMargin = 12
const accentColours = [
'e9345c', 'b6334c', '7b3238', '922532', // top-side, bottom-side: wing and front
'ff90a9', '7b1c33', // end of wing, bottom-side front
'852a39', '5c2126', '5d2126', // bottom-side: center and darker wing
// WHY IS CANVAS CHANGING RANDOM AMOUNT OF BIT OF RGB VALUE ON SOME PIXELS WHEN DRAWING IT STRAIGHT FROM THE STORED IMAGE FILE
'b6334d', 'b7334c', 'ee345a', 'b4304a', '832839', '7b3039', '942431', '5c2026', 'e9355c', '852b39', '922432', '5d2026', '7b3338'
]
const spriteIndex = {
topView: 4,
bottomView: 12
}
</script>
<!-- define dom references -->
<script>
const textInput = {
base: {},
hex: document.getElementById('hexString'),
hue: document.getElementById('hueString'),
saturation: document.getElementById('saturationString'),
value: document.getElementById('valueString'),
}
const canvas = {
big: document.querySelector('#big-moving-picture canvas'),
strip: document.querySelector('#raw-strip canvas')
}
</script>
<!-- create instances -->
<script>
const picker = new iro.ColorPicker('#slider-container', {
id: 'sliders',
width: sliderWidth,
margin: sliderMargin,
display: 'inline-block',
color: accentColours[0],
borderWidth: 2,
borderColor: "#0063db",
layout: [
{
component: iro.ui.Slider,
options: {
sliderType: 'hue'
}
},
{
component: iro.ui.Slider,
options: {
sliderType: 'saturation'
}
},
{
component: iro.ui.Slider,
options: {
sliderType: 'value'
}
}
]
})
const changer = {
big: new ColourChanger(canvas.big, 'image/player_custom.png', {
colours: accentColours,
zoom: 8,
cellView: true,
cellNumber: spriteIndex.topView
}),
strip: new ColourChanger(canvas.strip, 'image/player_custom.png', {
colours: accentColours
})
}
// load `changer.big.imageData` with imageData of all sprite cells
changer.strip.image.addEventListener('load', () => {
changer.big.imageData = changer.strip.imageData
})
</script>
<!-- connect text input elements and the picker -->
<script>
// text input value -> picker
const textInputCommonParent = document.getElementById('colour-picker')
textInputCommonParent.addEventListener('change', function (e) {
if(
e.target.tagName !== 'INPUT' ||
!e.target.classList.contains('listenToChange')
) {
return
}
switch (e.target.id) {
case 'hexString':
// send the value to the picker
picker.color.hexString = e.target.value || '#000000'
break
case 'hueString':
case 'saturationString':
case 'valueString':
// keep the values valid
textInput.hue.value = Math.min(textInput.hue.value, 360) || 0
textInput.saturation.value = Math.min(textInput.saturation.value, 100) || 0
textInput.value.value = Math.min(textInput.value.value, 100) || 0
// send the values to the picker
picker.color.hsv = {
h: textInput.hue.value,
s: textInput.saturation.value,
v: textInput.value.value
}
break
}
})
// picker -> text input value & canvas
picker.on(['color:init', 'color:change'], function(color) {
// update text displays
textInput.hex.value = color.hexString
textInput.hue.value = Math.round(color.hsv.h)
textInput.saturation.value = Math.round(color.hsv.s)
textInput.value.value = Math.round(color.hsv.v)
// apply the new colour and draw the image with it
changer.big.saveConvertedColours(color.hsv.h, color.hsv.s, color.hsv.v)
changer.strip.saveConvertedColours(color.hsv.h, color.hsv.s, color.hsv.v)
changer.big.drawOneCell()
changer.strip.drawEachCell()
})
</script>
<!-- add mouse events -->
<script>
const canvasBigPadding = [132, 68]
canvas.big.addEventListener('mousemove', e => {
const posYFromCanvasStart = Math.max( e.offsetY - canvasBigPadding[1] , 0 )
let yQuantizedPos =
Math.min( Math.floor( posYFromCanvasStart / 16 ) , 16 ) % 16
yQuantizedPos = ( yQuantizedPos + spriteIndex.bottomView ) % 16
if (changer.big.cellNumber !== yQuantizedPos) {
changer.big.cellNumber = yQuantizedPos
changer.big.drawOneCell()
}
})
canvas.big.addEventListener('mouseleave', () => {
changer.big.cellNumber = spriteIndex.topView
changer.big.drawOneCell()
})
</script>
</body>
</html>