DmitrMakeev
commited on
Commit
•
a7bd6bd
1
Parent(s):
7f1c605
Update koleso.html
Browse files- koleso.html +13 -5
koleso.html
CHANGED
@@ -77,7 +77,7 @@ body {
|
|
77 |
|
78 |
<script>
|
79 |
|
80 |
-
|
81 |
{ color: '#f82', label: 'VIP' },
|
82 |
{ color: '#0bf', label: '10' },
|
83 |
{ color: '#fb0', label: '200' },
|
@@ -96,10 +96,10 @@ const rad = dia / 2
|
|
96 |
const PI = Math.PI
|
97 |
const TAU = 2 * PI
|
98 |
const arc = TAU / sectors.length
|
99 |
-
|
100 |
const friction = 0.991 // 0.995=soft, 0.99=mid, 0.98=hard
|
101 |
let angVel = 0 // Angular velocity
|
102 |
let ang = 0 // Angle in radians
|
|
|
103 |
|
104 |
const getIndex = () => Math.floor(tot - (ang / TAU) * tot) % tot
|
105 |
|
@@ -134,7 +134,12 @@ function rotate() {
|
|
134 |
function frame() {
|
135 |
if (!angVel) return
|
136 |
angVel *= friction // Decrement velocity by friction
|
137 |
-
if (angVel < 0.002)
|
|
|
|
|
|
|
|
|
|
|
138 |
ang += angVel // Update angle
|
139 |
ang %= TAU // Normalize angle
|
140 |
rotate()
|
@@ -150,12 +155,15 @@ function init() {
|
|
150 |
rotate() // Initial rotation
|
151 |
engine() // Start engine
|
152 |
spinEl.addEventListener('click', () => {
|
153 |
-
if (!angVel
|
|
|
|
|
|
|
|
|
154 |
})
|
155 |
}
|
156 |
|
157 |
init()
|
158 |
-
|
159 |
</script>
|
160 |
|
161 |
|
|
|
77 |
|
78 |
<script>
|
79 |
|
80 |
+
const sectors = [
|
81 |
{ color: '#f82', label: 'VIP' },
|
82 |
{ color: '#0bf', label: '10' },
|
83 |
{ color: '#fb0', label: '200' },
|
|
|
96 |
const PI = Math.PI
|
97 |
const TAU = 2 * PI
|
98 |
const arc = TAU / sectors.length
|
|
|
99 |
const friction = 0.991 // 0.995=soft, 0.99=mid, 0.98=hard
|
100 |
let angVel = 0 // Angular velocity
|
101 |
let ang = 0 // Angle in radians
|
102 |
+
let hasSpun = localStorage.getItem('hasSpun') === 'true'
|
103 |
|
104 |
const getIndex = () => Math.floor(tot - (ang / TAU) * tot) % tot
|
105 |
|
|
|
134 |
function frame() {
|
135 |
if (!angVel) return
|
136 |
angVel *= friction // Decrement velocity by friction
|
137 |
+
if (angVel < 0.002) {
|
138 |
+
angVel = 0 // Bring to stop
|
139 |
+
const sector = sectors[getIndex()]
|
140 |
+
localStorage.setItem('hasSpun', 'true')
|
141 |
+
console.log('Result:', sector.label)
|
142 |
+
}
|
143 |
ang += angVel // Update angle
|
144 |
ang %= TAU // Normalize angle
|
145 |
rotate()
|
|
|
155 |
rotate() // Initial rotation
|
156 |
engine() // Start engine
|
157 |
spinEl.addEventListener('click', () => {
|
158 |
+
if (!angVel && !hasSpun) {
|
159 |
+
angVel = rand(0.25, 0.45)
|
160 |
+
} else if (hasSpun) {
|
161 |
+
console.log('You have already spun the wheel.')
|
162 |
+
}
|
163 |
})
|
164 |
}
|
165 |
|
166 |
init()
|
|
|
167 |
</script>
|
168 |
|
169 |
|