-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.html
531 lines (472 loc) · 17.4 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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Oy Pusulası Yapıcı</title>
<!-- CSS Reset -->
<link rel="stylesheet" href="//cdn.rawgit.com/necolas/normalize.css/master/normalize.css">
<!-- You should properly set the path from the main file. -->
<link href="https://fonts.googleapis.com/css?family=Indie+Flower" rel="stylesheet">
<meta property="og:title" content="Oy Pusulası Fotoğrafı Yapıcı"/>
<meta property="og:image" content="https://midorikocak.github.io/pusula/og-image.png"/>
<meta property="og:description"
content="Oy pusulası fotoğrafı isteyen işyerleri için, oy pusulası fotoğrafı yapıcı"/>
<meta property="og:url" content="https://midorikocak.github.io/pusula"/>
</head>
<style>
@charset "utf-8";
@font-face {
font-family: 'AHundredMiles';
src: url('AHundredMiles.ttf');
}
#my-canvas {
border: 1px solid #ababab;
font-family: 'AHundredMiles', 'Indie Flower', cursive;
color: blue;
}
#indir {
color: blue;
text-decoration: underline;
cursor: pointer;
}
</style>
<body>
<h1>Oy pusulası fotoğrafı yapıcı 24 Haziran</h1>
<a href="https://www.mynameismidori.com">Midori Kocak</a> tarafından HTML5 ve Javascript kullanılarak yazılmıştır.
#T A M A M
<br><br>
Destek için:<br><br>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="7N3QMNGG26ZYC">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit"
alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
<p>
Oy pusulası fotoğrafı isteyen işyerleri için, oy pusulası fotoğrafı yapıcı<br/>
<ul>
<li>
Oy vermek için pusulanın üzerine tıklayın.
</li>
<li>
Pusulayı, evet mührünü, zarfı, kartvizit ve kimliği sürükle bırak özelliğiyle hareket ettirebilirsiniz.
</li>
<li>
İsim yazmak için, isminizi yazdıktan sonra ismin görünmesini istediğiniz yere tıklayın
</li>
<li>
Resme kimlik koymak için, kimlik yükledikten sonra kimliğin görünmesini istediğiniz yere tıklayın
</li>
<li>
Mobilden inmiyorsa ekran resmi alın.
</li>
<li>
Masanın üzerinde zarf olsun istiyorsanız, zarf kutusunu işaretleyin. Baştan başlaya tıklayın.
</li>
<li>
Baştan başlaya tıklayınca zemin değişir.
</li>
</ul>
</p>
Kimlik Yüklemek için (İsteğe bağlı): <input type="file" id="imageLoader" name="imageLoader"/>
<br/><br/>
Özel kağıt, resim, kartvizit yüklemek için (İsteğe bağlı): <input type="file" id="imageLoader2"
name="imageLoader2"/><br/>
<br>
Zarflı zemin: <input type="checkbox" id="zarf"> Gölge var: <input type="checkbox" id="golge"> Filtre var: <input type="checkbox" id="filterCheck" checked>
<br>
<form>
<p>Pusula Türü:</p>
<div>
<input type="radio" id="cb"
name="contact" value="cb">
<label for="cb">Cumhurbaşkanı</label>
<input type="radio" id="mv"
name="contact" value="mv">
<label for="mv">Milletvekili</label>
</div>
</form>
<br>
İsminiz (İsteğe bağlı): <input type="text" id="isim"/>
<br>
<br>
<button id="bastan">Baştan başla</button>
<a id="indir">İndir</a>
<br>
<br>
<canvas id="my-canvas" width="800" height="600"></canvas>
</body>
<script>
var canvas = document.getElementById('my-canvas')
var ctx = canvas.getContext('2d')
var imgs = [], grab
var shadowBlur = 0, shadowOffsetX = 0, shadowOffsetY = 0
var cbSelector = document.getElementById('cb')
cbSelector.addEventListener('click', function () {
changeBallot(false);
});
var mvSelector = document.getElementById('mv')
mvSelector.addEventListener('click', function () {
changeBallot(true);
});
/* x, y: coords. w, h: width, height.
* angle: rotation around origin. drag: can we drag this? loadedImage: Image, drawFunc: update function */
function Img(x, y, w, h, angle, drag, loadedImage) {
this.x = x
this.y = y
this.w = w
this.h = h
this.angle = angle
this.drag = drag
this.loadedImage = loadedImage
this.drawFunc = function () {
console.log('no drawFunc set', this)
}
imgs.push(this)
}
function drawPlain(img) {
ctx.save()
ctx.translate(img.x, img.y)
ctx.rotate(img.angle)
ctx.drawImage(img.loadedImage, 0, 0, img.w, img.h)
ctx.restore()
}
function drawFilter(img) {
ctx.save()
ctx.translate(img.x, img.y)
ctx.rotate(img.angle)
ctx.globalCompositeOperation = 'multiply';
ctx.drawImage(img.loadedImage, 0, 0, img.w, img.h)
ctx.restore()
}
function drawShadow(img, shadowColor) {
ctx.save()
ctx.translate(img.x, img.y)
ctx.rotate(img.angle)
ctx.shadowColor = shadowColor
ctx.shadowBlur = shadowBlur
ctx.shadowOffsetX = shadowOffsetX
ctx.shadowOffsetY = shadowOffsetY
ctx.drawImage(img.loadedImage, 0, 0, img.w, img.h)
ctx.restore()
}
function rotatePoint(x, y, theta) {
var out = {}
out.x = Math.cos(theta) * x - Math.sin(theta) * y
out.y = Math.sin(theta) * x + Math.cos(theta) * y
return out
}
function loadImage(src, onload) {
// http://www.thefutureoftheweb.com/blog/image-onload-isnt-being-called
var img = new Image()
img.onload = onload
img.src = src
return img
}
function main() {
if (++imagesLoaded < 13) {
return
}
imgs = []
var angle = Math.floor(Math.random() * 10)
var angle2 = Math.floor(Math.random() * 10)
var bgImgs = [wood1, wood2, wood3, wood4, wood5, wood6, wood7, wood8, wood9, wood10, wood11]
oybackground = bgImgs[Math.floor(Math.random() * bgImgs.length)]
bg = new Img(-100, -100, oybackground.width, oybackground.height,
5 * Math.PI / 180, false, oybackground)
bg.drawFunc = function () {
drawPlain(bg)
}
var zarflizemin = document.getElementById('zarf')
if (zarflizemin.checked == true) {
var angle24 = Math.floor(Math.random() * 10)
var d = angle24 * 20
envelope = new Img(canvas.width / 2 - zarf.width / 2 + d, canvas.height / 2 - zarf.height / 2 + d,
zarf.width, zarf.height, -angle24 * Math.PI / 180, true, zarf)
envelope.drawFunc = function () {
drawShadow(envelope, '#000')
}
}
var cb = document.getElementById('cb');
ballot = new Img(canvas.width / 2 - img2.width / 2, canvas.height / 2 - img2.height / 2 - 50,
img2.width, img2.height, angle * Math.PI / 180, true, img2)
ballot.drawFunc = function () {
drawShadow(ballot, '#000')
}
var filterCheck = document.getElementById('filterCheck')
if (filterCheck.checked == true) {
var filterImage = new Img(0, 0, filter.width, filter.height,
0, false, filter)
filterImage.drawFunc = function () {
drawFilter(filterImage)
}
}
// ballot2 = new Img(canvas.width / 2 - img3.width / 2, canvas.height / 2 - img3.height / 2 - 50,
// img3.width, img3.height, angle2 * Math.PI / 180, true, img3)
// ballot2.drawFunc = function () { drawShadow(ballot2, '#000') }
drawCanvas()
}
function handleImage(e) {
var reader = new FileReader()
reader.onload = function (event) {
var img = new Image()
img.onload = function () {
kimlik = img
}
img.src = event.target.result
}
reader.readAsDataURL(e.target.files[0])
}
function handleImage2(e) {
var reader = new FileReader()
reader.onload = function (event) {
var img = new Image()
img.onload = function () {
ozel = img
}
img.src = event.target.result
}
reader.readAsDataURL(e.target.files[0])
}
function changeBallot(isPM) {
if (isPM === true) {
console.log('changed')
img2 = mv;
} else {
img2 = cb;
}
redraw();
}
var imagesLoaded = 0
var tercih = loadImage('tercih.png', main)
var zarf = loadImage('zarf.png', main)
var wood1 = loadImage('wood1.jpg', main)
var wood2 = loadImage('wood2.jpg', main)
var wood3 = loadImage('wood3.jpg', main)
var wood4 = loadImage('wood4.jpg', main)
var wood5 = loadImage('wood5.jpg', main)
var wood6 = loadImage('wood6.jpg', main)
var wood7 = loadImage('wood7.jpg', main)
var wood8 = loadImage('wood8.jpg', main)
var wood9 = loadImage('wood9.jpg', main)
var wood10 = loadImage('wood10.jpg', main)
var wood11 = loadImage('wood11.jpg', main)
var filter = loadImage('filter.jpg', main)
var cb = loadImage('cb.png', main)
var mv = loadImage('milletvekili.png', main);
var img2 = cb
var papers = loadImage('paper.png', main)
var shadowBlur = 0
var shadowOffsetX = 0
var shadowOffsetY = 0
var kimlik = null
var kimlikResimde = false
var ozel = null
var ozelResimde = false
var isimResimde = false
var secildi = false
document.addEventListener('DOMContentLoaded', function () {
var imageLoader = document.getElementById('imageLoader')
imageLoader.addEventListener('change', handleImage, false)
var imageLoader2 = document.getElementById('imageLoader2')
imageLoader2.addEventListener('change', handleImage2, false)
canvas.addEventListener('click', function (evt) {
var rect = canvas.getBoundingClientRect()
var x = evt.clientX - rect.left
var y = evt.clientY - rect.top
var angle2 = Math.floor(Math.random() * 50)
var isim = document.getElementById('isim').value
if (secildi == false) {
/* tercih */
stamp = new Img(x, y, 45, 45, angle2 * Math.PI / 180, true, tercih)
stamp.drawFunc = function () {
drawPlain(stamp)
}
secildi = true
}
else if (secildi == true && isim != '' && isimResimde == false) {
/* name paper */
var angle3 = Math.floor(Math.random() * 10)
paper = new Img(x, y, 300, 100, angle3 * Math.PI / 180, true, papers)
paper.drawFunc = function () {
drawShadow(paper, '#555555', 10)
ctx.save()
ctx.translate(paper.x, paper.y)
ctx.rotate(paper.angle)
ctx.font = '30px "AHundredMiles"'
var isim = document.getElementById('isim').value
ctx.fillStyle = '#284283'
ctx.fillText(isim, 60, 60)
ctx.restore()
}
isimResimde = true
}
else if (secildi == true && kimlik != null && kimlikResimde == false) {
var angle3 = Math.floor(Math.random() * 30)
idcard = new Img(x, y, 332, 450, angle3 * Math.PI / 180, true, kimlik)
idcard.drawFunc = function () {
drawShadow(idcard, '#000')
}
kimlikResimde = true
}
else if (secildi == true && ozel != null && ozelResimde == false) {
var angle3 = Math.floor(Math.random() * 30)
extra = new Img(x, y, ozel.width, ozel.height, angle3 * Math.PI / 180, true, ozel)
extra.drawFunc = function () {
drawShadow(extra, '#000')
}
ozelResimde = true
}
drawCanvas()
}, false)
function startDrag(x, y) {
var i
for (i = 0; i < imgs.length; i++) {
if (imgs[i].drag == false) {
continue
}
var rot = rotatePoint(x - imgs[i].x, y - imgs[i].y, imgs[i].angle * -1)
var imageX = rot.x
var imageY = rot.y
if (imageX < 0 || imageX > imgs[i].w || imageY < 0 || imageY > imgs[i].h) {
continue
}
/* click is outside image */
grab = {}
grab.img = imgs[i]
grab.origX = imgs[i].x
grab.origY = imgs[i].y
grab.origMouseX = x
grab.origMouseY = y
}
drawCanvas()
}
function drag(x, y) {
if (grab != null) {
grab.img.x = grab.origX - (grab.origMouseX - x)
grab.img.y = grab.origY - (grab.origMouseY - y)
drawCanvas(grab.img)
}
}
function endDrag() {
grab = null
drawCanvas()
}
canvas.addEventListener('mousedown', function (evt) {
var rect = canvas.getBoundingClientRect()
startDrag(evt.clientX - rect.left, evt.clientY - rect.top)
})
canvas.addEventListener('mousemove', function (evt) {
var rect = canvas.getBoundingClientRect()
drag(evt.clientX - rect.left, evt.clientY - rect.top)
})
canvas.addEventListener('mouseup', function (evt) {
endDrag()
})
canvas.addEventListener('touchstart', function (evt) {
var rect = canvas.getBoundingClientRect()
startDrag(evt.touches[0].clientX - rect.left, evt.touches[0].clientY - rect.top)
evt.preventDefault()
})
canvas.addEventListener('touchmove', function (evt) {
var rect = canvas.getBoundingClientRect()
drag(evt.changedTouches[0].clientX - rect.left, evt.changedTouches[0].clientY - rect.top)
evt.preventDefault()
})
canvas.addEventListener('touchend', function (evt) {
endDrag()
/* send click event anyway */
var event = new MouseEvent('click',
{clientX: evt.changedTouches[0].clientX, clientY: evt.changedTouches[0].clientY})
canvas.dispatchEvent(event)
})
var golge = document.getElementById('golge')
golge.onchange = function () {
if (golge.checked) {
window.shadowBlur = 5
window.shadowOffsetX = 1
window.shadowOffsetY = 1
} else {
window.shadowBlur = 0
window.shadowOffsetX = 0
window.shadowOffsetY = 0
}
drawCanvas()
}
drawCanvas()
})
var bastan = document.getElementById('bastan')
bastan.addEventListener('click', function (evt) {
redraw();
})
function redraw() {
imgs = []
secildi = false
kimlikResimde = false
isimResimde = false
ozelResimde = false
ctx.clearRect(0, 0, canvas.width, canvas.height)
main()
drawCanvas()
}
var indir = document.getElementById('indir')
function downloadCanvas(link, canvasId, filename) {
link.href = document.getElementById(canvasId).toDataURL()
link.download = filename
}
indir.addEventListener('click', function (evt) {
downloadCanvas(this, 'my-canvas', 'oy.png')
})
function drawCanvas() {
if (grab !== undefined && grab !== null) {
if (grab.img) {
var fullPath = grab.img.loadedImage.src
var filename = fullPath.replace(/^.*[\\\/]/, '')
if (filename == 'milletvekili.png') {
var index = imgs.indexOf(grab.img)
if (index > -1) {
imgs.splice(index, 1)
}
imgs.push(grab.img)
}
}
}
ctx.clearRect(0, 0, canvas.width, canvas.height)
var i
var tercihImage
var tercihIndex
var j
for (i = 0; i < imgs.length; i++) {
var imageName = imgs[i].loadedImage.src.replace(/^.*[\\\/]/, '')
if (imageName === 'tercih.png') {
tercihImage = imgs[i]
tercihIndex = i
}
}
if (tercihIndex > -1) {
imgs.splice(tercihIndex, 1)
imgs.push(tercihImage)
}
i = 0;
for (i = 0; i < imgs.length; i++) {
imgs[i].drawFunc()
}
}
</script>
<script>
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r
i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date()
a = s.createElement(o),
m = s.getElementsByTagName(o)[0]
a.async = 1
a.src = g
m.parentNode.insertBefore(a, m)
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga')
ga('create', 'UA-55638688-2', 'auto')
ga('send', 'pageview')
</script>
</html>