Esempio n. 1
0
        public static Color[] CreateGradient(Color[] colors, int minSteps, int maxSteps)
        {
            List <Color> tmp = new List <Color>();

            SS_Random random = new SS_Random(0);

            int steps = random.Range(minSteps, maxSteps);

            for (int j = 0; j < colors.Length - 1; j++)
            {
                Color start = colors[j];
                Color end   = colors[j + 1];

                for (int i = 0; i < steps; i++)
                {
                    Color result = new
                                   Color(
                        start.r + (i * (end.r - start.r) / steps),
                        start.g + (i * (end.g - start.g) / steps),
                        start.b + (i * (end.b - start.b) / steps)
                        );

                    tmp.Add(result);
                }
            }

            return(tmp.ToArray());
        }
Esempio n. 2
0
        public SS_Ship(int seed, SS_ShipType shipType, float bodyDetail, int bodyLength, float wingDetail, Color[] colors, float colorDetail)
        {
            Seed = seed;

            ColorBase      = colors[0];
            ColorHighlight = colors[1];
            ColorEngine    = colors[2];

            BodyDetail  = bodyDetail;
            BodyLength  = bodyLength;
            WingDetail  = wingDetail;
            ColorDetail = colorDetail;

            Sprite = new SS_Texture(Size, Size, Color.clear);

            random = new SS_Random(Seed);

            // generate ship based on type
            if (shipType == SS_ShipType.Fighter)
            {
                CreateWing(Sprite, Color.grey, random.NextBool());
                CreateBody(Sprite, SS_ShipBody.Human, bodyLength, random.Range(0, 4), random.NextBool());
                CreateEngine(Sprite, random.Range(1, 6));
                CreateTank(Sprite, random.Range(1, 6), Color.grey, random.NextBool());
                CreateWing(Sprite, Color.grey, random.NextBool());
                CreateCockpit(Sprite, Color.cyan);
            }
            else if (shipType == SS_ShipType.Fighter2)
            {
                CreateWing(Sprite, Color.grey, random.NextBool());
                CreateWing(Sprite, Color.grey, random.NextBool());
                CreateBody(Sprite, SS_ShipBody.Human, bodyLength, random.Range(0, 4), random.NextBool());
                CreateEngine(Sprite, random.Range(1, 4));
                CreateTank(Sprite, random.Range(1, 4), Color.grey, random.NextBool());
                CreateWing(Sprite, Color.grey, random.NextBool());
                CreateWing(Sprite, Color.grey, random.NextBool());
                CreateCockpit(Sprite, Color.cyan);
            }
            else if (shipType == SS_ShipType.Hauler)
            {
                CreateBody(Sprite, SS_ShipBody.Human, bodyLength, random.Range(0, 4), random.NextBool());
                CreateEngine(Sprite, random.Range(1, 4));
                CreateTank(Sprite, 2, Color.grey, random.NextBool());
                CreateCockpit(Sprite, Color.cyan);
            }
            else if (shipType == SS_ShipType.Saucer)
            {
                BodyLength = 48;

                //CreateWing(Sprite, Color.grey, random.NextBool());
                CreateBody(Sprite, SS_ShipBody.Alien, bodyLength, random.Range(0, 4), random.NextBool());
                //CreateTank(Sprite, 1, Color.grey, random.NextBool());
                //CreateWing(Sprite, Color.grey, random.NextBool());
            }
        }
Esempio n. 3
0
        public SS_Starfield(int seed, int size, int starCount)
        {
            // Create sprite texture
            Sprite = new SS_Texture(size, size, Color.clear);

            // Random generator
            SS_Random random = new SS_Random(seed);

            // Create point stars
            for (int i = 0; i < starCount; i++)
            {
                int x = random.Range(0, size - 1);
                int y = random.Range(0, size - 1);

                Sprite.SetPixel(x, y, new Color(1f, 1f, 1f, random.Range(0.5f, 1.0f)));
            }
        }
Esempio n. 4
0
        public static Color[] GenerateColorWheelColors(int seed, int count)
        {
            SS_Texture colorWheel = ColorWheel();

            Color[] colors = new Color[count];

            SS_Random random = new SS_Random(seed);

            float angle = random.Range(0f, 360f);

            for (int i = 0; i < count; i++)
            {
                float xPos = (colorWheel.Width / 2) + Mathf.Cos(angle) * 32;
                float yPos = (colorWheel.Height / 2) + Mathf.Sin(angle) * 32;

                colors[i] = colorWheel.GetPixel((int)xPos, (int)yPos);
                angle    += 360 / count;
            }

            return(colors);
        }
Esempio n. 5
0
        public SS_Station(int seed, SS_StationType stationType, Color tint, int numberOfPods)
        {
            Seed = seed;

            random = new SS_Random(Seed);
            Sprite = new SS_Texture(Size, Size, Color.clear);

            if (stationType == SS_StationType.Cool)
            {
                CreateRing(random.Range(0.85f, 1.0f), random.Range(1, 4), true, random.NextColor(), false);
                CreateRing(random.Range(0.5f, 0.75f), random.Range(1, 4), true, random.NextColor(), true);

                // Draw lights
                for (int i = 0; i < LightPoints.Count; i++)
                {
                    CreateFlare(Sprite, LightPoints[i], 16, true, Color.white);
                }

                int podCount    = random.RangeEven(2, 8);
                int podWidth    = random.RangeEven(24, 32);
                int podHeight   = random.RangeEven(12, 24);
                int podDistance = random.RangeEven(64, Size / 2 - 32);
                CreatePods(podCount, podWidth, podHeight, 8, podDistance, 1.0, Color.grey);
                CreatePods(podCount, podWidth, podHeight, 8, podDistance, 0.75, Color.grey);

                Color[] flareColors = SS_Utilities.GenerateColorWheelColors(Seed, 3);
                CreateFlare(Sprite, new SS_Point(Sprite.Center.x, Sprite.Center.y), 128, true, flareColors[0]);
                CreateFlare(Sprite, new SS_Point(Sprite.Center.x, Sprite.Center.y), 64, true, flareColors[1]);
                CreateFlare(Sprite, new SS_Point(Sprite.Center.x, Sprite.Center.y), 32, true, flareColors[2]);
            }
            else if (stationType == SS_StationType.Pod)
            {
                int podCount    = numberOfPods;
                int podSize     = 64;
                int step        = 360 / podCount;
                int bridgeWidth = random.RangeEven(8, 16);

                // Setup pod positions
                List <SS_Point> podPositions = new List <SS_Point>();
                for (int a = 0; a < 359; a += step)
                {
                    int x = Sprite.Center.x + (int)(Mathf.Cos(a * Mathf.Deg2Rad) * 96);
                    int y = Sprite.Center.y + (int)(Mathf.Sin(a * Mathf.Deg2Rad) * 96);

                    podPositions.Add(new SS_Point(x, y));
                }

                for (int i = 0; i < podPositions.Count; i++)
                {
                    SS_Texture      tmpBridgeTexture = new SS_Texture(Size, Size, Color.clear);
                    List <SS_Point> points           = new List <SS_Point>();

                    int px1 = podPositions[i].x + (int)(Mathf.Cos((i * step - 90) * Mathf.Deg2Rad) * bridgeWidth);
                    int py1 = podPositions[i].y + (int)(Mathf.Sin((i * step - 90) * Mathf.Deg2Rad) * bridgeWidth);
                    int px2 = podPositions[i].x + (int)(Mathf.Cos((i * step + 90) * Mathf.Deg2Rad) * bridgeWidth);
                    int py2 = podPositions[i].y + (int)(Mathf.Sin((i * step + 90) * Mathf.Deg2Rad) * bridgeWidth);

                    int cx1 = Sprite.Center.x + (int)(Mathf.Cos((i * step - 90) * Mathf.Deg2Rad) * bridgeWidth);
                    int cy1 = Sprite.Center.y + (int)(Mathf.Sin((i * step - 90) * Mathf.Deg2Rad) * bridgeWidth);
                    int cx2 = Sprite.Center.x + (int)(Mathf.Cos((i * step + 90) * Mathf.Deg2Rad) * bridgeWidth);
                    int cy2 = Sprite.Center.y + (int)(Mathf.Sin((i * step + 90) * Mathf.Deg2Rad) * bridgeWidth);

                    points.Add(new SS_Point(cx1, cy1));
                    points.Add(new SS_Point(px1, py1));
                    points.Add(new SS_Point(px2, py2));
                    points.Add(new SS_Point(cx2, cy2));

                    SS_Drawing.PolygonFill(tmpBridgeTexture, points.ToArray(), SS_StellarSprite.FillColor, SS_StellarSprite.FillColor);
                    SS_Drawing.MergeColors(Sprite, tmpBridgeTexture, 0, 0);
                }

                int numPoints = random.RangeEven(6, 10);
                for (int i = 0; i < podPositions.Count; i++)
                {
                    float angleStep = 360.0f / numPoints;

                    List <SS_Point> controlPoints = new List <SS_Point>();
                    for (float angle = 0; angle < 360f; angle += angleStep)
                    {
                        int px = (int)(podPositions[i].x + (Mathf.Cos(angle * Mathf.Deg2Rad) * (podSize * 0.5)));
                        int py = (int)(podPositions[i].y + (Mathf.Sin(angle * Mathf.Deg2Rad) * (podSize * 0.5)));

                        controlPoints.Add(new SS_Point(px, py));
                    }

                    SS_Texture tmpPodTexture = new SS_Texture(Size, Size, Color.clear);
                    SS_Drawing.PolygonFill(tmpPodTexture, controlPoints.ToArray(), SS_StellarSprite.OutlineColor, SS_StellarSprite.FillColor);
                    SS_Drawing.MergeColors(Sprite, tmpPodTexture, 0, 0);

                    List <SS_Point> controlPoints2 = new List <SS_Point>();
                    for (float angle = 0; angle < 360f; angle += angleStep)
                    {
                        int px = (int)(podPositions[i].x + (Mathf.Cos(angle * Mathf.Deg2Rad) * (podSize * 0.4)));
                        int py = (int)(podPositions[i].y + (Mathf.Sin(angle * Mathf.Deg2Rad) * (podSize * 0.4)));

                        controlPoints2.Add(new SS_Point(px, py));
                        LightPoints.Add(new SS_Point(px, py));
                    }

                    SS_Texture tmpPodTexture2 = new SS_Texture(Size, Size, Color.clear);
                    SS_Drawing.PolygonFill(tmpPodTexture2, controlPoints2.ToArray(), SS_StellarSprite.OutlineColor, SS_StellarSprite.FillColor);
                    SS_Drawing.MergeColors(Sprite, tmpPodTexture2, 0, 0);
                }

                int hubSize      = random.RangeEven(64, 128);
                int numHubPoints = random.RangeEven(6, 10);

                float hubAngleSteps = 360.0f / numHubPoints;

                List <SS_Point> hubPoints = new List <SS_Point>();
                for (float angle = 0; angle < 360f; angle += hubAngleSteps)
                {
                    int px = (int)(Sprite.Center.x + (Mathf.Cos(angle * Mathf.Deg2Rad) * (hubSize * 0.5)));
                    int py = (int)(Sprite.Center.y + (Mathf.Sin(angle * Mathf.Deg2Rad) * (hubSize * 0.5)));

                    hubPoints.Add(new SS_Point(px, py));
                }

                SS_Texture tmpHub = new SS_Texture(Size, Size, Color.clear);
                SS_Drawing.PolygonFill(tmpHub, hubPoints.ToArray(), SS_StellarSprite.OutlineColor, SS_StellarSprite.FillColor);
                SS_Drawing.MergeColors(Sprite, tmpHub, 0, 0);

                List <SS_Point> hubPoints2 = new List <SS_Point>();
                for (float angle = 0; angle < 360f; angle += hubAngleSteps)
                {
                    int px = (int)(Sprite.Center.x + (Mathf.Cos(angle * Mathf.Deg2Rad) * (hubSize * 0.4)));
                    int py = (int)(Sprite.Center.y + (Mathf.Sin(angle * Mathf.Deg2Rad) * (hubSize * 0.4)));

                    hubPoints2.Add(new SS_Point(px, py));
                }

                SS_Texture tmpHub2 = new SS_Texture(Size, Size, Color.clear);
                SS_Drawing.PolygonFill(tmpHub2, hubPoints2.ToArray(), SS_StellarSprite.OutlineColor, SS_StellarSprite.FillColor);
                SS_Drawing.MergeColors(Sprite, tmpHub2, 0, 0);

                SS_Drawing.Outline(Sprite, Color.black);
                Texturize(Sprite, Color.magenta, tint, false, true);
                SS_StellarSprite.ShadeEdge(Sprite);

                SS_StellarSprite.Mirror(Sprite, SS_Mirror.TopRight);

                foreach (SS_Point p in podPositions)
                {
                    CreateFlare(Sprite, p, 32, false, Color.white);
                }

                foreach (SS_Point p in LightPoints)
                {
                    CreateFlare(Sprite, p, 16, true, Color.white);
                }

                CreateFlare(Sprite, Sprite.Center, hubSize, false, Color.white);
            }
        }
Esempio n. 6
0
        public SS_Blackhole(int seed, int size)
        {
            Seed = seed;
            Size = size;

            Sprite = new SS_Texture(Size, Size, Color.clear);
            SS_Random random = new SS_Random(Seed);

            float radius = Size * 0.75f;
            float atmosphereThickness = Size * 0.125f;

            for (int y = 0; y < Size; y++)
            {
                for (int x = 0; x < Size; x++)
                {
                    //float dist = Vector2.Distance(new Vector2(x, y), new Vector2(sprite.Center.x, sprite.Center.y));
                    int dist = SS_Point.Distance(new SS_Point(x, y), Sprite.Center);

                    if (dist <= (radius / 2))
                    {
                        Sprite.SetPixel(x, y, Color.black);
                    }

                    // Create "glow"
                    Color currentPixel = Sprite.GetPixel(x, y);

                    Color atmosphereColor = Color.black;
                    if (currentPixel == Color.clear)
                    {
                        atmosphereColor.a = 1;
                        //float distToEdge = Vector2.Distance(new Vector2(x, y), new Vector2(sprite.Center.x, sprite.Center.y));
                        int distToEdge = SS_Point.Distance(new SS_Point(x, y), Sprite.Center);
                        if (distToEdge < (radius / 2) + atmosphereThickness &&
                            distToEdge > (radius / 2))
                        {
                            float dist2 = dist - (radius / 2);
                            atmosphereColor.a = (atmosphereThickness - dist2) / atmosphereThickness;;

                            Sprite.SetPixel(x, y, atmosphereColor);
                        }
                    }
                }
            }

            // Calculate the number of light points around the even horizon based on the square root of the size halfed.
            int lightSpecCount = (int)(Mathf.Sqrt(Size) / 2) * Size;

            // Create specs of light around event horizon
            for (int i = 0; i < lightSpecCount; i++)
            {
                int a    = random.Range(0, 359);
                int dist = (short)random.Range(radius * 0.25f, radius * 0.65f);

                int x = Sprite.Center.x + (int)(Mathf.Cos(a * Mathf.Deg2Rad) * dist);
                int y = Sprite.Center.y + (int)(Mathf.Sin(a * Mathf.Deg2Rad) * dist);

                SS_Point p = new SS_Point(x, y);

                int distToCenter = SS_Point.Distance(p, Sprite.Center);

                float v = 1 - (distToCenter / radius);

                Color c = new Color(v, v, v);

                Sprite.SetPixel(x, y, c);
            }

            SS_Drawing.Swirl(Sprite, Sprite.Width / 2, Sprite.Height / 2, Sprite.Width / 2, 5f);

            for (int y = 0; y < Size; y++)
            {
                for (int x = 0; x < Size; x++)
                {
                    float dist = Vector2.Distance(new Vector2(x, y), new Vector2(Sprite.Center.x, Sprite.Center.y));

                    if (dist > (radius * 0.25f))
                    {
                        Color c = Sprite.GetPixel(x, y);
                        c.a = 1 - (dist / (Size / 2));
                        Sprite.SetPixel(x, y, c);
                    }
                }
            }

            SS_Drawing.Ellipse(Sprite, Sprite.Center.x, Sprite.Center.y, (int)(radius * 0.25), (int)(radius * 0.25), 32, Color.white);
        }
Esempio n. 7
0
        public SS_Planet(int seed, int size, Color[] colors, SS_PlanetType planetType, double frequency, double lacunarity, double persistence, int octaves, bool oceans, bool clouds, float cloudDensity, float cloudTransparency, bool atmosphere, bool city, float cityDensity, bool ring, float ringDetail, float lightAngle)
        {
            Seed = seed;

            if (ring)
            {
                Width = size * 2;
            }
            else
            {
                Width = size;
            }
            Height = size;

            // randomize based on seed
            random = new SS_Random(seed);

            // Create the sprite texture
            Sprite = new SS_Texture(Width, Height, Color.clear);

            // Create a gradient using the supplid colors and between 16 and 32 steps
            gradientColors = SS_Utilities.CreateGradient(colors, 16, 32);

            // Generate Perlin Noise
            //Perlin noise = new Perlin(frequency, 2, 0.5, 8, seed, QualityMode.High);
            Perlin noise      = new Perlin(frequency, lacunarity, persistence, octaves, seed, QualityMode.High);
            Perlin cloudNoise = new Perlin(0.02, 2, 0.5, 12, seed + 1, QualityMode.Low);

            // Radius of planet - only use 90% to make room for the atmosphere
            float radius = Height * 0.9f;

            // Oceans levels - determines how much water/terrain is visible
            float settleLevel = 0.4f;                   //random.Range(0.25f, 0.75f);

            // Thickeness of atmosphere - between 8-16 pixels
            int atmosphereThickness = random.Range((int)(Height * 0.01f), (int)(Height * 0.05f));

            atmosphereThickness = Mathf.Clamp(atmosphereThickness, 8, 16);

            // Calculate light position based on supplied lightAngle (degrees)
            Vector2 lightPosition = new Vector2(
                Sprite.Center.x + (Mathf.Cos(lightAngle * Mathf.Deg2Rad) * (radius * 0.8f)),
                Sprite.Center.y + (Mathf.Sin(lightAngle * Mathf.Deg2Rad) * (radius * 0.8f)));

            if (lightPosition.y < 0)
            {
                lightPosition.y = 0;
            }
            if (lightPosition.y > Height - 1)
            {
                lightPosition.y = Height - 1;
            }

            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    // Get distance of current point to the center of the sprite
                    float dist = Vector2.Distance(new Vector2(x, y), Sprite.Center.ToVector2);

                    // Check to see if this point is within the planets radius
                    if (dist <= (radius / 2))
                    {
                        // Get noise value for current point and clamp it between 0 and 1
                        float planetNoise = (float)noise.GetValue(x, y, 0);
                        planetNoise = (planetNoise + 1.0f) * 0.5f;
                        planetNoise = Mathf.Clamp(planetNoise, 0f, 1f);

                        // Gas Giant
                        if (planetType == SS_PlanetType.Gas_Giant)
                        {
                            // Get distance of the current point to the top-center of the sprite
                            float distNorthPole = Vector2.Distance(new Vector2(x, Height - 1), Sprite.Center.ToVector2);

                            // Generate gassy noise
                            float n = (float)noise.GetValue(dist / 10 + (planetNoise * 10f), y - (distNorthPole / 5) + (planetNoise * 10f), 0);
                            n  = (n + 1.0f) * 0.5f;
                            n  = Mathf.Clamp(n, 0f, 1f);
                            n *= (gradientColors.Length - 1);
                            Sprite.SetPixel(x, y, gradientColors[(int)n]);
                        }
                        // Terrestrial
                        else if (planetType == SS_PlanetType.Terrestrial)
                        {
                            Color pixelColor = new Color();

                            if (oceans)
                            {
                                if (planetNoise > settleLevel)
                                {
                                    float n = planetNoise * (gradientColors.Length - 1);

                                    // Generate color and noise so land doesn't look to smooth
                                    pixelColor   = gradientColors[(int)n];
                                    pixelColor  *= planetNoise;
                                    pixelColor.a = 1.0f;
                                }
                                else
                                {
                                    float n = planetNoise * ((gradientColors.Length - 1) / colors.Length);

                                    // solid ocean color
                                    pixelColor = gradientColors[(int)n];
                                }
                            }
                            else
                            {
                                float n = planetNoise * (gradientColors.Length - 1);

                                // Generate color and noise so land doesn't look to smooth
                                pixelColor = gradientColors[(int)n];
                            }

                            pixelColor.a = 1.0f;
                            Sprite.SetPixel(x, y, pixelColor);

                            if (clouds)
                            {
                                float cloud = (float)cloudNoise.GetValue(x, y, 0);
                                cloud = (cloud + 1.0f) * 0.5f;
                                cloud = Mathf.Clamp(cloud, 0f, 1f);

                                if (cloud >= cloudDensity)
                                {
                                    Color cloudColor  = Color.white;
                                    Color planetColor = Sprite.GetPixel(x, y);

                                    float alpha    = cloudTransparency * cloud;
                                    Color newColor = new Color();
                                    newColor.r = alpha * cloudColor.r + (1 - alpha) * planetColor.r;
                                    newColor.g = alpha * cloudColor.g + (1 - alpha) * planetColor.g;
                                    newColor.b = alpha * cloudColor.b + (1 - alpha) * planetColor.b;
                                    newColor.a = 1f;
                                    Sprite.SetPixel(x, y, newColor);
                                }
                            }
                        }
                        else if (planetType == SS_PlanetType.Barren)
                        {
                            // Generate gassy noise
                            float n = planetNoise;
                            n  = (n + 1.0f) * 0.5f;
                            n  = Mathf.Clamp(n, 0f, 1f);
                            n *= (gradientColors.Length - 1);
                            Sprite.SetPixel(x, y, gradientColors[(int)n]);
                        }
                    }

                    // Create inner atmosphere
                    if (atmosphere)
                    {
                        Color atmosphereColor = gradientColors[0];
                        atmosphereColor.a = 1f;

                        if (dist < (radius / 2) && dist > (radius / 2) - atmosphereThickness)
                        {
                            float d = Mathf.Abs(dist - (radius / 2));
                            float a = (atmosphereThickness - d) / atmosphereThickness;

                            Color newColor = SS_Utilities.Blend(atmosphereColor, Sprite.GetPixel(x, y), a);
                            Sprite.SetPixel(x, y, newColor);
                        }
                    }
                }
            }

            // Ring
            SS_Texture tmpRingRotated = new SS_Texture(Width, Height, Color.clear);
            SS_Texture tmpRing        = new SS_Texture(Width, Height, Color.clear);

            if (ring)
            {
                Perlin perlinRing = new Perlin(ringDetail, 2, 0.5, 8, seed, QualityMode.High);

                // Create a gradient using the supplid colors and between 16 and 32 steps
                Color[] ringColors = SS_Utilities.GenerateColorWheelColors(seed, 6);
                ringColors[1] = Color.black;
                ringColors[4] = Color.black;
                Color[] ringGradient = SS_Utilities.CreateGradient(ringColors, 8, 16);

                float ringW      = (int)(radius * 0.6);
                float ringH      = (int)(radius * random.Range(0.05f, 0.2f));
                int   resolution = 360;

                // Basically we are drawing a bunch of ellipses that get bigger
                for (int i = 0; i < (radius / 2) - 16; i++)
                {
                    // I'm spicy and confusing because my programmer is a douche.
                    // I'll explain
                    // get some noise and normalize it from 0-1
                    float ringNoise = (float)perlinRing.GetValue(i, 0, 0);
                    ringNoise = (ringNoise + 1.0f) * 0.5f;
                    ringNoise = Mathf.Clamp(ringNoise, 0.0f, 1f);

                    // multiple said 0.0-1 value by the number of colors available for the ring to get an int value for what color to use of the array
                    Color c = ringGradient[(int)(ringNoise * (ringGradient.Length - 1))];

                    // The darkness of the color value also sets the alpha value (darker values are more transparent)
                    c.a = (c.r + c.g + c.b) / 3f;

                    SS_Drawing.Ellipse(tmpRing, Sprite.Center.x, Sprite.Center.y, (int)ringW, (int)ringH, resolution * 4, c);

                    ringW += 1f;
                    ringH += 0.5f;
                }

                // rotate ring
                float ringAngle = random.Range(-3f, 3f);
                for (int y = 0; y < Height; y++)
                {
                    for (int x = 0; x < Width; x++)
                    {
                        SS_Point rotatedPoint = SS_Point.Rotate(new SS_Point(x, y), Sprite.Center.x, Sprite.Center.y, ringAngle);

                        tmpRingRotated.SetPixel(x, y, tmpRing.GetPixel(rotatedPoint.x, rotatedPoint.y));
                    }
                }

                //SS_Drawing.Blur(ref tmpRingRotated);

                // Copy Ring data to Planet Sprite ignoring the parts "behind" the planet.
                for (int y = 0; y < Height; y++)
                {
                    for (int x = 0; x < Width; x++)
                    {
                        // Bottom (in front of planet)
                        if (y <= (Height / 2))
                        {
                            // Make sure we have a ring pixel
                            if (tmpRingRotated.GetPixel(x, y) != Color.clear)
                            {
                                // if the pixel behind the ring pixel is clear, then just copy the data as is
                                if (Sprite.GetPixel(x, y) == Color.clear)
                                {
                                    Sprite.SetPixel(x, y, tmpRingRotated.GetPixel(x, y));
                                }
                                // if the pixel behind the ring pixel IS NOT clear, then we have to blend the two pixels
                                // using the ring's alpha for the blend factor
                                else
                                {
                                    Color newColor = SS_Utilities.Blend(tmpRingRotated.GetPixel(x, y), Sprite.GetPixel(x, y), tmpRingRotated.GetPixel(x, y).a);
                                    Sprite.SetPixel(x, y, newColor);
                                }
                            }
                        }
                        // Top (behind planet)
                        else
                        {
                            // no blending here, so just copy the pixel (ignoring pixels that already have a value)
                            if (Sprite.GetPixel(x, y) == Color.clear)
                            {
                                Sprite.SetPixel(x, y, tmpRingRotated.GetPixel(x, y));
                            }
                        }
                    }
                }
            }

            // Atmosphere and Shadows depend on ring
            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    // Get distance of current point to the center of the sprite
                    float dist = Vector2.Distance(new Vector2(x, y), Sprite.Center.ToVector2);

                    // Create outer atmosphere
                    if (atmosphere)
                    {
                        Color currentPixel    = Sprite.GetPixel(x, y);
                        Color atmosphereColor = gradientColors[0];
                        atmosphereColor.a = 1f;

                        if (dist < (radius / 2) + atmosphereThickness && dist > (radius / 2))
                        {
                            float d = Mathf.Abs(dist - (radius / 2));
                            atmosphereColor.a = (atmosphereThickness - d) / atmosphereThickness;

                            if (currentPixel == Color.clear)
                            {
                                Sprite.SetPixel(x, y, atmosphereColor);
                            }
                            else
                            {
                                Color newColor = SS_Utilities.Blend(atmosphereColor, Sprite.GetPixel(x, y), atmosphereColor.a);
                                Sprite.SetPixel(x, y, newColor);
                            }
                        }
                    }

                    // Shadow
                    float lightDistance = Vector2.Distance(new Vector2(x, y), lightPosition);

                    lightDistance = 1.15f - SS_Utilities.Normalize(lightDistance, 0, Height);
                    if (lightDistance < 0.025f)
                    {
                        lightDistance = 0.025f;
                    }

                    Color lightingColor = Sprite.GetPixel(x, y);
                    lightingColor.r *= lightDistance;
                    lightingColor.g *= lightDistance;
                    lightingColor.b *= lightDistance;
                    Sprite.SetPixel(x, y, lightingColor);

                    // City lights
                    if (city)
                    {
                        if (dist <= (radius / 2))
                        {
                            float pixelNoise = (float)noise.GetValue(x, y, 0);
                            pixelNoise = (pixelNoise + 1.0f) * 0.5f;
                            pixelNoise = Mathf.Clamp(pixelNoise, 0f, 1f);

                            if (Sprite.GetPixel(x, y).grayscale < 0.025f)
                            {
                                // Find land edges
                                if (pixelNoise > settleLevel && pixelNoise < settleLevel + 0.05f)
                                {
                                    if (random.Range(0f, 1f) > cityDensity)
                                    {
                                        // I don't know - i just wrotes numbers beside some colors and hoped for the best.
                                        // Hurray for laziness!
                                        Color newColor = (Color.white * 0.65f + Color.yellow * 0.85f) * 0.8f;
                                        newColor.a = 1;

                                        // Blend the city light with the ring if there is one
                                        Color ringColor = tmpRingRotated.GetPixel(x, y);
                                        if (ring && ringColor != Color.clear)
                                        {
                                            newColor = SS_Utilities.Blend(newColor, ringColor, ringColor.a);
                                        }

                                        Sprite.SetPixel(x, y, newColor);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }