-
Notifications
You must be signed in to change notification settings - Fork 0
/
tacoTimer.js
140 lines (118 loc) · 4.11 KB
/
tacoTimer.js
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
const pan = document.getElementById("frying-pan");
const panRadius = 300;
const panRadiusX = pan.offsetLeft + pan.clientWidth / 2;
const panRadiusY = pan.offsetTop + pan.clientHeight / 2;
const undo = document.querySelector('button');
let size = 200;
const first = 3;
const second = 10;
const third = 3;
const inputs = document.querySelectorAll('input');
const stylesheet = document.styleSheets[0];
let coordinates = {};
const tacoClass = document.querySelector('.taco')
undo.addEventListener('click', removeTaco);
inputs.forEach(input => input.addEventListener('change', handleChange));
inputs.forEach(input => input.addEventListener('mouseMove', handleChange));
function handleChange(event) {
if (this.type === 'range') {
size = this.value;
stylesheet.cssRules[0].style.setProperty('--taco-size', this.value + 'px');
let updateTacos = document.querySelectorAll('.taco');
updateTacos.forEach(val => {
let loc = {}
loc.clientX = val.dataset.clientx;
loc.clientY = val.dataset.clienty;
tacoCoordinates(loc);
val.style.setProperty("Left", coordinates.left);
val.style.setProperty("Top", coordinates.top);
})
}
else if (this.name === 'first') {
stylesheet.cssRules[0].style.setProperty('--firstFlip', this.value + 's');
}
else if (this.name === 'second') {
stylesheet.cssRules[0].style.setProperty('--secondFlip', this.value + 's');
}
else stylesheet.cssRules[0].style.setProperty('--thirdFlip', this.value + 's');
}
// pan.addEventListener('click', function (event) { addTaco(event) }); //not sure why keeps adding tacos on top
$('#frying-pan').click(function (event) {
addTaco(event);
})
$('#frying-pan').on('click', '.taco', function (event) {
event.stopPropagation();
let taco = $(this);
taco.text("")
.removeClass('done')
if (taco.data('turn') === 0) {
taco.removeClass('cooking trans');
taco.css('background-color');
taco.addClass('trans2 cooking2')
.data("turn", 1);
taco[0].addEventListener('transitionend', () => {
taco.addClass('done2')
.text("FLIP")
})
}
else if (taco.data("turn") === 1) {
taco.removeClass('cooking2 trans2');
taco.css('background-color');
taco.addClass('trans3 cooking3')
.data("turn", 2)
taco[0].addEventListener('transitionend', () => {
taco.addClass('done3')
.text("DONE")
})
}
else $(this).remove();
})
function removeTaco() {
var badTaco = document.querySelectorAll('.taco:last-child');
badTaco[0].remove()
}
function addTaco(loc) {
tacoCoordinates(loc);
let taco = $("<div>")
.addClass('taco trans')
.appendTo("#frying-pan")
.css(coordinates)
.data("turn", 0)
.attr({ "data-clientX": loc.clientX, "data-clientY": loc.clientY })
taco.css('background-color');
taco.addClass('cooking');
taco[0].addEventListener('transitionend', () => {
taco.addClass('done')
.text("flip")
});
}
function tacoCoordinates(loc) {
let x = loc.clientX - panRadiusX;
let y = -loc.clientY + panRadiusY; //had to flip because Y is measured from top screen down
let angle = (x < 0) ? Math.atan(y / x) + Math.PI : Math.atan(y / x);
let xLimit = Math.cos(angle) * (panRadius - size / 2) + panRadiusX - size / 2;
let yLimit = - Math.sin(angle) * (panRadius - size / 2) + panRadiusY - size / 2;
// console.table({
// 'clientX': loc.clientX,
// 'clientY': loc.clientY,
// 'pageX': loc.pageX,
// 'pageY': loc.pageY,
// 'x': x,
// 'y': y,
// 'xLimit': xLimit,
// 'yLimit': yLimit,
// 'angle': angle
// })
if (x ** 2 + y ** 2 > (panRadius - size / 2) ** 2) {
return coordinates = {
"left": xLimit + 'px',
"top": yLimit + 'px'
};
}
else {
return coordinates = {
"left": loc.clientX - size / 2 + 'px',
"top": loc.clientY - size / 2 + 'px'
}
}
}