summaryrefslogtreecommitdiff
path: root/index.php
blob: 2b5927332e189bfcb09a06cf600f87c06bfd9e42 (plain)
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
<!DOCTYPE html>

<?php
    $GRID_SIZE = 64;

    $grid = json_decode(file_get_contents('array.json'), true);
    if (empty($grid)) {
        for($x = 0; $x < $GRID_SIZE; ++$x) {
            $grid[$x] = array();
            for($y = 0; $y < $GRID_SIZE; ++$y) {
                $grid[$x][$y] = "#ffffff";
            }
        }
    }

    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
        $pos = explode(",", $_POST["cell"]);
        if ($pos[0] >= 0 && $pos[1] >= 0 && $pos[0] < $GRID_SIZE && $pos[1] < $GRID_SIZE) {
            $grid[$pos[0]][$pos[1]] = $_POST["color"];
            file_put_contents('array.json',  json_encode($grid));
        }
    }
?>

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>cellgrid</title>

    <style>
        @font-face {
            font-family: pixel;
            src: url("font.woff")
        }

        body {
            background: #282a2e;
            color: #c5c8c6;
            font-family: pixel, Courier New, Verdana, Arial;
            font-size: 1em;
            text-align: center;
        }

        .grid {
            overflow: auto;
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
        }

        #selector {
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);

            height: 0%;

            opacity: 0;
            visibility: hidden;
            float: right;

            transition: height 0.5s;
            overflow: hidden;
            white-space: nowrap;
            padding: 1%;
            background: #373b41;
        }

        form:valid > #selector {
            height: 3em;
            visibility: visible;
            opacity: 1;
        }

        input[type="color"] {
            width: 20px;
            height: 20px;
        }

        input[type='radio'] {
            opacity: 0;
            margin: 0;
        }

        input[type='radio']:checked {
            opacity: 1;
            height: 100%;
            width: 100%;
        }

        .cell {
            position: relative;
            width: 10px;
            height: 10px;
        }

        table {
            border: 0.1em solid black;
            font-size: 1px;
            width: 640px;
            height: 640px;
        }



    </style>

</head>

<body>
    <form class="main" action="." method="post">

        <div class="grid">
            <table  border="0" cellspacing="0" cellpadding="0">
                <?php 
                   for($x = 0; $x < $GRID_SIZE; ++$x) {
                       echo("<tr>");
                       for($y = 0; $y < $GRID_SIZE; ++$y) {
                           $id = "$x,$y";
                           $color = $grid[$x][$y];
                           echo "<td style='background-color:$color;'>";
                           echo "<label for='cell$id'>";
                           echo "<input type='radio' name='cell' id='cell$id' value='$id' required>";
                           echo "</label>";
                           echo "</td>";
                       }
                       echo("</tr>");
                   }
               ?>
            </table>
        </div>
        
        <div id="selector">
            <span>Select Color:</span>
            <br>
            <input type="color" id="color" name="color">
            <input type="submit" value="Submit">
        </div>
    </form>
</body>
</html>