-
Notifications
You must be signed in to change notification settings - Fork 0
/
PixelArtPainter.htm
230 lines (190 loc) · 9.19 KB
/
PixelArtPainter.htm
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
<!DOCTYPE html>
<!--
This tool is designed to draw icons and pixel art displayed on matrixes built from Spike Prime ColorLightMatrix modules.
Large parts of the code were created with ChatGPT and manually customized and improved.
Copyright <2023> <LC-jrx>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the “Software”), to deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<html lang="en">
<head>
<title>Pixel Art Painter for Spike Prime ColorLightMatrix</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.1.3/dist/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.14.3/dist/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.1.3/dist/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<style>
body {
position: relative;
margin: 20px auto;
width: 95%;
}
.grid-container {
margin: 20px auto;
width: 99%;
display: grid;
grid-gap: 1px;
}
.grid-item {
background-color: white;
cursor: pointer;
border: 1px solid #000;
}
.selected {
background-color: black;
}
#coordinates {
font-size: 18px;
margin-top: 20px;
margin-bottom: 20px;
}
#resetButton {
margin-top: 20px;
margin-bottom: 20px;
}
.size-container label {
font-weight: bold;
font-size: 0.7em;
}
.size-container input {
width: 60px;
font-size: 0.7em;
}
.size-container {
margin-top: 20px;
}
.container {
width: auto;
max-width: 680px;
margin-top: 20px;
margin-bottom: 20px;
}
.app-container {
margin: auto;
margin-top: 20px;
width: 99%;
}
</style>
</head>
<body>
<main>
<div class="container">
<h1>Pixel Art Painter</h1>
<h3>for Spike Prime ColorLightMatrix (and others)</h3>
<div class="app-container">
<div class="size-container">
<label for="widthInput">Width:</label>
<input type="number" id="widthInput" min="3" step="3" value="6">
<label for="heightInput">Height:</label>
<input type="number" id="heightInput" min="3" step="3" value="6">
<!-- <button id="resizeButton" class="btn btn-primary">Change Matrix Size</button>-->
</div>
<div class="grid-container" id="gridContainer"></div>
<h3>Coordinates</h3>
<div id="coordinates"></div>
<button id="resetButton" class="btn btn-primary btn-sm">Reset Matrix Content</button>
</div>
</div>
</main>
<footer>
<div class="container">
<h4>About</h4>
<p>This tool is designed to draw icons and pixel art displayed on matrixes built from Spike Prime ColorLightMatrix modules. To transfer a drawn picture to Pixel Pics Library copy the coordinates, edit pixel_pics.py, insert a valid new variable, and insert the coordinates.</p>
<p>Large parts of the code were created with <a href="https://chat.openai.com">ChatGPT</a> and manually customized and improved.</p>
<p>The Pixel Art Painter is part of the PortaBrick Arcade project. Learn more at <a href="https://www.lc-jrx.com/en/2023/08/19/creations/machines/moc-portabrick-arcade-636.html">LC-jrx.com</a> and <a href="https://ideas.lego.com/projects/53e8d771-166c-4a35-85d3-25e3512eb799">LEGO Ideas</a>. Source Code is available at <a href="https://github.com/lc-jrx/PortaBrick_Arcade">GitHub</a>. The PortaBrick Arcade, the PortaBrick Arcade software and the PortaBrick Arcade games are licensed under the MIT License.</p>
<h4>Disclaimer</h4>
<p>LEGO® is a trademark of the LEGO Group of companies which does not sponsor, authorize or endorse this project.</p>
</div>
</footer>
<script>
$(document).ready(function() {
let clickedCoordinates = [];
let gridWidth = 6;
let gridHeight = 6;
// Function to create the grid field with the given size
function createGrid() {
let gridContainer = $("#gridContainer");
gridContainer.empty();
let minCellSize = Math.max(5, Math.floor(Math.min(window.innerWidth, window.innerHeight) / Math.max(gridWidth, gridHeight)));
let maxCellSize = 20;
let cellSize = Math.min(minCellSize, maxCellSize);
gridContainer.css("grid-template-columns", "repeat(" + gridWidth + ", " + cellSize + "px)");
gridContainer.css("grid-template-rows", "repeat(" + gridHeight + ", " + cellSize + "px)");
for (let col = 0; col < gridHeight; col++) {
for (let row = 0; row < gridWidth; row++) {
let cellId = "cell_" + row.toString().padStart(2, '0') + col.toString().padStart(2, '0');
gridContainer.append("<div id='" + cellId + "' class='grid-item'></div>");
}
}
}
// Function to update the size of the grid field
function updateGridSize() {
let newWidth = parseInt($("#widthInput").val());
let newHeight = parseInt($("#heightInput").val());
// Verification that the new size is valid
if (newWidth >= 3 && newHeight >= 3 && newWidth <= 30 && newHeight <= 30 && newWidth % 3 === 0 && newHeight % 3 === 0) {
gridWidth = newWidth;
gridHeight = newHeight;
createGrid();
} else {
alert("Height and width must be a multiple of 3. The size of the matrix must be between 3x3 pixels and 30x30 pixels.");
}
}
// Function to reset the grid field and the coordinates list
function resetGrid() {
$(".grid-item").removeClass("selected");
clickedCoordinates = [];
$("#coordinates").empty();
}
// Click event for grid fields
$(document).on("click", ".grid-item", function() {
let cellId = $(this).attr("id");
let coordinates = cellId.replace("cell_", "");
let x = parseInt(coordinates.charAt(0) + coordinates.charAt(1));
let y = parseInt(coordinates.charAt(2) + coordinates.charAt(3));
let newCoordinate = "(" + x + ", " + y + ")";
$(this).toggleClass("selected");
if ($(this).hasClass("selected")) {
clickedCoordinates.push(newCoordinate);
} else {
clickedCoordinates = clickedCoordinates.filter(function(coord) {
return coord !== newCoordinate;
});
}
$("#coordinates").text(clickedCoordinates.join(", "));
});
// Click event for the resize button
$("#resizeButton").click(function() {
updateGridSize();
resetGrid();
});
// Click event for the input fields
$("#widthInput, #heightInput").click(function() {
updateGridSize();
resetGrid();
});
// Click event for the reset button
$("#resetButton").click(function() {
resetGrid();
});
// Key event for the input fields
$("#widthInput, #heightInput").keypress(function(e) {
if (e.which === 13) {
updateGridSize();
resetGrid();
}
});
// Create the grid field with the default size 6x6
createGrid();
});
</script>
</body>
</html>