Repository: KilledByAPixel/ZzSprite Branch: master Commit: 6cb57e3b20ce Files: 5 Total size: 14.8 KB Directory structure: gitextract_qsbomy9q/ ├── .gitattributes ├── LICENSE ├── README.md ├── ZzSprite.js └── index.html ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitattributes ================================================ *.html linguist-language=Javascript ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2020 Frank Force Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # ZzSprite A Tiny Sprite Generator by Frank Force [Based on a Dweet](https://www.dwitter.net/d/3078) by Firey Fly # [Live Demo](https://killedbyapixel.github.io/ZzSprite/) ## Features - Generates a wide variety of symetric pixel art sprites - Click on a sprite to set that as the current seed - Sprite can be mutated in shape or color - Sprite sheets can be saved as pngs - Sprites can be coppied to the clipboard for easy pasting - Supports 4 color and monochrome color modes - ZzSprite function can be used to generate sprites at run time ## Example sprites... ![Example Image 1](/examples/example1.png) ## Example mutations... ![Example Image 2](/examples/example2.png) ## Example animations... ![Example Image 3](/examples/example3.png) ## So many possibilities! ![Example Image 4](/examples/example4.png) ![Favicon](/favicon.png) ================================================ FILE: ZzSprite.js ================================================ // ZzSprite - Tiny Sprite Generator - Frank Force 2020 - MIT License 'use strict'; // ==ClosureCompiler== // @compilation_level ADVANCED_OPTIMIZATIONS // @language_out ECMASCRIPT_2019 // @js_externs ZzSprite // ==/ClosureCompiler== function ZzSprite(context, x=0, y=0, seed=1, size=16, mode=0, mutateSeed=0, colorSeed=0) { function Random(max=1, min=0) { randomSeed ^= randomSeed << 13; randomSeed ^= randomSeed >>> 17; return (Math.abs(randomSeed ^= randomSeed << 5) % 1e9 / 1e9)*(max-min) + min; } // random chance to flip drawing axis let randomSeed = seed; const flipAxis = Random() < .5; const w = flipAxis ? size-3 : size/2 - 1 |0; const h = !flipAxis ? size-3 : size/2 - 1 |0; // apply mutations randomSeed += mutateSeed + 1e8; const spriteSize = size * Random(.9, .6); const density = Random(1, .9); const doubleCenter = Random() < .5; const yBias = Random(.1, -.1); const colorRand = (mode==1 ? .08 : .04); // recenter x += size/2 | 0; y += 2 | 0; function DrawSpriteInternal(x, y, outline) { // draw each pixel randomSeed = seed; const passCount = mode == 3 ? 3: 1 for(let pass=0; pass < passCount; ++pass) for(let k=0; k < w*h; ++k) { const i = flipAxis ? k/w|0 : k%w; const j = !flipAxis ? k/w|0 : k%w; // pick new random color using color seed const saveSeed = randomSeed; randomSeed += colorSeed + 1e9; const r = Random(360)|0; let newColor = `hsl(${ r },${ Random(200,0)|0 }%,${ Random(100,20)|0 }%)`; if (outline || mode == 3) newColor = '#000'; else if (mode == 1) newColor = r%3? r%3==1 ? '#444' : '#999' : '#fff'; else if (mode == 2) newColor = `#fff`; if (!k || Random() < colorRand) context.fillStyle = newColor; randomSeed = saveSeed; // check if pixel should be drawn const isHole = Random() > density; if (Random(spriteSize/2)**2 > i*i + (j-(1-2*yBias)*h/2)**2 && !isHole) { const o = !!outline; context.fillRect(x+i-o-doubleCenter, y+j-o, 1+2*o, 1+2*o); context.fillRect(x-i-o, y+j-o, 1+2*o, 1+2*o); } } } // outline then fill if (mode != 3) DrawSpriteInternal(x, y, 1); DrawSpriteInternal(x, y); } ================================================ FILE: index.html ================================================
Advanced