DmitrMakeev commited on
Commit
52eb55e
1 Parent(s): 0f09b13

Update koleso.html

Browse files
Files changed (1) hide show
  1. koleso.html +31 -12
koleso.html CHANGED
@@ -78,13 +78,13 @@ body {
78
  <script>
79
 
80
  const sectors = [
81
- { color: '#f82', label: 'Stack' },
82
- { color: '#0bf', label: '10' },
83
- { color: '#fb0', label: '200' },
84
- { color: '#0fb', label: '50' },
85
- { color: '#b0f', label: '100' },
86
- { color: '#f0b', label: '5' },
87
- { color: '#bf0', label: '500' }
88
  ]
89
 
90
  const rand = (m, M) => Math.random() * (M - m) + m
@@ -99,7 +99,6 @@ 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
 
@@ -118,7 +117,7 @@ function drawSector(sector, i) {
118
  ctx.rotate(ang + arc / 2)
119
  ctx.textAlign = 'right'
120
  ctx.fillStyle = '#fff'
121
- ctx.font = 'bold 30px sans-serif'
122
  ctx.fillText(sector.label, rad - 10, 10)
123
  //
124
  ctx.restore()
@@ -151,19 +150,39 @@ function engine() {
151
  }
152
 
153
  function init() {
 
 
 
 
154
  sectors.forEach(drawSector)
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
 
 
78
  <script>
79
 
80
  const sectors = [
81
+ { color: '#f82', label: 'Stack', probability: 10 },
82
+ { color: '#0bf', label: '10', probability: 20 },
83
+ { color: '#fb0', label: '200', probability: 15 },
84
+ { color: '#0fb', label: '50', probability: 20 },
85
+ { color: '#b0f', label: '100', probability: 15 },
86
+ { color: '#f0b', label: '5', probability: 10 },
87
+ { color: '#bf0', label: '500', probability: 10 }
88
  ]
89
 
90
  const rand = (m, M) => Math.random() * (M - m) + m
 
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
 
103
  const getIndex = () => Math.floor(tot - (ang / TAU) * tot) % tot
104
 
 
117
  ctx.rotate(ang + arc / 2)
118
  ctx.textAlign = 'right'
119
  ctx.fillStyle = '#fff'
120
+ ctx.font = 'bold 21px sans-serif' // Уменьшенный размер шрифта на 30%
121
  ctx.fillText(sector.label, rad - 10, 10)
122
  //
123
  ctx.restore()
 
150
  }
151
 
152
  function init() {
153
+ if (!localStorage.getItem('hasSpun')) {
154
+ localStorage.setItem('hasSpun', 'false')
155
+ }
156
+
157
  sectors.forEach(drawSector)
158
  rotate() // Initial rotation
159
  engine() // Start engine
160
  spinEl.addEventListener('click', () => {
161
+ if (localStorage.getItem('hasSpun') === 'false') {
162
+ localStorage.setItem('hasSpun', 'true')
163
  angVel = rand(0.25, 0.45)
164
+ spinWheel()
165
+ } else {
166
  console.log('You have already spun the wheel.')
167
  }
168
  })
169
  }
170
 
171
+ function spinWheel() {
172
+ const probabilities = sectors.map(sector => sector.probability)
173
+ const totalProbability = probabilities.reduce((a, b) => a + b, 0)
174
+ const random = Math.random() * totalProbability
175
+ let cumulativeProbability = 0
176
+ for (let i = 0; i < sectors.length; i++) {
177
+ cumulativeProbability += sectors[i].probability
178
+ if (random < cumulativeProbability) {
179
+ ang = (i + 0.5) * arc
180
+ break
181
+ }
182
+ }
183
+ }
184
+
185
+ window.onload = init
186
  </script>
187
 
188