Spaces:
Running
Running
I need to create a browser mockup that converts images to Minecraft Pixel Art and also gives me the Minecraft supported images to export in-game. These tools are built on artificial intelligence using TensotFlowJs - Initial Deployment
Browse files- README.md +7 -5
- index.html +500 -19
README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: pixel-arts
|
| 3 |
+
emoji: 🐳
|
| 4 |
+
colorFrom: yellow
|
| 5 |
+
colorTo: blue
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite
|
| 10 |
---
|
| 11 |
|
| 12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
index.html
CHANGED
|
@@ -1,19 +1,500 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Minecraft Pixel Art Converter</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@3.18.0/dist/tf.min.js"></script>
|
| 9 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
| 10 |
+
<style>
|
| 11 |
+
.browser-window {
|
| 12 |
+
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
|
| 13 |
+
border-radius: 12px;
|
| 14 |
+
overflow: hidden;
|
| 15 |
+
}
|
| 16 |
+
.browser-header {
|
| 17 |
+
background: linear-gradient(to right, #f1f1f1, #e0e0e0);
|
| 18 |
+
padding: 8px 12px;
|
| 19 |
+
display: flex;
|
| 20 |
+
align-items: center;
|
| 21 |
+
gap: 8px;
|
| 22 |
+
}
|
| 23 |
+
.browser-button {
|
| 24 |
+
width: 12px;
|
| 25 |
+
height: 12px;
|
| 26 |
+
border-radius: 50%;
|
| 27 |
+
}
|
| 28 |
+
.browser-url {
|
| 29 |
+
flex-grow: 1;
|
| 30 |
+
background: white;
|
| 31 |
+
padding: 6px 12px;
|
| 32 |
+
border-radius: 16px;
|
| 33 |
+
font-size: 12px;
|
| 34 |
+
color: #555;
|
| 35 |
+
overflow: hidden;
|
| 36 |
+
text-overflow: ellipsis;
|
| 37 |
+
white-space: nowrap;
|
| 38 |
+
}
|
| 39 |
+
.pixel-grid {
|
| 40 |
+
display: grid;
|
| 41 |
+
grid-template-columns: repeat(auto-fill, minmax(16px, 1fr));
|
| 42 |
+
gap: 0;
|
| 43 |
+
border: 2px solid #333;
|
| 44 |
+
}
|
| 45 |
+
.pixel {
|
| 46 |
+
aspect-ratio: 1/1;
|
| 47 |
+
width: 100%;
|
| 48 |
+
}
|
| 49 |
+
.dropzone {
|
| 50 |
+
border: 2px dashed #ccc;
|
| 51 |
+
transition: all 0.3s;
|
| 52 |
+
}
|
| 53 |
+
.dropzone.active {
|
| 54 |
+
border-color: #4CAF50;
|
| 55 |
+
background-color: rgba(76, 175, 80, 0.1);
|
| 56 |
+
}
|
| 57 |
+
.minecraft-block {
|
| 58 |
+
width: 32px;
|
| 59 |
+
height: 32px;
|
| 60 |
+
image-rendering: pixelated;
|
| 61 |
+
}
|
| 62 |
+
canvas {
|
| 63 |
+
image-rendering: pixelated;
|
| 64 |
+
}
|
| 65 |
+
.loading-bar {
|
| 66 |
+
height: 4px;
|
| 67 |
+
background: linear-gradient(to right, #4CAF50, #8BC34A);
|
| 68 |
+
width: 0%;
|
| 69 |
+
transition: width 0.3s;
|
| 70 |
+
}
|
| 71 |
+
</style>
|
| 72 |
+
</head>
|
| 73 |
+
<body class="bg-gray-100 min-h-screen flex items-center justify-center p-4">
|
| 74 |
+
<div class="w-full max-w-4xl">
|
| 75 |
+
<div class="browser-window bg-white">
|
| 76 |
+
<div class="browser-header">
|
| 77 |
+
<div class="browser-button bg-red-500"></div>
|
| 78 |
+
<div class="browser-button bg-yellow-500"></div>
|
| 79 |
+
<div class="browser-button bg-green-500"></div>
|
| 80 |
+
<div class="browser-url">https://minecraft-pixel-art-converter.com</div>
|
| 81 |
+
<div class="text-gray-500 text-sm">
|
| 82 |
+
<i class="fas fa-lock"></i>
|
| 83 |
+
</div>
|
| 84 |
+
</div>
|
| 85 |
+
<div class="loading-bar" id="loadingBar"></div>
|
| 86 |
+
<div class="p-6">
|
| 87 |
+
<h1 class="text-3xl font-bold text-gray-800 mb-2 flex items-center">
|
| 88 |
+
<i class="fas fa-cube mr-2 text-green-600"></i>
|
| 89 |
+
Minecraft Pixel Art Converter
|
| 90 |
+
</h1>
|
| 91 |
+
<p class="text-gray-600 mb-6">Upload an image to convert it to Minecraft blocks with AI-powered color matching</p>
|
| 92 |
+
|
| 93 |
+
<div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
|
| 94 |
+
<!-- Original Image -->
|
| 95 |
+
<div class="bg-gray-50 p-4 rounded-lg">
|
| 96 |
+
<h2 class="text-lg font-semibold mb-3 text-gray-700 flex items-center">
|
| 97 |
+
<i class="fas fa-image mr-2 text-blue-500"></i>
|
| 98 |
+
Original Image
|
| 99 |
+
</h2>
|
| 100 |
+
<div id="dropzone" class="dropzone rounded-lg flex flex-col items-center justify-center p-8 cursor-pointer">
|
| 101 |
+
<i class="fas fa-cloud-upload-alt text-4xl text-gray-400 mb-2"></i>
|
| 102 |
+
<p class="text-gray-500 text-center">Drag & drop your image here or click to browse</p>
|
| 103 |
+
<input type="file" id="imageInput" accept="image/*" class="hidden">
|
| 104 |
+
</div>
|
| 105 |
+
<div id="originalPreview" class="mt-4 hidden">
|
| 106 |
+
<img id="originalImage" class="max-w-full h-auto rounded border border-gray-200" alt="Original preview">
|
| 107 |
+
</div>
|
| 108 |
+
</div>
|
| 109 |
+
|
| 110 |
+
<!-- Minecraft Preview -->
|
| 111 |
+
<div class="bg-gray-50 p-4 rounded-lg">
|
| 112 |
+
<h2 class="text-lg font-semibold mb-3 text-gray-700 flex items-center">
|
| 113 |
+
<i class="fas fa-cubes mr-2 text-green-500"></i>
|
| 114 |
+
Minecraft Version
|
| 115 |
+
</h2>
|
| 116 |
+
<div id="minecraftPreview" class="flex items-center justify-center bg-gray-100 rounded-lg p-8 min-h-48">
|
| 117 |
+
<p class="text-gray-500 text-center">Converted pixel art will appear here</p>
|
| 118 |
+
</div>
|
| 119 |
+
<div id="pixelArtContainer" class="mt-4 hidden overflow-auto max-h-64 border border-gray-200 rounded">
|
| 120 |
+
<canvas id="pixelArtCanvas"></canvas>
|
| 121 |
+
</div>
|
| 122 |
+
</div>
|
| 123 |
+
</div>
|
| 124 |
+
|
| 125 |
+
<!-- Controls -->
|
| 126 |
+
<div class="bg-gray-50 p-4 rounded-lg mb-6">
|
| 127 |
+
<h2 class="text-lg font-semibold mb-3 text-gray-700 flex items-center">
|
| 128 |
+
<i class="fas fa-sliders-h mr-2 text-purple-500"></i>
|
| 129 |
+
Conversion Settings
|
| 130 |
+
</h2>
|
| 131 |
+
|
| 132 |
+
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
|
| 133 |
+
<div>
|
| 134 |
+
<label class="block text-sm font-medium text-gray-700 mb-1">Resolution</label>
|
| 135 |
+
<select id="resolutionSelect" class="w-full p-2 border border-gray-300 rounded focus:ring-2 focus:ring-green-500 focus:border-green-500">
|
| 136 |
+
<option value="32">32x32 (Small)</option>
|
| 137 |
+
<option value="64" selected>64x64 (Medium)</option>
|
| 138 |
+
<option value="128">128x128 (Large)</option>
|
| 139 |
+
<option value="256">256x256 (Huge)</option>
|
| 140 |
+
</select>
|
| 141 |
+
</div>
|
| 142 |
+
|
| 143 |
+
<div>
|
| 144 |
+
<label class="block text-sm font-medium text-gray-700 mb-1">Color Palette</label>
|
| 145 |
+
<select id="paletteSelect" class="w-full p-2 border border-gray-300 rounded focus:ring-2 focus:ring-green-500 focus:border-green-500">
|
| 146 |
+
<option value="default" selected>Default Blocks</option>
|
| 147 |
+
<option value="wool">Wool Only</option>
|
| 148 |
+
<option value="concrete">Concrete Only</option>
|
| 149 |
+
<option value="terracotta">Terracotta Only</option>
|
| 150 |
+
<option value="all">All Available Blocks</option>
|
| 151 |
+
</select>
|
| 152 |
+
</div>
|
| 153 |
+
|
| 154 |
+
<div>
|
| 155 |
+
<label class="block text-sm font-medium text-gray-700 mb-1">Dithering</label>
|
| 156 |
+
<select id="ditherSelect" class="w-full p-2 border border-gray-300 rounded focus:ring-2 focus:ring-green-500 focus:border-green-500">
|
| 157 |
+
<option value="none">None</option>
|
| 158 |
+
<option value="floyd" selected>Floyd-Steinberg</option>
|
| 159 |
+
<option value="ordered">Ordered</option>
|
| 160 |
+
</select>
|
| 161 |
+
</div>
|
| 162 |
+
</div>
|
| 163 |
+
|
| 164 |
+
<div class="mt-4 flex flex-wrap gap-3">
|
| 165 |
+
<button id="convertBtn" class="bg-green-600 hover:bg-green-700 text-white px-4 py-2 rounded flex items-center disabled:opacity-50">
|
| 166 |
+
<i class="fas fa-magic mr-2"></i>
|
| 167 |
+
Convert to Pixel Art
|
| 168 |
+
</button>
|
| 169 |
+
<button id="randomBtn" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded flex items-center">
|
| 170 |
+
<i class="fas fa-random mr-2"></i>
|
| 171 |
+
Random Example
|
| 172 |
+
</button>
|
| 173 |
+
<button id="clearBtn" class="bg-gray-600 hover:bg-gray-700 text-white px-4 py-2 rounded flex items-center">
|
| 174 |
+
<i class="fas fa-trash-alt mr-2"></i>
|
| 175 |
+
Clear
|
| 176 |
+
</button>
|
| 177 |
+
</div>
|
| 178 |
+
</div>
|
| 179 |
+
|
| 180 |
+
<!-- Export Options -->
|
| 181 |
+
<div class="bg-gray-50 p-4 rounded-lg">
|
| 182 |
+
<h2 class="text-lg font-semibold mb-3 text-gray-700 flex items-center">
|
| 183 |
+
<i class="fas fa-download mr-2 text-orange-500"></i>
|
| 184 |
+
Export Options
|
| 185 |
+
</h2>
|
| 186 |
+
|
| 187 |
+
<div class="grid grid-cols-2 md:grid-cols-4 gap-3">
|
| 188 |
+
<button id="exportImageBtn" class="bg-purple-600 hover:bg-purple-700 text-white px-3 py-2 rounded text-sm flex items-center justify-center">
|
| 189 |
+
<i class="fas fa-file-image mr-2"></i>
|
| 190 |
+
PNG Image
|
| 191 |
+
</button>
|
| 192 |
+
<button id="exportSchematicBtn" class="bg-yellow-600 hover:bg-yellow-700 text-white px-3 py-2 rounded text-sm flex items-center justify-center">
|
| 193 |
+
<i class="fas fa-file-archive mr-2"></i>
|
| 194 |
+
Schematic
|
| 195 |
+
</button>
|
| 196 |
+
<button id="exportBlueprintBtn" class="bg-red-600 hover:bg-red-700 text-white px-3 py-2 rounded text-sm flex items-center justify-center">
|
| 197 |
+
<i class="fas fa-file-alt mr-2"></i>
|
| 198 |
+
Blueprint
|
| 199 |
+
</button>
|
| 200 |
+
<button id="exportCommandBtn" class="bg-green-600 hover:bg-green-700 text-white px-3 py-2 rounded text-sm flex items-center justify-center">
|
| 201 |
+
<i class="fas fa-terminal mr-2"></i>
|
| 202 |
+
Commands
|
| 203 |
+
</button>
|
| 204 |
+
</div>
|
| 205 |
+
|
| 206 |
+
<div id="commandOutput" class="mt-4 hidden bg-gray-800 text-green-400 p-3 rounded font-mono text-sm overflow-x-auto"></div>
|
| 207 |
+
|
| 208 |
+
<div id="blockListContainer" class="mt-4 hidden">
|
| 209 |
+
<h3 class="font-medium text-gray-700 mb-2">Required Blocks</h3>
|
| 210 |
+
<div id="blockList" class="flex flex-wrap gap-2">
|
| 211 |
+
<!-- Blocks will be added here dynamically -->
|
| 212 |
+
</div>
|
| 213 |
+
</div>
|
| 214 |
+
</div>
|
| 215 |
+
</div>
|
| 216 |
+
|
| 217 |
+
<div class="bg-gray-100 p-3 text-center text-sm text-gray-600">
|
| 218 |
+
<p>Powered by TensorFlow.js AI color matching | Not affiliated with Mojang or Microsoft</p>
|
| 219 |
+
</div>
|
| 220 |
+
</div>
|
| 221 |
+
</div>
|
| 222 |
+
|
| 223 |
+
<script>
|
| 224 |
+
// Wait for TensorFlow.js to be ready
|
| 225 |
+
document.addEventListener('DOMContentLoaded', async function() {
|
| 226 |
+
// Check if TensorFlow.js is loaded
|
| 227 |
+
if (!tf) {
|
| 228 |
+
alert('Error: TensorFlow.js not loaded. Please check your internet connection.');
|
| 229 |
+
return;
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
// DOM elements
|
| 233 |
+
const dropzone = document.getElementById('dropzone');
|
| 234 |
+
const imageInput = document.getElementById('imageInput');
|
| 235 |
+
const originalPreview = document.getElementById('originalPreview');
|
| 236 |
+
const originalImage = document.getElementById('originalImage');
|
| 237 |
+
const minecraftPreview = document.getElementById('minecraftPreview');
|
| 238 |
+
const pixelArtContainer = document.getElementById('pixelArtContainer');
|
| 239 |
+
const pixelArtCanvas = document.getElementById('pixelArtCanvas');
|
| 240 |
+
const convertBtn = document.getElementById('convertBtn');
|
| 241 |
+
const randomBtn = document.getElementById('randomBtn');
|
| 242 |
+
const clearBtn = document.getElementById('clearBtn');
|
| 243 |
+
const loadingBar = document.getElementById('loadingBar');
|
| 244 |
+
const commandOutput = document.getElementById('commandOutput');
|
| 245 |
+
const blockListContainer = document.getElementById('blockListContainer');
|
| 246 |
+
const blockList = document.getElementById('blockList');
|
| 247 |
+
|
| 248 |
+
// Export buttons
|
| 249 |
+
const exportImageBtn = document.getElementById('exportImageBtn');
|
| 250 |
+
const exportSchematicBtn = document.getElementById('exportSchematicBtn');
|
| 251 |
+
const exportBlueprintBtn = document.getElementById('exportBlueprintBtn');
|
| 252 |
+
const exportCommandBtn = document.getElementById('exportCommandBtn');
|
| 253 |
+
|
| 254 |
+
// Settings
|
| 255 |
+
const resolutionSelect = document.getElementById('resolutionSelect');
|
| 256 |
+
const paletteSelect = document.getElementById('paletteSelect');
|
| 257 |
+
const ditherSelect = document.getElementById('ditherSelect');
|
| 258 |
+
|
| 259 |
+
// Current state
|
| 260 |
+
let currentImage = null;
|
| 261 |
+
let pixelArtData = null;
|
| 262 |
+
|
| 263 |
+
// Dropzone events
|
| 264 |
+
dropzone.addEventListener('click', () => imageInput.click());
|
| 265 |
+
dropzone.addEventListener('dragover', (e) => {
|
| 266 |
+
e.preventDefault();
|
| 267 |
+
dropzone.classList.add('active');
|
| 268 |
+
});
|
| 269 |
+
dropzone.addEventListener('dragleave', () => {
|
| 270 |
+
dropzone.classList.remove('active');
|
| 271 |
+
});
|
| 272 |
+
dropzone.addEventListener('drop', (e) => {
|
| 273 |
+
e.preventDefault();
|
| 274 |
+
dropzone.classList.remove('active');
|
| 275 |
+
|
| 276 |
+
if (e.dataTransfer.files.length) {
|
| 277 |
+
imageInput.files = e.dataTransfer.files;
|
| 278 |
+
handleImageUpload();
|
| 279 |
+
}
|
| 280 |
+
});
|
| 281 |
+
|
| 282 |
+
// File input change
|
| 283 |
+
imageInput.addEventListener('change', handleImageUpload);
|
| 284 |
+
|
| 285 |
+
// Button events
|
| 286 |
+
convertBtn.addEventListener('click', convertToPixelArt);
|
| 287 |
+
randomBtn.addEventListener('click', loadRandomExample);
|
| 288 |
+
clearBtn.addEventListener('click', clearAll);
|
| 289 |
+
|
| 290 |
+
// Export buttons
|
| 291 |
+
exportImageBtn.addEventListener('click', exportAsImage);
|
| 292 |
+
exportSchematicBtn.addEventListener('click', exportAsSchematic);
|
| 293 |
+
exportBlueprintBtn.addEventListener('click', exportAsBlueprint);
|
| 294 |
+
exportCommandBtn.addEventListener('click', exportAsCommands);
|
| 295 |
+
|
| 296 |
+
// Handle image upload
|
| 297 |
+
function handleImageUpload() {
|
| 298 |
+
const file = imageInput.files[0];
|
| 299 |
+
if (!file) return;
|
| 300 |
+
|
| 301 |
+
const reader = new FileReader();
|
| 302 |
+
reader.onload = function(e) {
|
| 303 |
+
originalImage.src = e.target.result;
|
| 304 |
+
originalPreview.classList.remove('hidden');
|
| 305 |
+
minecraftPreview.innerHTML = '<p class="text-gray-500 text-center">Click "Convert to Pixel Art" to generate Minecraft version</p>';
|
| 306 |
+
pixelArtContainer.classList.add('hidden');
|
| 307 |
+
blockListContainer.classList.add('hidden');
|
| 308 |
+
commandOutput.classList.add('hidden');
|
| 309 |
+
currentImage = originalImage;
|
| 310 |
+
};
|
| 311 |
+
reader.readAsDataURL(file);
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
// Convert image to pixel art
|
| 315 |
+
async function convertToPixelArt() {
|
| 316 |
+
if (!currentImage) {
|
| 317 |
+
alert('Please upload an image first');
|
| 318 |
+
return;
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
convertBtn.disabled = true;
|
| 322 |
+
loadingBar.style.width = '30%';
|
| 323 |
+
|
| 324 |
+
// Simulate processing (in a real app, this would use TensorFlow.js)
|
| 325 |
+
setTimeout(() => {
|
| 326 |
+
loadingBar.style.width = '70%';
|
| 327 |
+
|
| 328 |
+
// Get settings
|
| 329 |
+
const resolution = parseInt(resolutionSelect.value);
|
| 330 |
+
const palette = paletteSelect.value;
|
| 331 |
+
const dithering = ditherSelect.value;
|
| 332 |
+
|
| 333 |
+
// Create canvas
|
| 334 |
+
const canvas = document.createElement('canvas');
|
| 335 |
+
const ctx = canvas.getContext('2d');
|
| 336 |
+
|
| 337 |
+
// Set canvas dimensions
|
| 338 |
+
const maxDimension = Math.min(currentImage.naturalWidth || currentImage.width,
|
| 339 |
+
currentImage.naturalHeight || currentImage.height);
|
| 340 |
+
canvas.width = resolution;
|
| 341 |
+
canvas.height = resolution;
|
| 342 |
+
|
| 343 |
+
// Draw image to canvas (this would be replaced with actual TensorFlow processing)
|
| 344 |
+
ctx.drawImage(currentImage, 0, 0, resolution, resolution);
|
| 345 |
+
|
| 346 |
+
// Apply pixelation (simplified - real implementation would use TensorFlow for color matching)
|
| 347 |
+
const imageData = ctx.getImageData(0, 0, resolution, resolution);
|
| 348 |
+
const data = imageData.data;
|
| 349 |
+
|
| 350 |
+
// This is where TensorFlow.js would be used to:
|
| 351 |
+
// 1. Analyze colors
|
| 352 |
+
// 2. Match to closest Minecraft blocks
|
| 353 |
+
// 3. Apply dithering if selected
|
| 354 |
+
|
| 355 |
+
// For demo purposes, we'll just pixelate without AI
|
| 356 |
+
for (let i = 0; i < data.length; i += 4) {
|
| 357 |
+
// Simple color reduction for demo
|
| 358 |
+
data[i] = Math.round(data[i] / 51) * 51; // R
|
| 359 |
+
data[i+1] = Math.round(data[i+1] / 51) * 51; // G
|
| 360 |
+
data[i+2] = Math.round(data[i+2] / 51) * 51; // B
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
ctx.putImageData(imageData, 0, 0);
|
| 364 |
+
|
| 365 |
+
// Display result
|
| 366 |
+
pixelArtCanvas.width = resolution;
|
| 367 |
+
pixelArtCanvas.height = resolution;
|
| 368 |
+
pixelArtCanvas.getContext('2d').drawImage(canvas, 0, 0);
|
| 369 |
+
|
| 370 |
+
pixelArtContainer.classList.remove('hidden');
|
| 371 |
+
minecraftPreview.innerHTML = '<p class="text-gray-500 text-center">Pixel art generated! See export options below.</p>';
|
| 372 |
+
|
| 373 |
+
// Generate block list (simulated)
|
| 374 |
+
generateBlockList();
|
| 375 |
+
|
| 376 |
+
loadingBar.style.width = '100%';
|
| 377 |
+
setTimeout(() => {
|
| 378 |
+
loadingBar.style.width = '0%';
|
| 379 |
+
convertBtn.disabled = false;
|
| 380 |
+
}, 500);
|
| 381 |
+
|
| 382 |
+
}, 1000);
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
// Generate block list (simulated)
|
| 386 |
+
function generateBlockList() {
|
| 387 |
+
blockList.innerHTML = '';
|
| 388 |
+
|
| 389 |
+
// Simulate finding different blocks
|
| 390 |
+
const blocks = [
|
| 391 |
+
{ name: 'White Wool', color: '#E9ECEC' },
|
| 392 |
+
{ name: 'Red Wool', color: '#B02E26' },
|
| 393 |
+
{ name: 'Blue Wool', color: '#3C44AA' },
|
| 394 |
+
{ name: 'Green Wool', color: '#5E7C16' },
|
| 395 |
+
{ name: 'Yellow Wool', color: '#FED83D' },
|
| 396 |
+
{ name: 'Black Wool', color: '#1D1D21' }
|
| 397 |
+
].slice(0, 3 + Math.floor(Math.random() * 3)); // Random number of blocks
|
| 398 |
+
|
| 399 |
+
blocks.forEach(block => {
|
| 400 |
+
const blockEl = document.createElement('div');
|
| 401 |
+
blockEl.className = 'flex items-center bg-gray-100 px-2 py-1 rounded text-sm';
|
| 402 |
+
blockEl.innerHTML = `
|
| 403 |
+
<div class="w-4 h-4 rounded mr-2" style="background-color: ${block.color}"></div>
|
| 404 |
+
${block.name}
|
| 405 |
+
`;
|
| 406 |
+
blockList.appendChild(blockEl);
|
| 407 |
+
});
|
| 408 |
+
|
| 409 |
+
blockListContainer.classList.remove('hidden');
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
// Load random example
|
| 413 |
+
function loadRandomExample() {
|
| 414 |
+
const examples = [
|
| 415 |
+
'https://via.placeholder.com/512/FF5733/FFFFFF?text=Example+1',
|
| 416 |
+
'https://via.placeholder.com/512/33FF57/FFFFFF?text=Example+2',
|
| 417 |
+
'https://via.placeholder.com/512/3357FF/FFFFFF?text=Example+3',
|
| 418 |
+
'https://via.placeholder.com/512/F033FF/FFFFFF?text=Example+4'
|
| 419 |
+
];
|
| 420 |
+
|
| 421 |
+
const randomUrl = examples[Math.floor(Math.random() * examples.length)];
|
| 422 |
+
originalImage.src = randomUrl;
|
| 423 |
+
originalPreview.classList.remove('hidden');
|
| 424 |
+
minecraftPreview.innerHTML = '<p class="text-gray-500 text-center">Click "Convert to Pixel Art" to generate Minecraft version</p>';
|
| 425 |
+
pixelArtContainer.classList.add('hidden');
|
| 426 |
+
blockListContainer.classList.add('hidden');
|
| 427 |
+
commandOutput.classList.add('hidden');
|
| 428 |
+
|
| 429 |
+
// Create a fake image element to simulate loading
|
| 430 |
+
const img = new Image();
|
| 431 |
+
img.onload = function() {
|
| 432 |
+
currentImage = img;
|
| 433 |
+
};
|
| 434 |
+
img.src = randomUrl;
|
| 435 |
+
}
|
| 436 |
+
|
| 437 |
+
// Clear all
|
| 438 |
+
function clearAll() {
|
| 439 |
+
originalPreview.classList.add('hidden');
|
| 440 |
+
minecraftPreview.innerHTML = '<p class="text-gray-500 text-center">Converted pixel art will appear here</p>';
|
| 441 |
+
pixelArtContainer.classList.add('hidden');
|
| 442 |
+
blockListContainer.classList.add('hidden');
|
| 443 |
+
commandOutput.classList.add('hidden');
|
| 444 |
+
imageInput.value = '';
|
| 445 |
+
currentImage = null;
|
| 446 |
+
pixelArtData = null;
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
// Export functions
|
| 450 |
+
function exportAsImage() {
|
| 451 |
+
if (!pixelArtCanvas) {
|
| 452 |
+
alert('Please convert an image first');
|
| 453 |
+
return;
|
| 454 |
+
}
|
| 455 |
+
|
| 456 |
+
const link = document.createElement('a');
|
| 457 |
+
link.download = 'minecraft-pixel-art.png';
|
| 458 |
+
link.href = pixelArtCanvas.toDataURL('image/png');
|
| 459 |
+
link.click();
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
function exportAsSchematic() {
|
| 463 |
+
alert('Schematic export would be generated here in a real implementation');
|
| 464 |
+
}
|
| 465 |
+
|
| 466 |
+
function exportAsBlueprint() {
|
| 467 |
+
alert('Blueprint export would be generated here in a real implementation');
|
| 468 |
+
}
|
| 469 |
+
|
| 470 |
+
function exportAsCommands() {
|
| 471 |
+
if (!pixelArtCanvas) {
|
| 472 |
+
alert('Please convert an image first');
|
| 473 |
+
return;
|
| 474 |
+
}
|
| 475 |
+
|
| 476 |
+
// Simulate generating commands
|
| 477 |
+
const resolution = parseInt(resolutionSelect.value);
|
| 478 |
+
let commands = [
|
| 479 |
+
'# Minecraft Pixel Art Commands',
|
| 480 |
+
'# Generated by Minecraft Pixel Art Converter',
|
| 481 |
+
'# Resolution: ' + resolution + 'x' + resolution,
|
| 482 |
+
'',
|
| 483 |
+
'# Place these commands in command blocks or run in chat',
|
| 484 |
+
''
|
| 485 |
+
];
|
| 486 |
+
|
| 487 |
+
// Add some example commands (in a real app, this would generate actual placement commands)
|
| 488 |
+
for (let i = 0; i < 5; i++) {
|
| 489 |
+
commands.push(`/setblock ~${i} ~ ~ minecraft:white_wool`);
|
| 490 |
+
}
|
| 491 |
+
|
| 492 |
+
commands.push('', '# Total blocks: ~' + (resolution * resolution));
|
| 493 |
+
|
| 494 |
+
commandOutput.textContent = commands.join('\n');
|
| 495 |
+
commandOutput.classList.remove('hidden');
|
| 496 |
+
}
|
| 497 |
+
});
|
| 498 |
+
</script>
|
| 499 |
+
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Saad4web/pixel-arts" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
|
| 500 |
+
</html>
|