-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdice_with_long.html
More file actions
258 lines (251 loc) · 7.92 KB
/
dice_with_long.html
File metadata and controls
258 lines (251 loc) · 7.92 KB
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
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<title>3D 주사위와 문장형</title>
<style>
body {
background: #f5f5f5;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
font-family: "Noto Sans KR", sans-serif;
}
h2 {
font-size: 3rem;
margin-bottom: 60px;
}
.dice {
position: relative;
margin: 0 auto 0;
transform-style: preserve-3d;
transform: rotateX(0deg) rotateY(0deg);
transition: transform 1s cubic-bezier(0.36, 1.7, 0.43, 0.87);
cursor: pointer;
width: 400px;
height: 400px;
}
.face {
position: absolute;
width: 400px;
height: 400px;
background: #fff;
border: 8px solid #333;
border-radius: 40px;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}
.front {
transform: rotateY(0deg) translateZ(200px);
}
.back {
transform: rotateY(180deg) translateZ(200px);
}
.right {
transform: rotateY(90deg) translateZ(200px);
}
.left {
transform: rotateY(-90deg) translateZ(200px);
}
.top {
transform: rotateX(90deg) translateZ(200px);
}
.bottom {
transform: rotateX(-90deg) translateZ(200px);
}
.dot {
position: absolute;
width: 80px;
height: 80px;
border-radius: 50%;
}
#result {
font-size: 2.5rem;
margin-top: 60px;
color: #333;
font-weight: bold;
}
.dice-container {
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 40px;
}
#ment-result {
font-size: 6rem;
color: #333;
font-weight: bold;
margin-left: 60px;
min-width: 300px;
text-align: left;
word-break: keep-all;
}
</style>
</head>
<body>
<h2>소개 해보기</h2>
<div id="show-dice-nav" style="position:fixed; left:0; top:50%; transform:translateY(-50%); background:#333; color:#fff; font-size:3rem; width:60px; height:60px; display:none; align-items:center; justify-content:center; border-radius:0 30px 30px 0; cursor:pointer; z-index:1000;">
>
</div>
<div class="dice-container">
<div id="dice3d" class="dice">
<div class="face front"></div>
<div class="face back"></div>
<div class="face right"></div>
<div class="face left"></div>
<div class="face top"></div>
<div class="face bottom"></div>
</div>
</div>
<div id="ment-result"></div>
<div id="result"></div>
<script>
// 각 눈에 해당하는 3D 회전값
const dice3dRotations = [
{ x: 0, y: 0 }, // 1 (front)
{ x: 90, y: 0 }, // 2 (bottom)
{ x: 0, y: -90 }, // 3 (right)
{ x: 0, y: 90 }, // 4 (left)
{ x: -90, y: 0 }, // 5 (top)
{ x: 0, y: 180 }, // 6 (back)
];
// 주사위 눈 점 위치 (400px 기준)
const diceDots = [
[[200, 200]],
[
[100, 100],
[300, 300],
],
[
[100, 100],
[200, 200],
[300, 300],
],
[
[100, 100],
[100, 300],
[300, 100],
[300, 300],
],
[
[100, 100],
[100, 300],
[200, 200],
[300, 100],
[300, 300],
],
[
[100, 100],
[100, 200],
[100, 300],
[300, 100],
[300, 200],
[300, 300],
],
];
// 각 눈(1~6)에 해당하는 색상
const dotColors = [
"#e53935", // 1: 빨강
"#fb8c00", // 2: 주황
"#fdd835", // 3: 노랑
"#43a047", // 4: 초록
"#1e88e5", // 5: 파랑
"#8e24aa", // 6: 보라
];
function setDiceFaceDots() {
const faces = ["front", "back", "right", "left", "top", "bottom"];
document.querySelectorAll(".face").forEach((face, idx) => {
face.innerHTML = "";
let dots = [];
let color = "#222";
switch (faces[idx]) {
case "front":
dots = diceDots[0];
color = dotColors[0];
break; // 1
case "back":
dots = diceDots[5];
color = dotColors[5];
break; // 6
case "right":
dots = diceDots[2];
color = dotColors[2];
break; // 3
case "left":
dots = diceDots[3];
color = dotColors[3];
break; // 4
case "top":
dots = diceDots[4];
color = dotColors[4];
break; // 5
case "bottom":
dots = diceDots[1];
color = dotColors[1];
break; // 2
}
dots.forEach(([cx, cy]) => {
const dot = document.createElement("div");
dot.className = "dot";
dot.style.left = cx - 40 + "px";
dot.style.top = cy - 40 + "px";
dot.style.background = color;
face.appendChild(dot);
});
});
}
setDiceFaceDots();
const dice3d = document.getElementById("dice3d");
const resultDiv = document.getElementById("result");
let shuffledNumbers = [];
let currentIndex = 0;
function shuffleNumbers() {
shuffledNumbers = [1, 2, 3, 4, 5, 6]
.sort(() => Math.random() - 0.5);
currentIndex = 0;
}
shuffleNumbers();
const diceContainer = document.querySelector('.dice-container');
const showDiceNav = document.getElementById('show-dice-nav');
function rollDice3D() {
// 중복 없이 1~6에서 하나씩 추출
if (currentIndex >= shuffledNumbers.length) {
shuffleNumbers();
}
const roll = shuffledNumbers[currentIndex];
currentIndex++;
// 3D 회전 애니메이션
const extraX = 360 * (2 + Math.floor(Math.random() * 2));
const extraY = 360 * (2 + Math.floor(Math.random() * 2));
const rot = dice3dRotations[roll - 1];
dice3d.style.transform = `rotateX(${rot.x + extraX}deg) rotateY(${rot.y + extraY}deg)`;
document.getElementById("ment-result").textContent = "";
setTimeout(() => {
document.getElementById("ment-result").textContent = ment[roll - 1];
// 주사위 숨기고 nav bar 보이기
diceContainer.style.display = "none";
showDiceNav.style.display = "flex";
}, 1000);
}
dice3d.addEventListener("click", rollDice3D);
showDiceNav.addEventListener("click", () => {
diceContainer.style.display = "flex";
showDiceNav.style.display = "none";
document.getElementById("ment-result").textContent = "";
});
//각 눈(1~6)에 해당하는 멘트
const ment = [
"우리 반 친구 한 명에 대해서 소개해 보세요.", // 1번
"여러분이 가지고 있는 물건 중에 가장 좋아하는 것은 무엇입니까? 왜 그것을 좋아합니까? 친구들에게 소개해 보세요.", // 2번
"여러분 나라의 수도는 어디입니까? 그곳은 어떤 곳이고 무엇이 유명합니까? 친구들에게 소개해 보세요.", // 3번
"여러분은 중,고등학교 때 어떤 취미가 있었습니까?", // 4번
"여러분은 배워 보고 싶은 것이 있습니까? 왜 그것을 배우고 싶습니까? 친구들에게 이야기해 보세요.", // 5번
"여러분은 한국에서 어느 도시에 가 봤습니까? 그곳에서 무엇을 했습니까? 여러분의 경험을 이야기해 보세요.", // 6번
];
</script>
</body>
</html>