Created
June 1, 2016 21:29
-
-
Save Shogan/674f2d6e9f86902b04a4a005bfe24f71 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using PixelSpriteGenerator; | |
public class RandomShrub : MonoBehaviour { | |
private PsgMask mask; | |
private PsgSprite sprite; | |
private SpriteRenderer sr; | |
// Use this for initialization | |
void Start () { | |
sr = GetComponent<SpriteRenderer> (); | |
mask = new PsgMask (new int[] { | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 2, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 2, 2, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, -1, 2, 2, 2, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, -1, 2, 2, 2, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 2, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 2, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 2, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, -1, 2, 2, 2, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, -1, 2, 2, 2, | |
0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 2, 2, 2, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 2, 2, 2, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 2, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, 2, 2, 2, 2, 2, | |
0, 0, 0, 0, 0, 0, 0, -1, -1, 0, 0, -1, -1, 2, 2, 2, | |
0, 0, 0, 0, 0, 0, -1, 0, -1, 0, 0, -1, 0, -1, 2, 2, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, -1, 2, 2, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, | |
0, 0, 0, 0, 0, 0, 0, -1, -1, 2, 0, 0, 0, 2, 2, 2, | |
0, 0, 0, 0, 0, 0, -1, 0, 0, -1, -1, 2, 0, 2, 2, 2, | |
0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, -1, -1, 2, 2, 2, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 2, 2, 2, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 2, 2, 2, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -2, 2, 2, 2, | |
}, 16, 32, true, false); | |
var options = new PsgOptions () { | |
Colored = true, | |
EdgeBrightness = 0.3f, | |
ColorVariations = 0.2f, | |
BrightnessNoise = 0.3f, | |
Saturation = 0.5f | |
}; | |
sprite = new PsgSprite (mask, options); | |
var tex = sprite.texture; | |
tex.wrapMode = TextureWrapMode.Clamp; | |
tex.filterMode = FilterMode.Point; | |
sr.sprite = Sprite.Create(tex, new Rect(0, 0, 32f, 32f), new Vector2(0.5f, 0.5f), 32f); | |
sr.flipY = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Found a small work around by subtracting 0.02f from the width before creating the sprite. Any idea why your example ships have a much larger variance in color compared to the original project's even with the same settings? Each individual pixel color seems more random in your examples. Comparing the 'many color variations' sprites you have on this project's readme against the original project's 'many color variations' sprites it's quite noticable