Random Anime Pixel Face Generator Schema 1. Project Overview: - Develop one code HTML,…
- User
Random Anime Pixel Face Generator Schema
- Project Overview:
- Develop one code HTML, CSS, and JavaScript for implementation.
- The generator should include distinct areas for facial features.
17 columns x 16 rows pixel grid:
33333333333333333 <--row:0, hair column: 0-16 33333333333333333 <--row:1, hair column: 0-16 33333333333333333 <--row:2, hair column: 0-16 33333333333333333 <--row:3, hair column: 0-16 33333333333333333 <--row:4, hair column: 0-16 33333333333333333 <--row:5, hair column: 0-16 24444444144444442 <--row:6, brows column: 1-7, 9-15; border column: 0 & 16 21555551115555512 <--row:7, eyes column: 2-6, 10-14; border column: 0 & 16 21555551115555512 <--row:8, eyes column: 2-6, 10-14; border column: 0 & 16 21555551115555512 <--row:9, eyes column: 2-6, 10-14; border column: 0 & 16 12111116661111121 <--row:10, nose column: 7-9, 10-14; border column: 1 & 15 11211116661111211 <--row:11, nose column: 7-9, 10-14; border column: 2 & 14 11122222222222111 <--row:12, border column: 3-13 11112777777721111 <--row:13, mouth column: 5-11; border column: 4 & 12 11111277777211111 <--row:14, mouth column: 6-10; border column: 5 & 11 11111122222111111 <--row:15, border column: 6-101: empty index 2: border outline 3: hair 4: brows 5: eyes 6: nose 7: mouth
- Project Overview:
- Assistant
Sure! Here’s a simple implementation of a random anime pixel face generator using HTML, CSS, and JavaScript. This code defines a 17x16 pixel grid for facial features, and you can customize it further to add more complexity or design.
HTML:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Random Anime Pixel Face Generator</title> <link rel="stylesheet" href="styles.css"> </head> <body> <div class="container"> <h1>Anime Pixel Face Generator</h1> <div id="pixelGrid" class="grid"></div> <button id="generateButton">Generate Random Face</button> </div> <script src="script.js"></script> </body> </html>CSS (styles.css):
body { font-family: 'Arial', sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; background-color: #f0f0f0; } .container { text-align: center; } .grid { display: grid; grid-template-columns: repeat(17, 20px); grid-template-rows: repeat(16, 20px); border: 2px solid #222; margin: 20px auto; } .pixel { width: 20px; height: 20px; border: 1px solid #ddd; box-sizing: border-box; } .hair { background-color: #000; } .brow { background-color: #6b4f4f; } .eye { background-color: #fff; } .nose { background-color: #f0a500; } .mouth { background-color: #ff0000; } .border { background-color: #222; }JavaScript (script.js):
const pixels = [ [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], // row 0 [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], // row 1 [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], // row 2 [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], // row 3 [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], // row 4 [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], // row 5 [2, 4, 4, 4, 4, 4, 4, 1, 4, 4, 4, 4, 4, 4, 4, 2], // row 6 [2, 1, 5, 5, 5, 5, 5, 1, 5, 5, 5, 5, 5, 1, 2], // row 7 [2, 1, 5, 5, 5, 5, 5, 1, 5, 5, 5, 5, 5, 1, 2], // row 8 [2, 1, 5, 5, 5, 5, 5, 1, 5, 5, 5, 5, 5, 1, 2], // row 9 [1, 1, 1, 6, 6, 6, 1, 1, 1, 1, 1, 6, 6, 6, 1, 1], // row 10 [1, 1, 2, 1, 1, 6, 6, 1, 1, 1, 1, 1, 6, 6, 1, 1], // row 11 [1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1], // row 12 [1, 1, 1, 1, 1, 7, 7, 7, 7, 7, 7, 1, 1, 1, 1, 1], // row 13 [1, 1, 1, 1, 1, 2, 7, 7, 7, 7, 1, 1, 1, 1, 1, 1], // row 14 [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1] // row 15 ]; const pixelGrid = document.getElementById('pixelGrid'); function generateRandomFace() { const randPixels = JSON.parse(JSON.stringify(pixels)); const hairColor = getRandomColor(); const browColor = getRandomColor(); const eyeColor = getRandomColor(); const noseColor = getRandomColor(); const mouthColor = getRandomColor(); // Assign random colors based on indices randPixels.forEach((row, rowIndex) => { row.forEach((value, colIndex) => { const pixel = document.createElement('div'); pixel.classList.add('pixel'); switch (value) { case 1: // empty index pixel.style.backgroundColor = "transparent"; break; case 2: // border outline pixel.classList.add('border'); break; case 3: // hair pixel.style.backgroundColor = hairColor; break; case 4: // brows pixel.style.backgroundColor = browColor; break; case 5: // eyes pixel.style.backgroundColor = eyeColor; break; case 6: // nose pixel.style.backgroundColor = noseColor; break; case 7: // mouth pixel.style.backgroundColor = mouthColor; break; } pixelGrid.appendChild(pixel); }); }); } function getRandomColor() { const randomColor = `#${Math.floor(Math.random() * 16777215).toString(16)}`; return randomColor; } document.getElementById('generateButton').addEventListener('click', function() { pixelGrid.innerHTML = ''; // Clear existing pixels generateRandomFace(); // Generate new face }); // Generate the first face on load generateRandomFace();Explanation:
- The provided HTML structure includes a grid where the pixel face will be displayed.
- The CSS styles define the appearance of the grid and individual pixels with different colors based on their roles (hair, eyes, etc.).
- The JavaScript generates a random anime face based on the predefined pixel schema. The RGB colors for the features are randomly generated.
You can adjust styles, configurations, and the features to fit your vision better. This basic framework should provide a solid starting point for creating an anime pixel face generator!
- User
one code
- Assistant
Certainly! Below is the complete code in one piece, combining HTML, CSS, and JavaScript for the random anime pixel face generator.
Complete Code:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Random Anime Pixel Face Generator</title> <style> body { font-family: 'Arial', sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; background-color: #f0f0f0; } .container { text-align: center; } .grid { display: grid; grid-template-columns: repeat(17, 20px); grid-template-rows: repeat(16, 20px); border: 2px solid #222; margin: 20px auto; } .pixel { width: 20px; height: 20px; border: 1px solid #ddd; box-sizing: border-box; } .hair { background-color: #000; } .brow { background-color: #6b4f4f; } .eye { background-color: #fff; } .nose { background-color: #f0a500; } .mouth { background-color: #ff0000; } .border { background-color: #222; } </style> </head> <body> <div class="container"> <h1>Anime Pixel Face Generator</h1> <div id="pixelGrid" class="grid"></div> <button id="generateButton">Generate Random Face</button> </div> <script> const pixels = [ [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], // row 0 [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], // row 1 [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], // row 2 [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], // row 3 [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], // row 4 [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], // row 5 [2, 4, 4, 4, 4, 4, 4, 1, 4, 4, 4, 4, 4, 4, 4, 2], // row 6 [2, 1, 5, 5, 5, 5, 5, 1, 5, 5, 5, 5, 5, 1, 2], // row 7 [2, 1, 5, 5, 5, 5, 5, 1, 5, 5, 5, 5, 5, 1, 2], // row 8 [2, 1, 5, 5, 5, 5, 5, 1, 5, 5, 5, 5, 5, 1, 2], // row 9 [1, 1, 1, 6, 6, 6, 1, 1, 1, 1, 1, 6, 6, 6, 1, 1], // row 10 [1, 1, 2, 1, 1, 6, 6, 1, 1, 1, 1, 1, 6, 6, 1, 1], // row 11 [1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1], // row 12 [1, 1, 1, 1, 1, 7, 7, 7, 7, 7, 7, 1, 1, 1, 1, 1], // row 13 [1, 1, 1, 1, 1, 2, 7, 7, 7, 7, 1, 1, 1, 1, 1, 1], // row 14 [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1] // row 15 ]; const pixelGrid = document.getElementById('pixelGrid'); function generateRandomFace() { const randPixels = JSON.parse(JSON.stringify(pixels)); const hairColor = getRandomColor(); const browColor = getRandomColor(); const eyeColor = getRandomColor(); const noseColor = getRandomColor(); const mouthColor = getRandomColor(); // Clear previous pixels pixelGrid.innerHTML = ''; // Assign colors based on indices randPixels.forEach((row) => { row.forEach((value) => { const pixel = document.createElement('div'); pixel.classList.add('pixel'); switch (value) { case 1: // empty index pixel.style.backgroundColor = "transparent"; break; case 2: // border outline pixel.classList.add('border'); break; case 3: // hair pixel.style.backgroundColor = hairColor; break; case 4: // brows pixel.style.backgroundColor = browColor; break; case 5: // eyes pixel.style.backgroundColor = eyeColor; break; case 6: // nose pixel.style.backgroundColor = noseColor; break; case 7: // mouth pixel.style.backgroundColor = mouthColor; break; } pixelGrid.appendChild(pixel); }); }); } function getRandomColor() { const randomColor = `#${Math.floor(Math.random() * 16777215).toString(16)}`; return randomColor; } document.getElementById('generateButton').addEventListener('click', generateRandomFace); // Generate the first face on load generateRandomFace(); </script> </body> </html>How to Use:
- Copy the code above and paste it into an HTML file (e.g.,
index.html). - Open the file in any web browser.
- Click the "Generate Random Face" button to see different anime pixel faces generated based on random colors.
Feel free to modify the styles and features in the JavaScript if you want to customize the effects further!
- Copy the code above and paste it into an HTML file (e.g.,