A web-based avatar maker where four overlapping image layers (body
, eyes
, hair
, cloths
) create a full avatar. Users can change each layer using navigation buttons or generate a random avatar.
- Layer-based avatar customization
- 8 navigation buttons to change layers
- 🎲 Randomize Avatar button to create a unique look instantly
- Uses assets from Raid Heroes: Total War
- Live preview: Click Here
- Open
index.html
in a browser. - Click the left/right buttons to change each layer.
- Click 🎲 Randomize Avatar to generate a unique look instantly!
With all layers combined, there are 143,360 possible avatar combinations!
- HTML
- CSS
- JavaScript
/avatar-maker
│── index.html # The main UI with image layers & buttons
│── styles.css # Styling for avatar layout & buttons
│── script.js # Core logic for image swapping & randomization
│── body/ # Folder containing 5 images (0.png - 4.png)
│── eyes/ # Folder containing 7 images (0.png - 6.png)
│── hair/ # Folder containing 64 images (0.png - 63.png)
│── cloths/ # Folder containing 64 images (0.png - 63.png)
The core logic is handled by JavaScript, where each layer has a predefined number of images, and the user can switch between them.
let imageCounts = { body: 5, eyes: 7, hair: 64, cloths: 64 };
let currentIndexes = { body: 0, eyes: 0, hair: 0, cloths: 0 };
imageCounts
→ Stores the total images available for each layer.currentIndexes
→ Keeps track of the current image index for each layer.
function changeLayer(layer, direction) {
let maxImages = imageCounts[layer];
currentIndexes[layer] = (currentIndexes[layer] + direction + maxImages) % maxImages;
updateImage(layer);
}
- Moves the current image index forward (
+1
) or backward (-1
). - Uses modulus (
%
) arithmetic to wrap around when reaching the first/last image. - Calls
updateImage(layer)
, which updates the<img>
tag source dynamically.
function updateImage(layer) {
let newImagePath = `${layer}/${currentIndexes[layer]}.png`;
document.getElementById(layer).src = newImagePath;
}
- Constructs the correct image path based on
layer
andcurrentIndexes[layer]
. - Updates the
src
attribute of the<img>
element for that layer.
function randomizeAvatar() {
for (let layer in imageCounts) {
currentIndexes[layer] = Math.floor(Math.random() * imageCounts[layer]);
updateImage(layer);
}
}
- Loops through all layers (
body
,eyes
,hair
,cloths
). - Randomly picks an image for each layer using
Math.random()
. - Calls
updateImage(layer)
to update the avatar.
- Game: Raid Heroes: Total War
- All assets belong to their respective owners.
- Fork this repo: https://github.com/Abhay557/avatar
- Clone it:
git clone https://github.com/YOUR_USERNAME/avatar.git
- Make changes and push:
git add . git commit -m "Your message" git push origin main
This project is open-source under the MIT License.