-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmagic_matric.html
131 lines (117 loc) · 3.37 KB
/
magic_matric.html
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
<!DOCTYPE html>
<html>
<head>
<title>Magic Matrix - Generator</title>
<link rel="icon" type="image/png" href="/images/rahul3v.png">
<meta name="viewport" content="width=device-width, initial-scale=.8">
</head>
<body>
<style type="text/css">
*,
*::before,
*::after {box-sizing: border-box;}
body {margin:0;background: #f5f5f5;-webkit-tap-highlight-color:transparent;touch-action: manipulation;}
body,html,#game{height: 100%;}
.grid {
display:grid;
height:100%;
place-content: center;
grid-template: repeat(3,30vmin)/repeat(3,30vmin);
grid-gap: .66vmin;
font-size: 1vmin;
color:white;
/*transition:font-size 1s;*/
}
.card {
position: relative;
transition: all .4s linear;
transform-style: preserve-3d;
}
.card,
.back,
.front {
height: 100%;
width: 100%;
}
.back,
.front {
position: absolute;
backface-visibility: hidden;
display: flex;
justify-content:center;
align-items:center;
}
.front {
background-color: #f27d9a;
cursor:pointer;
/*background: #42FAB3 url('/images/rahul3v.png') no-repeat center center / contain fixed;*//*#FAB942*/
}
.back {
background: #42FAB3 url('/images/rahul3v.png') no-repeat center center / contain fixed; /*#FAB942*/
transform: rotateY(180deg);
}
.card:hover {transform: rotateY(180deg);}
.match .front {
visibility: hidden;
pointer-events: none; /**/
}
.fixed{position:fixed;top:0;left:0;font-size:20px;background-color:#f27d9a;padding:5px 16px;box-shadow:0 2px 4px rgba(0,0,0,0.4);}
</style>
<div class="fixed">Magic Matrix - Generator</div>
<div id="game">
<section class="grid" id="grid">
<!--
<p id="matrix">Print Matrix here</p>-->
</section></div>
<script>
var genrate=(num)=>{
// alert(num);
let card = document.createElement('div');
card.classList.add('card');
let front = document.createElement('div');
front.classList.add('front');
front.textContent=num;
let back = document.createElement('div');
back.classList.add('back');
grid.appendChild(card);
card.appendChild(front);
card.appendChild(back);
}
var n=prompt("Enter your magic matrix size (Must be odd) : ",3);
n=Number(n);
if(n%2==0){alert("Magic matrix size must be an odd");location.reload();}
else {
document.querySelector(".fixed").innerHTML+="<br><b> "+n+" x "+n+"</b>";
grid.style.gridTemplate=`repeat(${n},${80/n}vmin)/repeat(${n},${80/n}vmin)`;
grid.style.gridGap=`${3/n}vmin`;
grid.style.fontSize=`${30/n}vmin`;
var m={},z=[],r=n,c=Math.floor(n/2)-1,k=1;
for(var i=0;i<n;i++){m[i]=new Array(n);}
//matrix.innerHTML="";
// matrix.innerHTML+=JSON.stringify(m)+"<br>";
for(i=0;i<n;i++){
for(j=0;j<n;j++){
r=(r+n)%n;
c++;c%=n;
m[r][c]=k;
k++;
if(k%n==1){r++;c--;}
else{r--;}
}
}
// matrix.innerHTML+="Your Magic Matrix :<br>"+JSON.stringify(m)+"<br>";
for(var i=0;i<n;i++) {
for(var j=0;j<n;j++) {
//matrix.innerHTML+=m[i][j];
genrate(m[i][j]);
/*if(m[i][j]<10)matrix.innerHTML+=" ";
else if(m[i][j]<100)matrix.innerHTML+=" ";
else if(m[i][j]<1000)matrix.innerHTML+=" ";
else matrix.innerHTML+=" ";*/
}
//matrix.innerHTML+="<br>";
}
}
</script>
</body>
</html>