DmitrMakeev
commited on
Commit
•
72ae086
1
Parent(s):
0ff5c80
Update koleso.html
Browse files- koleso.html +121 -121
koleso.html
CHANGED
@@ -68,127 +68,127 @@ body {
|
|
68 |
</head>
|
69 |
|
70 |
<body>
|
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 |
-
const
|
99 |
-
const
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
const
|
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 |
-
spinEl.style.background = sector.color;
|
131 |
-
}
|
132 |
-
|
133 |
-
function frame() {
|
134 |
-
if (!angVel) return;
|
135 |
-
angVel *= friction; // Decrement velocity by friction
|
136 |
-
if (angVel < 0.002) {
|
137 |
-
angVel = 0; // Bring to stop
|
138 |
-
const sector = sectors[getIndex()];
|
139 |
-
localStorage.setItem('hasSpun', 'true');
|
140 |
-
console.log('Result:', sector.label); // Вывод значения в консоль
|
141 |
-
}
|
142 |
-
ang += angVel; // Update angle
|
143 |
-
ang %= TAU; // Normalize angle
|
144 |
-
rotate();
|
145 |
-
}
|
146 |
-
|
147 |
-
function engine() {
|
148 |
-
frame();
|
149 |
-
requestAnimationFrame(engine);
|
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 |
-
|
172 |
-
|
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 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
194 |
</html>
|
|
|
68 |
</head>
|
69 |
|
70 |
<body>
|
71 |
+
<div id="wheelOfFortune">
|
72 |
+
<canvas id="wheel" width="300" height="300"></canvas>
|
73 |
+
<div id="spin">Пуск</div>
|
74 |
+
</div>
|
75 |
+
|
76 |
+
<!-- Форма ввода данных -->
|
77 |
+
<div id="registrationForm" style="display: none;">
|
78 |
+
<form id="registration">
|
79 |
+
<input type="text" id="name" name="name" placeholder="Ваше имя" required><br>
|
80 |
+
<input type="email" id="email" name="email" placeholder="Ваш email" required><br>
|
81 |
+
<input type="tel" id="phone" name="phone" placeholder="Ваш телефон" required><br>
|
82 |
+
<label><input type="checkbox" id="newsletter" name="newsletter"> Согласен на рассылку</label><br>
|
83 |
+
<label><input type="checkbox" id="privacyPolicy" name="privacyPolicy" required> Знаком с политикой конфиденциальности</label><br>
|
84 |
+
<button type="submit">Зарегистрироваться</button>
|
85 |
+
</form>
|
86 |
+
</div>
|
87 |
+
|
88 |
+
<script>
|
89 |
+
const sectors = [
|
90 |
+
{ color: '#f82', label: 'VIP', probability: 94 },
|
91 |
+
{ color: '#0bf', label: '10', probability: 1 },
|
92 |
+
{ color: '#fb0', label: '200', probability: 1 },
|
93 |
+
{ color: '#0fb', label: '50', probability: 1 },
|
94 |
+
{ color: '#b0f', label: '100', probability: 1 },
|
95 |
+
{ color: '#f0b', label: '5', probability: 1 },
|
96 |
+
{ color: '#bf0', label: '500', probability: 1 }
|
97 |
+
];
|
98 |
+
const rand = (m, M) => Math.random() * (M - m) + m;
|
99 |
+
const tot = sectors.length;
|
100 |
+
const spinEl = document.querySelector('#spin');
|
101 |
+
const ctx = document.querySelector('#wheel').getContext('2d');
|
102 |
+
const dia = ctx.canvas.width;
|
103 |
+
const rad = dia / 2;
|
104 |
+
const PI = Math.PI;
|
105 |
+
const TAU = 2 * PI;
|
106 |
+
const arc = TAU / sectors.length;
|
107 |
+
const friction = 0.991; // 0.995=soft, 0.99=mid, 0.98=hard
|
108 |
+
let angVel = 0; // Angular velocity
|
109 |
+
let ang = 0; // Angle in radians
|
110 |
+
const getIndex = () => Math.floor(tot - (ang / TAU) * tot) % tot;
|
111 |
+
function drawSector(sector, i) {
|
112 |
+
const ang = arc * i;
|
113 |
+
ctx.save();
|
114 |
+
// COLOR
|
115 |
+
ctx.beginPath();
|
116 |
+
ctx.fillStyle = sector.color;
|
117 |
+
ctx.moveTo(rad, rad);
|
118 |
+
ctx.arc(rad, rad, rad, ang, ang + arc);
|
119 |
+
ctx.lineTo(rad, rad);
|
120 |
+
ctx.fill();
|
121 |
+
// TEXT
|
122 |
+
ctx.translate(rad, rad);
|
123 |
+
ctx.rotate(ang + arc / 2);
|
124 |
+
ctx.textAlign = 'right';
|
125 |
+
ctx.fillStyle = '#fff';
|
126 |
+
ctx.font = 'bold 21px sans-serif'; // Уменьшенный размер шрифта на 30%
|
127 |
+
ctx.fillText(sector.label, rad - 10, 10);
|
128 |
+
//
|
129 |
+
ctx.restore();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
}
|
131 |
+
function rotate() {
|
132 |
+
const sector = sectors[getIndex()];
|
133 |
+
ctx.canvas.style.transform = `rotate(${ang - PI / 2}rad)`;
|
134 |
+
spinEl.textContent = !angVel ? 'Удача!' : sector.label;
|
135 |
+
spinEl.style.background = sector.color;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
}
|
137 |
+
function frame() {
|
138 |
+
if (!angVel) return;
|
139 |
+
angVel *= friction; // Decrement velocity by friction
|
140 |
+
if (angVel < 0.002) {
|
141 |
+
angVel = 0; // Bring to stop
|
142 |
+
const sector = sectors[getIndex()];
|
143 |
+
localStorage.setItem('hasSpun', 'true');
|
144 |
+
console.log('Result:', sector.label); // Вывод значения в консоль
|
145 |
+
showRegistrationForm(); // Показать форму после остановки колеса
|
146 |
+
}
|
147 |
+
ang += angVel; // Update angle
|
148 |
+
ang %= TAU; // Normalize angle
|
149 |
+
rotate();
|
150 |
+
}
|
151 |
+
function engine() {
|
152 |
+
frame();
|
153 |
+
requestAnimationFrame(engine);
|
154 |
+
}
|
155 |
+
function init() {
|
156 |
+
if (!localStorage.getItem('hasSpun')) {
|
157 |
+
localStorage.setItem('hasSpun', 'false');
|
158 |
+
}
|
159 |
+
sectors.forEach(drawSector);
|
160 |
+
rotate(); // Initial rotation
|
161 |
+
engine(); // Start engine
|
162 |
+
spinEl.addEventListener('click', () => {
|
163 |
+
if (localStorage.getItem('hasSpun') === 'false') {
|
164 |
+
localStorage.setItem('hasSpun', 'true');
|
165 |
+
angVel = rand(0.25, 0.45);
|
166 |
+
spinWheel();
|
167 |
+
} else {
|
168 |
+
console.log('You have already spun the wheel.');
|
169 |
+
}
|
170 |
+
});
|
171 |
+
}
|
172 |
+
function spinWheel() {
|
173 |
+
const probabilities = sectors.map(sector => sector.probability);
|
174 |
+
const totalProbability = probabilities.reduce((a, b) => a + b, 0);
|
175 |
+
const random = Math.random() * totalProbability;
|
176 |
+
let cumulativeProbability = 0;
|
177 |
+
for (let i = 0; i < sectors.length; i++) {
|
178 |
+
cumulativeProbability += sectors[i].probability;
|
179 |
+
if (random < cumulativeProbability) {
|
180 |
+
ang = (i + 0.5) * arc;
|
181 |
+
break;
|
182 |
+
}
|
183 |
+
}
|
184 |
+
}
|
185 |
+
function showRegistrationForm() {
|
186 |
+
const wheelOfFortune = document.getElementById('wheelOfFortune');
|
187 |
+
const registrationForm = document.getElementById('registrationForm');
|
188 |
+
wheelOfFortune.style.display = 'none'; // Скрыть колесо
|
189 |
+
registrationForm.style.display = 'block'; // Показать форму
|
190 |
+
}
|
191 |
+
window.onload = init;
|
192 |
+
</script>
|
193 |
+
</body>
|
194 |
</html>
|