Docs update for mobile
This commit is contained in:
parent
3ce6b4d20e
commit
14f80f0fb8
4 changed files with 2864 additions and 2865 deletions
|
@ -1,401 +1,397 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
|
||||||
<link
|
|
||||||
rel="icon"
|
|
||||||
href="https://upload.wikimedia.org/wikipedia/commons/0/0f/Original_Ferris.svg"
|
|
||||||
type="image/svg+xml"
|
|
||||||
/>
|
|
||||||
<title>ZennDev1337 Image Converter</title>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body onload="setup(this);">
|
<head>
|
||||||
<style>
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
html,
|
<link rel="icon" href="https://upload.wikimedia.org/wikipedia/commons/0/0f/Original_Ferris.svg"
|
||||||
body {
|
type="image/svg+xml" />
|
||||||
margin: 0;
|
<title>ZennDev1337 Image Converter</title>
|
||||||
background-color: black;
|
</head>
|
||||||
color: azure;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
body {
|
|
||||||
font-family: Courier New;
|
|
||||||
text-align: center;
|
|
||||||
align-items: center;
|
|
||||||
font-size: xx-large;
|
|
||||||
font-weight: 700;
|
|
||||||
}
|
|
||||||
.wrapper {
|
|
||||||
min-height: calc(100vh - 50px);
|
|
||||||
}
|
|
||||||
.footer {
|
|
||||||
font-family: Courier New;
|
|
||||||
text-align: center;
|
|
||||||
font-size: large;
|
|
||||||
font-weight: 600;
|
|
||||||
height: 50px;
|
|
||||||
|
|
||||||
color: #e7e7e7;
|
<body onload="setup(this);">
|
||||||
}
|
<style>
|
||||||
.footer > a {
|
html,
|
||||||
font-family: Courier New;
|
body {
|
||||||
text-align: center;
|
margin: 0;
|
||||||
font-size: large;
|
background-color: black;
|
||||||
font-weight: 700;
|
color: azure;
|
||||||
margin: 0;
|
overflow: hidden;
|
||||||
color: #e7e7e7;
|
}
|
||||||
text-decoration: none;
|
|
||||||
}
|
body {
|
||||||
.sticky {
|
font-family: Courier New;
|
||||||
bottom: 0;
|
text-align: center;
|
||||||
height: 50px;
|
align-items: center;
|
||||||
}
|
font-size: xx-large;
|
||||||
textarea {
|
font-weight: 700;
|
||||||
background-color: #281c1c;
|
}
|
||||||
color: azure;
|
|
||||||
border: dotted 2px #ce422b;
|
.wrapper {
|
||||||
width: 670px;
|
min-height: calc(100vh - 50px);
|
||||||
height: 300px;
|
}
|
||||||
resize: none;
|
|
||||||
}
|
.footer {
|
||||||
.title > p {
|
font-family: Courier New;
|
||||||
padding-left: 20px;
|
text-align: center;
|
||||||
margin: 0;
|
font-size: large;
|
||||||
padding-right: 20px;
|
font-weight: 600;
|
||||||
color: #e7e7e7;
|
height: 50px;
|
||||||
font-size: xx-large;
|
|
||||||
}
|
color: #e7e7e7;
|
||||||
.title {
|
}
|
||||||
padding-top: 50px;
|
|
||||||
}
|
.footer>a {
|
||||||
.separator {
|
font-family: Courier New;
|
||||||
border-top: solid #281c1c;
|
text-align: center;
|
||||||
border-bottom: none;
|
font-size: large;
|
||||||
border-left: none;
|
font-weight: 700;
|
||||||
border-right: none;
|
margin: 0;
|
||||||
margin-top: 40px;
|
color: #e7e7e7;
|
||||||
width: clamp(700px, 70vw, 1200px);
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
.image-container {
|
|
||||||
margin-top: 40px;
|
.sticky {
|
||||||
min-height: 80px;
|
bottom: 0;
|
||||||
}
|
height: 50px;
|
||||||
p {
|
}
|
||||||
font-size: medium;
|
|
||||||
}
|
textarea {
|
||||||
.txtHead {
|
background-color: #281c1c;
|
||||||
margin-bottom: 5px;
|
color: azure;
|
||||||
}
|
border: dotted 2px #ce422b;
|
||||||
.topnav {
|
width: 670px;
|
||||||
background-color: #000000;
|
height: 300px;
|
||||||
overflow: hidden;
|
resize: none;
|
||||||
height: 47px;
|
}
|
||||||
}
|
|
||||||
.topnav a {
|
.title>p {
|
||||||
color: #f2f2f2;
|
padding-left: 20px;
|
||||||
text-align: center;
|
margin: 0;
|
||||||
padding: 14px 16px;
|
padding-right: 20px;
|
||||||
text-decoration: none;
|
color: #e7e7e7;
|
||||||
font-size: 17px;
|
font-size: xx-large;
|
||||||
}
|
}
|
||||||
.topnav a:hover {
|
|
||||||
background-color: #ddd;
|
.title {
|
||||||
color: black;
|
padding-top: 50px;
|
||||||
}
|
}
|
||||||
.topnav a.active {
|
|
||||||
background-color: #281c1c;
|
.separator {
|
||||||
color: white;
|
border-top: solid #281c1c;
|
||||||
}
|
border-bottom: none;
|
||||||
.topnav .icon {
|
border-left: none;
|
||||||
|
border-right: none;
|
||||||
|
margin-top: 40px;
|
||||||
|
width: clamp(700px, 70vw, 1200px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.image-container {
|
||||||
|
margin-top: 40px;
|
||||||
|
min-height: 80px;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
font-size: medium;
|
||||||
|
}
|
||||||
|
|
||||||
|
.txtHead {
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topnav {
|
||||||
|
background-color: #000000;
|
||||||
|
overflow: hidden;
|
||||||
|
height: 47px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topnav a {
|
||||||
|
color: #f2f2f2;
|
||||||
|
text-align: center;
|
||||||
|
padding: 14px 16px;
|
||||||
|
text-decoration: none;
|
||||||
|
font-size: 17px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topnav a:hover {
|
||||||
|
background-color: #ddd;
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topnav a.active {
|
||||||
|
background-color: #281c1c;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topnav .icon {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 810px) {
|
||||||
|
.topnav a:not(:first-child) {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
@media screen and (max-width: 800px) {
|
|
||||||
.topnav a:not(:first-child) {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
.topnav a.icon {
|
|
||||||
float: right;
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@media screen and (max-width: 800px) {
|
|
||||||
.topnav.responsive {
|
|
||||||
position: relative;
|
|
||||||
height: 188px;
|
|
||||||
}
|
|
||||||
.topnav.responsive a.icon {
|
|
||||||
position: absolute;
|
|
||||||
right: 0;
|
|
||||||
top: 0;
|
|
||||||
}
|
|
||||||
.topnav.responsive a {
|
|
||||||
float: none;
|
|
||||||
display: block;
|
|
||||||
text-align: left;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
<div class="wrapper">
|
|
||||||
<div class="topnav" id="myTopnav">
|
|
||||||
<a
|
|
||||||
href="https://zenndev1337.github.io/Rust-for-Arduboy/index.html"
|
|
||||||
>Rust for Arduboy</a
|
|
||||||
>
|
|
||||||
<a
|
|
||||||
href="https://zenndev1337.github.io/Rust-for-Arduboy/image-converter.html"
|
|
||||||
class="active"
|
|
||||||
>Image Converter</a
|
|
||||||
>
|
|
||||||
<a
|
|
||||||
href="https://zenndev1337.github.io/Rust-for-Arduboy/tile-converter.html"
|
|
||||||
>Tile Converter</a
|
|
||||||
>
|
|
||||||
<a
|
|
||||||
href="https://zenndev1337.github.io/Rust-for-Arduboy/sprite-converter.html"
|
|
||||||
>Sprite Converter</a
|
|
||||||
>
|
|
||||||
<a
|
|
||||||
href="javascript:void(0);"
|
|
||||||
class="icon"
|
|
||||||
onclick="myFunction()"
|
|
||||||
>
|
|
||||||
<svg
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
width="16"
|
|
||||||
height="16"
|
|
||||||
fill="currentColor"
|
|
||||||
class="bi bi-list"
|
|
||||||
viewBox="0 0 16 16"
|
|
||||||
>
|
|
||||||
<path
|
|
||||||
fill-rule="evenodd"
|
|
||||||
d="M2.5 12a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5z"
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div class="title">
|
|
||||||
<p>Drop your image here</p>
|
|
||||||
</div>
|
|
||||||
<hr class="separator" />
|
|
||||||
<div class="image-container">
|
|
||||||
<div id="image-container"></div>
|
|
||||||
</div>
|
|
||||||
<hr class="separator" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<footer class="footer">
|
.topnav a.icon {
|
||||||
<a href="https://github.com/ZennDev1337/" target="_blank"
|
float: right;
|
||||||
>By ZennDev1337</a
|
display: block;
|
||||||
>
|
|
||||||
</footer>
|
|
||||||
<script language="JavaScript">
|
|
||||||
function myFunction() {
|
|
||||||
var x = document.getElementById("myTopnav");
|
|
||||||
if (x.className === "topnav") {
|
|
||||||
x.className += " responsive";
|
|
||||||
} else {
|
|
||||||
x.className = "topnav";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
}
|
||||||
<script language="JavaScript">
|
|
||||||
function swapImage(t, e) {
|
@media screen and (max-width: 810px) {
|
||||||
var r = t.getAttribute("data-srcnm");
|
.topnav.responsive {
|
||||||
t.removeAttribute("srcset"),
|
position: relative;
|
||||||
r || t.setAttribute("data-srcnm", t.src),
|
height: 188px;
|
||||||
(t.src = e);
|
|
||||||
}
|
}
|
||||||
function setOriginal(t) {
|
|
||||||
var e = "",
|
.topnav.responsive a.icon {
|
||||||
r = "";
|
position: absolute;
|
||||||
(r = t.getAttribute("data-srcmd")),
|
right: 0;
|
||||||
(e = t.getAttribute("data-srcnm")),
|
top: 0;
|
||||||
r
|
|
||||||
? ((t.src = r), t.removeAttribute("data-srcmd"))
|
|
||||||
: ((t.src = e), t.removeAttribute("data-srcnm"));
|
|
||||||
}
|
}
|
||||||
function swapImageMD(t, e) {
|
|
||||||
t.setAttribute("data-srcmd", t.src), (t.src = e);
|
.topnav.responsive a {
|
||||||
|
float: none;
|
||||||
|
display: block;
|
||||||
|
text-align: left;
|
||||||
}
|
}
|
||||||
function jsready(t) {
|
}
|
||||||
/in/.test(document.readyState)
|
</style>
|
||||||
? setTimeout("jsready(" + t + ")", 9)
|
<div class="wrapper">
|
||||||
: t();
|
<div class="topnav" id="myTopnav">
|
||||||
|
<a href="https://zenndev1337.github.io/Rust-for-Arduboy/index.html">Rust for Arduboy</a>
|
||||||
|
<a href="https://zenndev1337.github.io/Rust-for-Arduboy/image-converter.html" class="active">Image
|
||||||
|
Converter</a>
|
||||||
|
<a href="https://zenndev1337.github.io/Rust-for-Arduboy/tile-converter.html">Tile Converter</a>
|
||||||
|
<a href="https://zenndev1337.github.io/Rust-for-Arduboy/sprite-converter.html">Sprite Converter</a>
|
||||||
|
<a href="javascript:void(0);" class="icon" onclick="myFunction()">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-list"
|
||||||
|
viewBox="0 0 16 16">
|
||||||
|
<path fill-rule="evenodd"
|
||||||
|
d="M2.5 12a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5z" />
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div class="title">
|
||||||
|
<p>Drop your image here</p>
|
||||||
|
</div>
|
||||||
|
<hr class="separator" />
|
||||||
|
<div class="image-container">
|
||||||
|
<div id="image-container"></div>
|
||||||
|
</div>
|
||||||
|
<hr class="separator" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<footer class="footer">
|
||||||
|
<a href="https://github.com/ZennDev1337/" target="_blank">By ZennDev1337</a>
|
||||||
|
</footer>
|
||||||
|
<script language="JavaScript">
|
||||||
|
function myFunction() {
|
||||||
|
var x = document.getElementById("myTopnav");
|
||||||
|
if (x.className === "topnav") {
|
||||||
|
x.className += " responsive";
|
||||||
|
} else {
|
||||||
|
x.className = "topnav";
|
||||||
}
|
}
|
||||||
jsready(function () {
|
}
|
||||||
var t = window.devicePixelRatio ? window.devicePixelRatio : 1;
|
</script>
|
||||||
if (t > 1)
|
<script language="JavaScript">
|
||||||
for (
|
function swapImage(t, e) {
|
||||||
var e = document.getElementsByTagName("img"), r = 0;
|
var r = t.getAttribute("data-srcnm");
|
||||||
r < e.length;
|
t.removeAttribute("srcset"),
|
||||||
r++
|
r || t.setAttribute("data-srcnm", t.src),
|
||||||
)
|
(t.src = e);
|
||||||
e[r].getAttribute("data-src2x") &&
|
}
|
||||||
(e[r].setAttribute(
|
function setOriginal(t) {
|
||||||
"data-src-orig",
|
var e = "",
|
||||||
e[r].getAttribute("src")
|
r = "";
|
||||||
),
|
(r = t.getAttribute("data-srcmd")),
|
||||||
|
(e = t.getAttribute("data-srcnm")),
|
||||||
|
r
|
||||||
|
? ((t.src = r), t.removeAttribute("data-srcmd"))
|
||||||
|
: ((t.src = e), t.removeAttribute("data-srcnm"));
|
||||||
|
}
|
||||||
|
function swapImageMD(t, e) {
|
||||||
|
t.setAttribute("data-srcmd", t.src), (t.src = e);
|
||||||
|
}
|
||||||
|
function jsready(t) {
|
||||||
|
/in/.test(document.readyState)
|
||||||
|
? setTimeout("jsready(" + t + ")", 9)
|
||||||
|
: t();
|
||||||
|
}
|
||||||
|
jsready(function () {
|
||||||
|
var t = window.devicePixelRatio ? window.devicePixelRatio : 1;
|
||||||
|
if (t > 1)
|
||||||
|
for (
|
||||||
|
var e = document.getElementsByTagName("img"), r = 0;
|
||||||
|
r < e.length;
|
||||||
|
r++
|
||||||
|
)
|
||||||
|
e[r].getAttribute("data-src2x") &&
|
||||||
|
(e[r].setAttribute(
|
||||||
|
"data-src-orig",
|
||||||
|
e[r].getAttribute("src")
|
||||||
|
),
|
||||||
e[r].setAttribute(
|
e[r].setAttribute(
|
||||||
"src",
|
"src",
|
||||||
e[r].getAttribute("data-src2x")
|
e[r].getAttribute("data-src2x")
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
|
|
||||||
function setup(body) {
|
function setup(body) {
|
||||||
body.ondragover = function () {
|
body.ondragover = function () {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
body.ondragend = function () {
|
body.ondragend = function () {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
body.ondrop = function (e) {
|
body.ondrop = function (e) {
|
||||||
// Prevent the browser from showing the dropped file
|
// Prevent the browser from showing the dropped file
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
// Get the image data
|
// Get the image data
|
||||||
var imageData = getImageData(e);
|
var imageData = getImageData(e);
|
||||||
|
|
||||||
// If there is some data, add it to the page
|
// If there is some data, add it to the page
|
||||||
if (imageData !== null) {
|
if (imageData !== null) {
|
||||||
addDroppedElement(imageData);
|
addDroppedElement(imageData);
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
function getImageData(event) {
|
|
||||||
var file = event.dataTransfer.files[0];
|
|
||||||
if (file.type.indexOf("image") === 0) {
|
|
||||||
return file;
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function getImageData(event) {
|
||||||
|
var file = event.dataTransfer.files[0];
|
||||||
|
if (file.type.indexOf("image") === 0) {
|
||||||
|
return file;
|
||||||
}
|
}
|
||||||
function addDroppedElement(imageData) {
|
}
|
||||||
var reader = new FileReader();
|
function addDroppedElement(imageData) {
|
||||||
reader.onload = function (event) {
|
var reader = new FileReader();
|
||||||
event.preventDefault;
|
reader.onload = function (event) {
|
||||||
|
event.preventDefault;
|
||||||
|
|
||||||
// Create image element
|
// Create image element
|
||||||
var droppedImage = new Image();
|
var droppedImage = new Image();
|
||||||
droppedImage.src = event.target.result;
|
droppedImage.src = event.target.result;
|
||||||
// add delay so the image can be loaded properly before accessing it
|
// add delay so the image can be loaded properly before accessing it
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
// Create canvas for image
|
// Create canvas for image
|
||||||
var droppedImageCanvas =
|
var droppedImageCanvas =
|
||||||
document.createElement("canvas");
|
document.createElement("canvas");
|
||||||
droppedImageCanvas.width = droppedImage.naturalWidth;
|
droppedImageCanvas.width = droppedImage.naturalWidth;
|
||||||
droppedImageCanvas.height = droppedImage.naturalHeight;
|
droppedImageCanvas.height = droppedImage.naturalHeight;
|
||||||
|
|
||||||
// Create code container
|
// Create code container
|
||||||
var droppedImageCode =
|
var droppedImageCode =
|
||||||
document.createElement("textarea");
|
document.createElement("textarea");
|
||||||
droppedImageCode.className = "code";
|
droppedImageCode.className = "code";
|
||||||
|
|
||||||
droppedImageCode.style.width = "698px";
|
droppedImageCode.style.width = "698px";
|
||||||
droppedImageCode.rows = "20";
|
droppedImageCode.rows = "20";
|
||||||
|
|
||||||
// Create div container
|
// Create div container
|
||||||
var droppedImageDiv = document.createElement("div");
|
var droppedImageDiv = document.createElement("div");
|
||||||
droppedImageDiv.className = "image-view";
|
droppedImageDiv.className = "image-view";
|
||||||
droppedImageDiv.appendChild(droppedImageCanvas);
|
droppedImageDiv.appendChild(droppedImageCanvas);
|
||||||
|
|
||||||
var imageContainer =
|
var imageContainer =
|
||||||
document.getElementById("image-container");
|
document.getElementById("image-container");
|
||||||
imageContainer.innerHTML = "";
|
imageContainer.innerHTML = "";
|
||||||
imageContainer.appendChild(droppedImageDiv);
|
imageContainer.appendChild(droppedImageDiv);
|
||||||
imageContainer.appendChild(
|
imageContainer.appendChild(
|
||||||
document.createElement("br")
|
document.createElement("br")
|
||||||
);
|
);
|
||||||
imageContainer.appendChild(droppedImageCode);
|
imageContainer.appendChild(droppedImageCode);
|
||||||
|
|
||||||
// Create context for drawing
|
// Create context for drawing
|
||||||
var droppedImageContext =
|
var droppedImageContext =
|
||||||
droppedImageCanvas.getContext("2d");
|
droppedImageCanvas.getContext("2d");
|
||||||
|
|
||||||
// Draw the image
|
// Draw the image
|
||||||
droppedImageContext.drawImage(droppedImage, 0, 0);
|
droppedImageContext.drawImage(droppedImage, 0, 0);
|
||||||
|
|
||||||
// Generate the sprite string
|
// Generate the sprite string
|
||||||
var spriteString =
|
var spriteString =
|
||||||
"static " +
|
"static " +
|
||||||
imageData.name.split(/_|\./)[0] +
|
imageData.name.split(/_|\./)[0] +
|
||||||
": [u8;_] = " +
|
": [u8;_] = " +
|
||||||
"[\n" +
|
"[\n" +
|
||||||
droppedImage.naturalWidth +
|
droppedImage.naturalWidth +
|
||||||
", " +
|
", " +
|
||||||
droppedImage.naturalHeight +
|
droppedImage.naturalHeight +
|
||||||
", // width, height,\n";
|
", // width, height,\n";
|
||||||
|
|
||||||
var pageCount = Math.ceil(
|
var pageCount = Math.ceil(
|
||||||
droppedImage.naturalHeight / 8
|
droppedImage.naturalHeight / 8
|
||||||
);
|
);
|
||||||
var columnCount = droppedImage.naturalWidth;
|
var columnCount = droppedImage.naturalWidth;
|
||||||
var currentByte = 0;
|
var currentByte = 0;
|
||||||
|
|
||||||
// Read the sprite page-by-page
|
// Read the sprite page-by-page
|
||||||
for (var page = 0; page < pageCount; page++) {
|
for (var page = 0; page < pageCount; page++) {
|
||||||
// Read the page column-by-column
|
// Read the page column-by-column
|
||||||
for (
|
for (
|
||||||
var column = 0;
|
var column = 0;
|
||||||
column < columnCount;
|
column < columnCount;
|
||||||
column++
|
column++
|
||||||
) {
|
) {
|
||||||
// Read the column into a byte
|
// Read the column into a byte
|
||||||
var spriteByte = 0;
|
var spriteByte = 0;
|
||||||
for (var yPixel = 0; yPixel < 8; yPixel++) {
|
for (var yPixel = 0; yPixel < 8; yPixel++) {
|
||||||
// If the color of the pixel is not black, count it as white
|
// If the color of the pixel is not black, count it as white
|
||||||
var pixelColor =
|
var pixelColor =
|
||||||
droppedImageContext.getImageData(
|
droppedImageContext.getImageData(
|
||||||
column,
|
column,
|
||||||
page * 8 + yPixel,
|
page * 8 + yPixel,
|
||||||
1,
|
1,
|
||||||
1
|
1
|
||||||
).data;
|
).data;
|
||||||
if (
|
|
||||||
pixelColor[0] > 0 ||
|
|
||||||
pixelColor[1] > 0 ||
|
|
||||||
pixelColor[2] > 0
|
|
||||||
) {
|
|
||||||
spriteByte |= 1 << yPixel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Print the column in hex notation, add a comma for formatting
|
|
||||||
var digitStr = spriteByte.toString(16);
|
|
||||||
if (digitStr.length == 1) {
|
|
||||||
digitStr = "0" + digitStr;
|
|
||||||
}
|
|
||||||
spriteString += "0x" + digitStr + ", ";
|
|
||||||
if (
|
if (
|
||||||
currentByte % droppedImage.naturalWidth ==
|
pixelColor[0] > 0 ||
|
||||||
droppedImage.naturalWidth - 1
|
pixelColor[1] > 0 ||
|
||||||
|
pixelColor[2] > 0
|
||||||
) {
|
) {
|
||||||
spriteString += "\n";
|
spriteByte |= 1 << yPixel;
|
||||||
}
|
}
|
||||||
currentByte++;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// Terminate the array
|
|
||||||
spriteString += "];";
|
|
||||||
// Create an invisible element containing the string
|
|
||||||
droppedImageCode.innerHTML = spriteString;
|
|
||||||
|
|
||||||
// Resize canvas to show 2x scaled image
|
// Print the column in hex notation, add a comma for formatting
|
||||||
droppedImageCanvas.width =
|
var digitStr = spriteByte.toString(16);
|
||||||
droppedImage.naturalWidth * 2;
|
if (digitStr.length == 1) {
|
||||||
droppedImageCanvas.height =
|
digitStr = "0" + digitStr;
|
||||||
droppedImage.naturalHeight * 2;
|
}
|
||||||
droppedImageContext =
|
spriteString += "0x" + digitStr + ", ";
|
||||||
droppedImageCanvas.getContext("2d");
|
if (
|
||||||
droppedImageContext.imageSmoothingEnabled = false;
|
currentByte % droppedImage.naturalWidth ==
|
||||||
droppedImageContext.drawImage(
|
droppedImage.naturalWidth - 1
|
||||||
droppedImage,
|
) {
|
||||||
0,
|
spriteString += "\n";
|
||||||
0,
|
}
|
||||||
droppedImage.naturalWidth * 2,
|
currentByte++;
|
||||||
droppedImage.naturalHeight * 2
|
}
|
||||||
);
|
}
|
||||||
}, 50);
|
// Terminate the array
|
||||||
};
|
spriteString += "];";
|
||||||
reader.readAsDataURL(imageData);
|
// Create an invisible element containing the string
|
||||||
}
|
droppedImageCode.innerHTML = spriteString;
|
||||||
</script>
|
|
||||||
</body>
|
// Resize canvas to show 2x scaled image
|
||||||
</html>
|
droppedImageCanvas.width =
|
||||||
|
droppedImage.naturalWidth * 2;
|
||||||
|
droppedImageCanvas.height =
|
||||||
|
droppedImage.naturalHeight * 2;
|
||||||
|
droppedImageContext =
|
||||||
|
droppedImageCanvas.getContext("2d");
|
||||||
|
droppedImageContext.imageSmoothingEnabled = false;
|
||||||
|
droppedImageContext.drawImage(
|
||||||
|
droppedImage,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
droppedImage.naturalWidth * 2,
|
||||||
|
droppedImage.naturalHeight * 2
|
||||||
|
);
|
||||||
|
}, 50);
|
||||||
|
};
|
||||||
|
reader.readAsDataURL(imageData);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
343
docs/index.html
343
docs/index.html
|
@ -1,175 +1,185 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
|
||||||
<link
|
|
||||||
rel="icon"
|
|
||||||
href="https://upload.wikimedia.org/wikipedia/commons/0/0f/Original_Ferris.svg"
|
|
||||||
type="image/svg+xml"
|
|
||||||
/>
|
|
||||||
<title>ZennDev1337 Sprite Converter</title>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body onload="setup(this);">
|
<head>
|
||||||
<style>
|
|
||||||
html,
|
|
||||||
body {
|
|
||||||
margin: 0;
|
|
||||||
background-color: black;
|
|
||||||
color: azure;
|
|
||||||
}
|
|
||||||
body {
|
|
||||||
font-family: Courier New;
|
|
||||||
text-align: center;
|
|
||||||
font-size: xx-large;
|
|
||||||
font-weight: 700;
|
|
||||||
}
|
|
||||||
.wrapper {
|
|
||||||
min-height: calc(100vh - 50px);
|
|
||||||
}
|
|
||||||
.footer {
|
|
||||||
font-family: Courier New;
|
|
||||||
text-align: center;
|
|
||||||
font-size: large;
|
|
||||||
font-weight: 600;
|
|
||||||
height: 50px;
|
|
||||||
|
|
||||||
color: #e7e7e7;
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
}
|
<link rel="icon" href="https://upload.wikimedia.org/wikipedia/commons/0/0f/Original_Ferris.svg"
|
||||||
.footer > a {
|
type="image/svg+xml" />
|
||||||
font-family: Courier New;
|
<title>ZennDev1337 Sprite Converter</title>
|
||||||
text-align: center;
|
</head>
|
||||||
font-size: large;
|
|
||||||
font-weight: 700;
|
<body onload="setup(this);">
|
||||||
margin: 0;
|
<style>
|
||||||
color: #e7e7e7;
|
html,
|
||||||
text-decoration: none;
|
body {
|
||||||
}
|
margin: 0;
|
||||||
.sticky {
|
background-color: black;
|
||||||
bottom: 0;
|
color: azure;
|
||||||
height: 50px;
|
}
|
||||||
}
|
|
||||||
textarea {
|
body {
|
||||||
background-color: #281c1c;
|
font-family: Courier New;
|
||||||
color: azure;
|
text-align: center;
|
||||||
border: dotted 2px #ce422b;
|
font-size: xx-large;
|
||||||
width: 670px;
|
font-weight: 700;
|
||||||
height: 300px;
|
}
|
||||||
resize: none;
|
|
||||||
}
|
.wrapper {
|
||||||
.title > p {
|
min-height: calc(100vh - 50px);
|
||||||
padding-left: 20px;
|
}
|
||||||
margin: 0;
|
|
||||||
padding-right: 20px;
|
.footer {
|
||||||
color: #e7e7e7;
|
font-family: Courier New;
|
||||||
font-size: xx-large;
|
text-align: center;
|
||||||
}
|
font-size: large;
|
||||||
.title {
|
font-weight: 600;
|
||||||
padding-top: 50px;
|
height: 50px;
|
||||||
}
|
|
||||||
.separator {
|
color: #e7e7e7;
|
||||||
border-top: solid #281c1c;
|
}
|
||||||
border-bottom: none;
|
|
||||||
border-left: none;
|
.footer>a {
|
||||||
border-right: none;
|
font-family: Courier New;
|
||||||
margin-top: 40px;
|
text-align: center;
|
||||||
width: clamp(700px, 70vw, 1200px);
|
font-size: large;
|
||||||
}
|
font-weight: 700;
|
||||||
.image-container {
|
margin: 0;
|
||||||
margin-top: 40px;
|
color: #e7e7e7;
|
||||||
min-height: 80px;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
p {
|
|
||||||
font-size: medium;
|
.sticky {
|
||||||
}
|
bottom: 0;
|
||||||
.txtHead {
|
height: 50px;
|
||||||
margin-bottom: 5px;
|
}
|
||||||
}
|
|
||||||
.topnav {
|
textarea {
|
||||||
background-color: #000000;
|
background-color: #281c1c;
|
||||||
overflow: hidden;
|
color: azure;
|
||||||
height: 47px;
|
border: dotted 2px #ce422b;
|
||||||
}
|
width: 670px;
|
||||||
.topnav a {
|
height: 300px;
|
||||||
color: #f2f2f2;
|
resize: none;
|
||||||
text-align: center;
|
}
|
||||||
padding: 14px 16px;
|
|
||||||
text-decoration: none;
|
.title>p {
|
||||||
font-size: 17px;
|
padding-left: 20px;
|
||||||
}
|
margin: 0;
|
||||||
.topnav a:hover {
|
padding-right: 20px;
|
||||||
background-color: #ddd;
|
color: #e7e7e7;
|
||||||
color: black;
|
font-size: xx-large;
|
||||||
}
|
}
|
||||||
.topnav a.active {
|
|
||||||
background-color: #281c1c;
|
.title {
|
||||||
color: white;
|
padding-top: 50px;
|
||||||
}
|
}
|
||||||
.topnav .icon {
|
|
||||||
|
.separator {
|
||||||
|
border-top: solid #281c1c;
|
||||||
|
border-bottom: none;
|
||||||
|
border-left: none;
|
||||||
|
border-right: none;
|
||||||
|
margin-top: 40px;
|
||||||
|
width: clamp(700px, 70vw, 1200px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.image-container {
|
||||||
|
margin-top: 40px;
|
||||||
|
min-height: 80px;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
font-size: medium;
|
||||||
|
}
|
||||||
|
|
||||||
|
.txtHead {
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topnav {
|
||||||
|
background-color: #000000;
|
||||||
|
overflow: hidden;
|
||||||
|
height: 47px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topnav a {
|
||||||
|
color: #f2f2f2;
|
||||||
|
text-align: center;
|
||||||
|
padding: 14px 16px;
|
||||||
|
text-decoration: none;
|
||||||
|
font-size: 17px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topnav a:hover {
|
||||||
|
background-color: #ddd;
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topnav a.active {
|
||||||
|
background-color: #281c1c;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topnav .icon {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 810px) {
|
||||||
|
.topnav a:not(:first-child) {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
@media screen and (max-width: 800px) {
|
|
||||||
.topnav a:not(:first-child) {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
.topnav a.icon {
|
|
||||||
float: right;
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@media screen and (max-width: 800px) {
|
|
||||||
.topnav.responsive {
|
|
||||||
position: relative;
|
|
||||||
height: 188px;
|
|
||||||
}
|
|
||||||
.topnav.responsive a.icon {
|
|
||||||
position: absolute;
|
|
||||||
right: 0;
|
|
||||||
top: 0;
|
|
||||||
}
|
|
||||||
.topnav.responsive a {
|
|
||||||
float: none;
|
|
||||||
display: block;
|
|
||||||
text-align: left;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
iframe{
|
|
||||||
width: 100vw;
|
|
||||||
border: none;
|
|
||||||
height: calc(100vh - 110px);
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
<div class="wrapper">
|
|
||||||
<div class="topnav" id="myTopnav">
|
|
||||||
<a href="https://zenndev1337.github.io/Rust-for-Arduboy/index.html" class="active">Rust for Arduboy</a>
|
|
||||||
<a href="https://zenndev1337.github.io/Rust-for-Arduboy/image-converter.html">Image Converter</a>
|
|
||||||
<a href="https://zenndev1337.github.io/Rust-for-Arduboy/tile-converter.html">Tile Converter</a>
|
|
||||||
<a href="https://zenndev1337.github.io/Rust-for-Arduboy/sprite-converter.html">Sprite Converter</a>
|
|
||||||
<a
|
|
||||||
href="javascript:void(0);"
|
|
||||||
class="icon"
|
|
||||||
onclick="myFunction()"
|
|
||||||
>
|
|
||||||
<svg
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
width="16"
|
|
||||||
height="16"
|
|
||||||
fill="currentColor"
|
|
||||||
class="bi bi-list"
|
|
||||||
viewBox="0 0 16 16"
|
|
||||||
>
|
|
||||||
<path
|
|
||||||
fill-rule="evenodd"
|
|
||||||
d="M2.5 12a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5z"
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<iframe src="https://ZennDev1337.github.io/Rust-for-Arduboy/doc/arduboy_rust/index.html" title="Rust for Arduboy Docs"></iframe>
|
.topnav a.icon {
|
||||||
|
float: right;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 810px) {
|
||||||
|
.topnav.responsive {
|
||||||
|
position: relative;
|
||||||
|
height: 188px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topnav.responsive a.icon {
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topnav.responsive a {
|
||||||
|
float: none;
|
||||||
|
display: block;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
iframe {
|
||||||
|
width: 100vw;
|
||||||
|
border: none;
|
||||||
|
height: calc(100vh - 110px);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<div class="wrapper">
|
||||||
|
<div class="topnav" id="myTopnav">
|
||||||
|
<a href="https://zenndev1337.github.io/Rust-for-Arduboy/index.html" class="active">Rust for Arduboy</a>
|
||||||
|
<a href="https://zenndev1337.github.io/Rust-for-Arduboy/image-converter.html">Image Converter</a>
|
||||||
|
<a href="https://zenndev1337.github.io/Rust-for-Arduboy/tile-converter.html">Tile Converter</a>
|
||||||
|
<a href="https://zenndev1337.github.io/Rust-for-Arduboy/sprite-converter.html">Sprite Converter</a>
|
||||||
|
<a href="javascript:void(0);" class="icon" onclick="myFunction()">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-list"
|
||||||
|
viewBox="0 0 16 16">
|
||||||
|
<path fill-rule="evenodd"
|
||||||
|
d="M2.5 12a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5z" />
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<iframe src="https://ZennDev1337.github.io/Rust-for-Arduboy/doc/arduboy_rust/index.html"
|
||||||
|
title="Rust for Arduboy Docs"></iframe>
|
||||||
<footer class="footer sticky">
|
<footer class="footer sticky">
|
||||||
<a href="https://github.com/ZennDev1337/" target="_blank"
|
<a href="https://github.com/ZennDev1337/" target="_blank">By ZennDev1337</a>
|
||||||
>By ZennDev1337</a
|
|
||||||
>
|
|
||||||
</footer>
|
</footer>
|
||||||
<script language="JavaScript">
|
<script language="JavaScript">
|
||||||
function myFunction() {
|
function myFunction() {
|
||||||
|
@ -181,5 +191,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
|
||||||
|
</html>
|
File diff suppressed because it is too large
Load diff
|
@ -1,487 +1,483 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
|
||||||
<link
|
|
||||||
rel="icon"
|
|
||||||
href="https://upload.wikimedia.org/wikipedia/commons/0/0f/Original_Ferris.svg"
|
|
||||||
type="image/svg+xml"
|
|
||||||
/>
|
|
||||||
<title>ZennDev1337 Tile Converter</title>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body onload="setup(this);">
|
<head>
|
||||||
<style>
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
html,
|
<link rel="icon" href="https://upload.wikimedia.org/wikipedia/commons/0/0f/Original_Ferris.svg"
|
||||||
body {
|
type="image/svg+xml" />
|
||||||
margin: 0;
|
<title>ZennDev1337 Tile Converter</title>
|
||||||
background-color: black;
|
</head>
|
||||||
color: azure;
|
|
||||||
}
|
|
||||||
body {
|
|
||||||
font-family: Courier New;
|
|
||||||
text-align: center;
|
|
||||||
font-size: xx-large;
|
|
||||||
font-weight: 700;
|
|
||||||
}
|
|
||||||
.wrapper {
|
|
||||||
min-height: calc(100vh - 50px);
|
|
||||||
}
|
|
||||||
.footer {
|
|
||||||
font-family: Courier New;
|
|
||||||
text-align: center;
|
|
||||||
font-size: large;
|
|
||||||
font-weight: 600;
|
|
||||||
height: 50px;
|
|
||||||
|
|
||||||
color: #e7e7e7;
|
<body onload="setup(this);">
|
||||||
}
|
<style>
|
||||||
.footer > a {
|
html,
|
||||||
font-family: Courier New;
|
body {
|
||||||
text-align: center;
|
margin: 0;
|
||||||
font-size: large;
|
background-color: black;
|
||||||
font-weight: 700;
|
color: azure;
|
||||||
margin: 0;
|
}
|
||||||
color: #e7e7e7;
|
|
||||||
text-decoration: none;
|
body {
|
||||||
}
|
font-family: Courier New;
|
||||||
.sticky {
|
text-align: center;
|
||||||
bottom: 0;
|
font-size: xx-large;
|
||||||
height: 50px;
|
font-weight: 700;
|
||||||
}
|
}
|
||||||
textarea {
|
|
||||||
background-color: #281c1c;
|
.wrapper {
|
||||||
color: azure;
|
min-height: calc(100vh - 50px);
|
||||||
border: dotted 2px #ce422b;
|
}
|
||||||
width: 670px;
|
|
||||||
height: 300px;
|
.footer {
|
||||||
resize: none;
|
font-family: Courier New;
|
||||||
}
|
text-align: center;
|
||||||
.title > p {
|
font-size: large;
|
||||||
padding-left: 20px;
|
font-weight: 600;
|
||||||
margin: 0;
|
height: 50px;
|
||||||
padding-right: 20px;
|
|
||||||
color: #e7e7e7;
|
color: #e7e7e7;
|
||||||
font-size: xx-large;
|
}
|
||||||
}
|
|
||||||
.title {
|
.footer>a {
|
||||||
padding-top: 50px;
|
font-family: Courier New;
|
||||||
}
|
text-align: center;
|
||||||
.separator {
|
font-size: large;
|
||||||
border-top: solid #281c1c;
|
font-weight: 700;
|
||||||
border-bottom: none;
|
margin: 0;
|
||||||
border-left: none;
|
color: #e7e7e7;
|
||||||
border-right: none;
|
text-decoration: none;
|
||||||
margin-top: 40px;
|
}
|
||||||
width: clamp(700px, 70vw, 1200px);
|
|
||||||
}
|
.sticky {
|
||||||
.image-container {
|
bottom: 0;
|
||||||
margin-top: 40px;
|
height: 50px;
|
||||||
min-height: 80px;
|
}
|
||||||
}
|
|
||||||
p {
|
textarea {
|
||||||
font-size: medium;
|
background-color: #281c1c;
|
||||||
}
|
color: azure;
|
||||||
.txtHead {
|
border: dotted 2px #ce422b;
|
||||||
margin-bottom: 5px;
|
width: 670px;
|
||||||
}
|
height: 300px;
|
||||||
.topnav {
|
resize: none;
|
||||||
background-color: #000000;
|
}
|
||||||
overflow: hidden;
|
|
||||||
height: 47px;
|
.title>p {
|
||||||
}
|
padding-left: 20px;
|
||||||
.topnav a {
|
margin: 0;
|
||||||
color: #f2f2f2;
|
padding-right: 20px;
|
||||||
text-align: center;
|
color: #e7e7e7;
|
||||||
padding: 14px 16px;
|
font-size: xx-large;
|
||||||
text-decoration: none;
|
}
|
||||||
font-size: 17px;
|
|
||||||
}
|
.title {
|
||||||
.topnav a:hover {
|
padding-top: 50px;
|
||||||
background-color: #ddd;
|
}
|
||||||
color: black;
|
|
||||||
}
|
.separator {
|
||||||
.topnav a.active {
|
border-top: solid #281c1c;
|
||||||
background-color: #281c1c;
|
border-bottom: none;
|
||||||
color: white;
|
border-left: none;
|
||||||
}
|
border-right: none;
|
||||||
.topnav .icon {
|
margin-top: 40px;
|
||||||
|
width: clamp(700px, 70vw, 1200px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.image-container {
|
||||||
|
margin-top: 40px;
|
||||||
|
min-height: 80px;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
font-size: medium;
|
||||||
|
}
|
||||||
|
|
||||||
|
.txtHead {
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topnav {
|
||||||
|
background-color: #000000;
|
||||||
|
overflow: hidden;
|
||||||
|
height: 47px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topnav a {
|
||||||
|
color: #f2f2f2;
|
||||||
|
text-align: center;
|
||||||
|
padding: 14px 16px;
|
||||||
|
text-decoration: none;
|
||||||
|
font-size: 17px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topnav a:hover {
|
||||||
|
background-color: #ddd;
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topnav a.active {
|
||||||
|
background-color: #281c1c;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topnav .icon {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 810px) {
|
||||||
|
.topnav a:not(:first-child) {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
@media screen and (max-width: 800px) {
|
|
||||||
.topnav a:not(:first-child) {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
.topnav a.icon {
|
|
||||||
float: right;
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@media screen and (max-width: 800px) {
|
|
||||||
.topnav.responsive {
|
|
||||||
position: relative;
|
|
||||||
height: 188px;
|
|
||||||
}
|
|
||||||
.topnav.responsive a.icon {
|
|
||||||
position: absolute;
|
|
||||||
right: 0;
|
|
||||||
top: 0;
|
|
||||||
}
|
|
||||||
.topnav.responsive a {
|
|
||||||
float: none;
|
|
||||||
display: block;
|
|
||||||
text-align: left;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
<div class="wrapper">
|
|
||||||
<div class="topnav" id="myTopnav">
|
|
||||||
<a
|
|
||||||
href="https://zenndev1337.github.io/Rust-for-Arduboy/index.html"
|
|
||||||
>Rust for Arduboy</a
|
|
||||||
>
|
|
||||||
<a
|
|
||||||
href="https://zenndev1337.github.io/Rust-for-Arduboy/image-converter.html"
|
|
||||||
>Image Converter</a
|
|
||||||
>
|
|
||||||
<a
|
|
||||||
href="https://zenndev1337.github.io/Rust-for-Arduboy/tile-converter.html"
|
|
||||||
class="active"
|
|
||||||
>Tile Converter</a
|
|
||||||
>
|
|
||||||
<a
|
|
||||||
href="https://zenndev1337.github.io/Rust-for-Arduboy/sprite-converter.html"
|
|
||||||
>Sprite Converter</a
|
|
||||||
>
|
|
||||||
<a
|
|
||||||
href="javascript:void(0);"
|
|
||||||
class="icon"
|
|
||||||
onclick="myFunction()"
|
|
||||||
>
|
|
||||||
<svg
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
width="16"
|
|
||||||
height="16"
|
|
||||||
fill="currentColor"
|
|
||||||
class="bi bi-list"
|
|
||||||
viewBox="0 0 16 16"
|
|
||||||
>
|
|
||||||
<path
|
|
||||||
fill-rule="evenodd"
|
|
||||||
d="M2.5 12a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5z"
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div class="title">
|
|
||||||
<p>Drop your tile sheet here</p>
|
|
||||||
</div>
|
|
||||||
<hr class="separator" />
|
|
||||||
<div class="image-container">
|
|
||||||
<div id="image-container"></div>
|
|
||||||
</div>
|
|
||||||
<hr class="separator" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<footer class="footer">
|
.topnav a.icon {
|
||||||
<a href="https://github.com/ZennDev1337/" target="_blank"
|
float: right;
|
||||||
>By ZennDev1337</a
|
display: block;
|
||||||
>
|
|
||||||
</footer>
|
|
||||||
<script language="JavaScript">
|
|
||||||
function myFunction() {
|
|
||||||
var x = document.getElementById("myTopnav");
|
|
||||||
if (x.className === "topnav") {
|
|
||||||
x.className += " responsive";
|
|
||||||
} else {
|
|
||||||
x.className = "topnav";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
}
|
||||||
<script language="JavaScript">
|
|
||||||
function swapImage(t, e) {
|
@media screen and (max-width: 810px) {
|
||||||
var r = t.getAttribute("data-srcnm");
|
.topnav.responsive {
|
||||||
t.removeAttribute("srcset"),
|
position: relative;
|
||||||
r || t.setAttribute("data-srcnm", t.src),
|
height: 188px;
|
||||||
(t.src = e);
|
|
||||||
}
|
}
|
||||||
function setOriginal(t) {
|
|
||||||
var e = "",
|
.topnav.responsive a.icon {
|
||||||
r = "";
|
position: absolute;
|
||||||
(r = t.getAttribute("data-srcmd")),
|
right: 0;
|
||||||
(e = t.getAttribute("data-srcnm")),
|
top: 0;
|
||||||
r
|
|
||||||
? ((t.src = r), t.removeAttribute("data-srcmd"))
|
|
||||||
: ((t.src = e), t.removeAttribute("data-srcnm"));
|
|
||||||
}
|
}
|
||||||
function swapImageMD(t, e) {
|
|
||||||
t.setAttribute("data-srcmd", t.src), (t.src = e);
|
.topnav.responsive a {
|
||||||
|
float: none;
|
||||||
|
display: block;
|
||||||
|
text-align: left;
|
||||||
}
|
}
|
||||||
function jsready(t) {
|
}
|
||||||
/in/.test(document.readyState)
|
</style>
|
||||||
? setTimeout("jsready(" + t + ")", 9)
|
<div class="wrapper">
|
||||||
: t();
|
<div class="topnav" id="myTopnav">
|
||||||
|
<a href="https://zenndev1337.github.io/Rust-for-Arduboy/index.html">Rust for Arduboy</a>
|
||||||
|
<a href="https://zenndev1337.github.io/Rust-for-Arduboy/image-converter.html">Image Converter</a>
|
||||||
|
<a href="https://zenndev1337.github.io/Rust-for-Arduboy/tile-converter.html" class="active">Tile
|
||||||
|
Converter</a>
|
||||||
|
<a href="https://zenndev1337.github.io/Rust-for-Arduboy/sprite-converter.html">Sprite Converter</a>
|
||||||
|
<a href="javascript:void(0);" class="icon" onclick="myFunction()">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-list"
|
||||||
|
viewBox="0 0 16 16">
|
||||||
|
<path fill-rule="evenodd"
|
||||||
|
d="M2.5 12a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5z" />
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div class="title">
|
||||||
|
<p>Drop your tile sheet here</p>
|
||||||
|
</div>
|
||||||
|
<hr class="separator" />
|
||||||
|
<div class="image-container">
|
||||||
|
<div id="image-container"></div>
|
||||||
|
</div>
|
||||||
|
<hr class="separator" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<footer class="footer">
|
||||||
|
<a href="https://github.com/ZennDev1337/" target="_blank">By ZennDev1337</a>
|
||||||
|
</footer>
|
||||||
|
<script language="JavaScript">
|
||||||
|
function myFunction() {
|
||||||
|
var x = document.getElementById("myTopnav");
|
||||||
|
if (x.className === "topnav") {
|
||||||
|
x.className += " responsive";
|
||||||
|
} else {
|
||||||
|
x.className = "topnav";
|
||||||
}
|
}
|
||||||
jsready(function () {
|
}
|
||||||
var t = window.devicePixelRatio ? window.devicePixelRatio : 1;
|
</script>
|
||||||
if (t > 1)
|
<script language="JavaScript">
|
||||||
for (
|
function swapImage(t, e) {
|
||||||
var e = document.getElementsByTagName("img"), r = 0;
|
var r = t.getAttribute("data-srcnm");
|
||||||
r < e.length;
|
t.removeAttribute("srcset"),
|
||||||
r++
|
r || t.setAttribute("data-srcnm", t.src),
|
||||||
)
|
(t.src = e);
|
||||||
e[r].getAttribute("data-src2x") &&
|
}
|
||||||
(e[r].setAttribute(
|
function setOriginal(t) {
|
||||||
"data-src-orig",
|
var e = "",
|
||||||
e[r].getAttribute("src")
|
r = "";
|
||||||
),
|
(r = t.getAttribute("data-srcmd")),
|
||||||
|
(e = t.getAttribute("data-srcnm")),
|
||||||
|
r
|
||||||
|
? ((t.src = r), t.removeAttribute("data-srcmd"))
|
||||||
|
: ((t.src = e), t.removeAttribute("data-srcnm"));
|
||||||
|
}
|
||||||
|
function swapImageMD(t, e) {
|
||||||
|
t.setAttribute("data-srcmd", t.src), (t.src = e);
|
||||||
|
}
|
||||||
|
function jsready(t) {
|
||||||
|
/in/.test(document.readyState)
|
||||||
|
? setTimeout("jsready(" + t + ")", 9)
|
||||||
|
: t();
|
||||||
|
}
|
||||||
|
jsready(function () {
|
||||||
|
var t = window.devicePixelRatio ? window.devicePixelRatio : 1;
|
||||||
|
if (t > 1)
|
||||||
|
for (
|
||||||
|
var e = document.getElementsByTagName("img"), r = 0;
|
||||||
|
r < e.length;
|
||||||
|
r++
|
||||||
|
)
|
||||||
|
e[r].getAttribute("data-src2x") &&
|
||||||
|
(e[r].setAttribute(
|
||||||
|
"data-src-orig",
|
||||||
|
e[r].getAttribute("src")
|
||||||
|
),
|
||||||
e[r].setAttribute(
|
e[r].setAttribute(
|
||||||
"src",
|
"src",
|
||||||
e[r].getAttribute("data-src2x")
|
e[r].getAttribute("data-src2x")
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
|
|
||||||
function setup(body) {
|
function setup(body) {
|
||||||
body.ondragover = function () {
|
body.ondragover = function () {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
body.ondragend = function () {
|
body.ondragend = function () {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
body.ondrop = function (e) {
|
body.ondrop = function (e) {
|
||||||
// Prevent the browser from showing the dropped file
|
// Prevent the browser from showing the dropped file
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
// Get the image data
|
// Get the image data
|
||||||
var imageData = getImageData(e);
|
var imageData = getImageData(e);
|
||||||
// If there is some data, add it to the page
|
// If there is some data, add it to the page
|
||||||
if (imageData !== null) {
|
if (imageData !== null) {
|
||||||
addDroppedElement(imageData);
|
addDroppedElement(imageData);
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
function getImageData(event) {
|
|
||||||
var file = event.dataTransfer.files[0];
|
|
||||||
if (file.type.indexOf("image") === 0) {
|
|
||||||
return file;
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function getImageData(event) {
|
||||||
|
var file = event.dataTransfer.files[0];
|
||||||
|
if (file.type.indexOf("image") === 0) {
|
||||||
|
return file;
|
||||||
}
|
}
|
||||||
function addDroppedElement(imageData) {
|
}
|
||||||
var reader = new FileReader();
|
function addDroppedElement(imageData) {
|
||||||
reader.onload = function (event) {
|
var reader = new FileReader();
|
||||||
event.preventDefault;
|
reader.onload = function (event) {
|
||||||
// Create image element
|
event.preventDefault;
|
||||||
var droppedImage = new Image();
|
// Create image element
|
||||||
droppedImage.src = event.target.result;
|
var droppedImage = new Image();
|
||||||
// add delay so the image can be loaded properly before accessing it
|
droppedImage.src = event.target.result;
|
||||||
setTimeout(function () {
|
// add delay so the image can be loaded properly before accessing it
|
||||||
var imgNW = droppedImage.naturalWidth;
|
setTimeout(function () {
|
||||||
var imgNH = droppedImage.naturalHeight;
|
var imgNW = droppedImage.naturalWidth;
|
||||||
var zoom = 1;
|
var imgNH = droppedImage.naturalHeight;
|
||||||
switch (imgNW) {
|
var zoom = 1;
|
||||||
case 8:
|
switch (imgNW) {
|
||||||
zoom = 4;
|
case 8:
|
||||||
break;
|
zoom = 4;
|
||||||
case 16:
|
break;
|
||||||
zoom = 2;
|
case 16:
|
||||||
break;
|
zoom = 2;
|
||||||
case 24:
|
break;
|
||||||
zoom = 4 / 3;
|
case 24:
|
||||||
break;
|
zoom = 4 / 3;
|
||||||
case 24:
|
break;
|
||||||
zoom = 1;
|
case 24:
|
||||||
break;
|
zoom = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
var tileW = imgNW * zoom;
|
||||||
|
var tileH = tileW;
|
||||||
|
// Create canvas for tiles
|
||||||
|
var droppedImageCanvas =
|
||||||
|
document.createElement("canvas");
|
||||||
|
var canvasWidth =
|
||||||
|
Math.floor(700 / (tileW + 2)) * (tileW + 2) - 2;
|
||||||
|
var canvasHeight =
|
||||||
|
Math.ceil(
|
||||||
|
imgNH / imgNW / Math.floor(700 / (tileW + 2))
|
||||||
|
) *
|
||||||
|
(tileH + 2) -
|
||||||
|
2;
|
||||||
|
droppedImageCanvas.width = canvasWidth;
|
||||||
|
droppedImageCanvas.height = canvasHeight;
|
||||||
|
// Create invisible canvas for original image
|
||||||
|
var invisImageCanvas = document.createElement("canvas");
|
||||||
|
invisImageCanvas.width = imgNW;
|
||||||
|
invisImageCanvas.height = imgNH;
|
||||||
|
invisImageCanvas.style.display = "none";
|
||||||
|
// Create code container
|
||||||
|
var droppedImageCode =
|
||||||
|
document.createElement("textarea");
|
||||||
|
droppedImageCode.className = "code";
|
||||||
|
droppedImageCode.style.width = "698px";
|
||||||
|
droppedImageCode.rows = "20";
|
||||||
|
// Create div container
|
||||||
|
var droppedImageDiv = document.createElement("div");
|
||||||
|
droppedImageDiv.className = "image-view";
|
||||||
|
droppedImageDiv.appendChild(droppedImageCanvas);
|
||||||
|
droppedImageDiv.appendChild(invisImageCanvas);
|
||||||
|
var imageContainer =
|
||||||
|
document.getElementById("image-container");
|
||||||
|
imageContainer.innerHTML = "";
|
||||||
|
imageContainer.appendChild(droppedImageDiv);
|
||||||
|
imageContainer.appendChild(
|
||||||
|
document.createElement("br")
|
||||||
|
);
|
||||||
|
imageContainer.appendChild(droppedImageCode);
|
||||||
|
// Create context for drawing
|
||||||
|
var droppedImageContext =
|
||||||
|
droppedImageCanvas.getContext("2d");
|
||||||
|
droppedImageContext.imageSmoothingEnabled = false;
|
||||||
|
var invisImageContext =
|
||||||
|
invisImageCanvas.getContext("2d");
|
||||||
|
// Draw the image on an invisible canvas to generate the code
|
||||||
|
invisImageContext.drawImage(droppedImage, 0, 0);
|
||||||
|
// Clip the image and draw individual tiles on the canvas with 2px spacing inbetween
|
||||||
|
for (
|
||||||
|
var i = 0, x = 0, y = 0, tile;
|
||||||
|
i < imgNH / imgNW;
|
||||||
|
i++
|
||||||
|
) {
|
||||||
|
if (x + tileW + 2 <= canvasWidth) {
|
||||||
|
x += tileW + 2;
|
||||||
|
} else {
|
||||||
|
x = 0;
|
||||||
|
y += tileH + 2;
|
||||||
}
|
}
|
||||||
var tileW = imgNW * zoom;
|
if (i === 0) {
|
||||||
var tileH = tileW;
|
x = 0;
|
||||||
// Create canvas for tiles
|
}
|
||||||
var droppedImageCanvas =
|
droppedImageContext.drawImage(
|
||||||
document.createElement("canvas");
|
droppedImage,
|
||||||
var canvasWidth =
|
0,
|
||||||
Math.floor(700 / (tileW + 2)) * (tileW + 2) - 2;
|
i * imgNW,
|
||||||
var canvasHeight =
|
imgNW,
|
||||||
Math.ceil(
|
imgNW,
|
||||||
imgNH / imgNW / Math.floor(700 / (tileW + 2))
|
x,
|
||||||
) *
|
y,
|
||||||
(tileH + 2) -
|
tileW,
|
||||||
2;
|
tileH
|
||||||
droppedImageCanvas.width = canvasWidth;
|
|
||||||
droppedImageCanvas.height = canvasHeight;
|
|
||||||
// Create invisible canvas for original image
|
|
||||||
var invisImageCanvas = document.createElement("canvas");
|
|
||||||
invisImageCanvas.width = imgNW;
|
|
||||||
invisImageCanvas.height = imgNH;
|
|
||||||
invisImageCanvas.style.display = "none";
|
|
||||||
// Create code container
|
|
||||||
var droppedImageCode =
|
|
||||||
document.createElement("textarea");
|
|
||||||
droppedImageCode.className = "code";
|
|
||||||
droppedImageCode.style.width = "698px";
|
|
||||||
droppedImageCode.rows = "20";
|
|
||||||
// Create div container
|
|
||||||
var droppedImageDiv = document.createElement("div");
|
|
||||||
droppedImageDiv.className = "image-view";
|
|
||||||
droppedImageDiv.appendChild(droppedImageCanvas);
|
|
||||||
droppedImageDiv.appendChild(invisImageCanvas);
|
|
||||||
var imageContainer =
|
|
||||||
document.getElementById("image-container");
|
|
||||||
imageContainer.innerHTML = "";
|
|
||||||
imageContainer.appendChild(droppedImageDiv);
|
|
||||||
imageContainer.appendChild(
|
|
||||||
document.createElement("br")
|
|
||||||
);
|
);
|
||||||
imageContainer.appendChild(droppedImageCode);
|
}
|
||||||
// Create context for drawing
|
// Draw raster between tiles on the canvas
|
||||||
var droppedImageContext =
|
droppedImageContext.beginPath();
|
||||||
droppedImageCanvas.getContext("2d");
|
for (
|
||||||
droppedImageContext.imageSmoothingEnabled = false;
|
var j = 1;
|
||||||
var invisImageContext =
|
j <= Math.floor(700 / (tileW + 2));
|
||||||
invisImageCanvas.getContext("2d");
|
j++
|
||||||
// Draw the image on an invisible canvas to generate the code
|
) {
|
||||||
invisImageContext.drawImage(droppedImage, 0, 0);
|
droppedImageContext.moveTo(
|
||||||
// Clip the image and draw individual tiles on the canvas with 2px spacing inbetween
|
j * tileW + 1 + (j - 1) * 2,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
droppedImageContext.lineTo(
|
||||||
|
j * tileW + 1 + (j - 1) * 2,
|
||||||
|
canvasHeight
|
||||||
|
);
|
||||||
|
}
|
||||||
|
for (
|
||||||
|
var k = 1;
|
||||||
|
k <=
|
||||||
|
Math.ceil(
|
||||||
|
imgNH / imgNW / Math.floor(700 / tileW + 2)
|
||||||
|
);
|
||||||
|
k++
|
||||||
|
) {
|
||||||
|
droppedImageContext.moveTo(
|
||||||
|
0,
|
||||||
|
k * tileW + 1 + (k - 1) * 2
|
||||||
|
);
|
||||||
|
droppedImageContext.lineTo(
|
||||||
|
canvasWidth,
|
||||||
|
k * tileW + 1 + (k - 1) * 2
|
||||||
|
);
|
||||||
|
}
|
||||||
|
droppedImageContext.strokeStyle = "#281c1c";
|
||||||
|
droppedImageContext.lineWidth = 2;
|
||||||
|
droppedImageContext.stroke();
|
||||||
|
let sep =
|
||||||
|
window.document.getElementsByClassName("separator");
|
||||||
|
for (let item of sep) {
|
||||||
|
item.style.borderColor = "#ce422b";
|
||||||
|
}
|
||||||
|
// Generate the sprite string
|
||||||
|
var spriteString =
|
||||||
|
"static " +
|
||||||
|
imageData.name.split("_")[0] +
|
||||||
|
": [u8;_] = " +
|
||||||
|
"[\n" +
|
||||||
|
imgNW +
|
||||||
|
", " +
|
||||||
|
imgNW +
|
||||||
|
", // width, height,\n" +
|
||||||
|
"// TILE 00\n";
|
||||||
|
var pageCount = Math.ceil(imgNH / 8);
|
||||||
|
var columnCount = imgNW;
|
||||||
|
var currentByte = 0;
|
||||||
|
var rowCounter = 0;
|
||||||
|
var tileCounter = 0;
|
||||||
|
// Read the sprite page-by-page
|
||||||
|
for (var page = 0; page < pageCount; page++) {
|
||||||
|
// Read the page column-by-column
|
||||||
for (
|
for (
|
||||||
var i = 0, x = 0, y = 0, tile;
|
var column = 0;
|
||||||
i < imgNH / imgNW;
|
column < columnCount;
|
||||||
i++
|
column++
|
||||||
) {
|
) {
|
||||||
if (x + tileW + 2 <= canvasWidth) {
|
// Read the column into a byte
|
||||||
x += tileW + 2;
|
var spriteByte = 0;
|
||||||
} else {
|
for (var yPixel = 0; yPixel < 8; yPixel++) {
|
||||||
x = 0;
|
// If the color of the pixel is not black, count it as white
|
||||||
y += tileH + 2;
|
var pixelColor =
|
||||||
}
|
invisImageContext.getImageData(
|
||||||
if (i === 0) {
|
column,
|
||||||
x = 0;
|
page * 8 + yPixel,
|
||||||
}
|
1,
|
||||||
droppedImageContext.drawImage(
|
1
|
||||||
droppedImage,
|
).data;
|
||||||
0,
|
if (
|
||||||
i * imgNW,
|
pixelColor[0] > 0 ||
|
||||||
imgNW,
|
pixelColor[1] > 0 ||
|
||||||
imgNW,
|
pixelColor[2] > 0
|
||||||
x,
|
) {
|
||||||
y,
|
spriteByte |= 1 << yPixel;
|
||||||
tileW,
|
|
||||||
tileH
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// Draw raster between tiles on the canvas
|
|
||||||
droppedImageContext.beginPath();
|
|
||||||
for (
|
|
||||||
var j = 1;
|
|
||||||
j <= Math.floor(700 / (tileW + 2));
|
|
||||||
j++
|
|
||||||
) {
|
|
||||||
droppedImageContext.moveTo(
|
|
||||||
j * tileW + 1 + (j - 1) * 2,
|
|
||||||
0
|
|
||||||
);
|
|
||||||
droppedImageContext.lineTo(
|
|
||||||
j * tileW + 1 + (j - 1) * 2,
|
|
||||||
canvasHeight
|
|
||||||
);
|
|
||||||
}
|
|
||||||
for (
|
|
||||||
var k = 1;
|
|
||||||
k <=
|
|
||||||
Math.ceil(
|
|
||||||
imgNH / imgNW / Math.floor(700 / tileW + 2)
|
|
||||||
);
|
|
||||||
k++
|
|
||||||
) {
|
|
||||||
droppedImageContext.moveTo(
|
|
||||||
0,
|
|
||||||
k * tileW + 1 + (k - 1) * 2
|
|
||||||
);
|
|
||||||
droppedImageContext.lineTo(
|
|
||||||
canvasWidth,
|
|
||||||
k * tileW + 1 + (k - 1) * 2
|
|
||||||
);
|
|
||||||
}
|
|
||||||
droppedImageContext.strokeStyle = "#281c1c";
|
|
||||||
droppedImageContext.lineWidth = 2;
|
|
||||||
droppedImageContext.stroke();
|
|
||||||
let sep =
|
|
||||||
window.document.getElementsByClassName("separator");
|
|
||||||
for (let item of sep) {
|
|
||||||
item.style.borderColor = "#ce422b";
|
|
||||||
}
|
|
||||||
// Generate the sprite string
|
|
||||||
var spriteString =
|
|
||||||
"static " +
|
|
||||||
imageData.name.split("_")[0] +
|
|
||||||
": [u8;_] = " +
|
|
||||||
"[\n" +
|
|
||||||
imgNW +
|
|
||||||
", " +
|
|
||||||
imgNW +
|
|
||||||
", // width, height,\n" +
|
|
||||||
"// TILE 00\n";
|
|
||||||
var pageCount = Math.ceil(imgNH / 8);
|
|
||||||
var columnCount = imgNW;
|
|
||||||
var currentByte = 0;
|
|
||||||
var rowCounter = 0;
|
|
||||||
var tileCounter = 0;
|
|
||||||
// Read the sprite page-by-page
|
|
||||||
for (var page = 0; page < pageCount; page++) {
|
|
||||||
// Read the page column-by-column
|
|
||||||
for (
|
|
||||||
var column = 0;
|
|
||||||
column < columnCount;
|
|
||||||
column++
|
|
||||||
) {
|
|
||||||
// Read the column into a byte
|
|
||||||
var spriteByte = 0;
|
|
||||||
for (var yPixel = 0; yPixel < 8; yPixel++) {
|
|
||||||
// If the color of the pixel is not black, count it as white
|
|
||||||
var pixelColor =
|
|
||||||
invisImageContext.getImageData(
|
|
||||||
column,
|
|
||||||
page * 8 + yPixel,
|
|
||||||
1,
|
|
||||||
1
|
|
||||||
).data;
|
|
||||||
if (
|
|
||||||
pixelColor[0] > 0 ||
|
|
||||||
pixelColor[1] > 0 ||
|
|
||||||
pixelColor[2] > 0
|
|
||||||
) {
|
|
||||||
spriteByte |= 1 << yPixel;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Print the column in hex notation, add a comma for formatting
|
|
||||||
var digitStr = spriteByte.toString(16);
|
|
||||||
if (digitStr.length == 1) {
|
|
||||||
digitStr = "0" + digitStr;
|
|
||||||
}
|
|
||||||
spriteString += "0x" + digitStr + ", ";
|
|
||||||
if (currentByte % imgNW == imgNW - 1) {
|
|
||||||
spriteString += "\n";
|
|
||||||
rowCounter++;
|
|
||||||
if (
|
|
||||||
rowCounter == imgNW / 8 &&
|
|
||||||
tileCounter < imgNH / imgNW - 1
|
|
||||||
) {
|
|
||||||
tileCounter++;
|
|
||||||
var tileNumber =
|
|
||||||
tileCounter.toString().length === 1
|
|
||||||
? "0" + tileCounter.toString()
|
|
||||||
: tileCounter.toString();
|
|
||||||
spriteString +=
|
|
||||||
"// TILE " + tileNumber + "\n";
|
|
||||||
rowCounter = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
currentByte++;
|
|
||||||
}
|
}
|
||||||
|
// Print the column in hex notation, add a comma for formatting
|
||||||
|
var digitStr = spriteByte.toString(16);
|
||||||
|
if (digitStr.length == 1) {
|
||||||
|
digitStr = "0" + digitStr;
|
||||||
|
}
|
||||||
|
spriteString += "0x" + digitStr + ", ";
|
||||||
|
if (currentByte % imgNW == imgNW - 1) {
|
||||||
|
spriteString += "\n";
|
||||||
|
rowCounter++;
|
||||||
|
if (
|
||||||
|
rowCounter == imgNW / 8 &&
|
||||||
|
tileCounter < imgNH / imgNW - 1
|
||||||
|
) {
|
||||||
|
tileCounter++;
|
||||||
|
var tileNumber =
|
||||||
|
tileCounter.toString().length === 1
|
||||||
|
? "0" + tileCounter.toString()
|
||||||
|
: tileCounter.toString();
|
||||||
|
spriteString +=
|
||||||
|
"// TILE " + tileNumber + "\n";
|
||||||
|
rowCounter = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
currentByte++;
|
||||||
}
|
}
|
||||||
// Terminate the array
|
}
|
||||||
spriteString += "];";
|
// Terminate the array
|
||||||
// Create an invisible element containing the string
|
spriteString += "];";
|
||||||
droppedImageCode.innerHTML = spriteString;
|
// Create an invisible element containing the string
|
||||||
}, 50);
|
droppedImageCode.innerHTML = spriteString;
|
||||||
};
|
}, 50);
|
||||||
reader.readAsDataURL(imageData);
|
};
|
||||||
}
|
reader.readAsDataURL(imageData);
|
||||||
</script>
|
}
|
||||||
</body>
|
</script>
|
||||||
</html>
|
</body>
|
||||||
|
|
||||||
|
</html>
|
Loading…
Add table
Add a link
Reference in a new issue