Exemple #1
0
        private void DrawFlag(int x, int y, int index, bool large)
        {
            var h   = index * Dy;
            var max = Big;

            if (!large)
            {
                h  += Big + 1;
                max = Small;
            }


            for (var i = 0; i < flags.Width; ++i)
            {
                for (var j = 0; j < max; ++j)
                {
                    int r, g, b;
                    flags.GetPixel(i, j + h, out r, out g, out b);
                    if ((flags.Image[i + (j + h) * flags.Width] & 0xFF000000) != 0)
                    {
                        SetPixel(i + x, j + y, r, g, b);
                    }
                }
            }
        }
Exemple #2
0
        } // FillImages

        public override void Update()
        {
            base.Update();

            int src_width, src_height;
            int dest_width, dest_height;

            // get image and dest sizes
            src_width   = img1.Width;
            src_height  = img1.Height;
            dest_width  = Width;
            dest_height = Height;

            // these are the 3 source movement offsets
            var x1 = (int)((dest_width / 2) * Math.Cos(angle) + dest_width / 2);
            var y1 = (int)((dest_height / 2) * Math.Sin(1.7 * angle) + dest_height / 2);
            var x2 = (int)((dest_width / 2) * Math.Cos(1.5 * angle + 1) + dest_width / 2);
            var y2 = (int)((dest_height / 2) * Math.Sin(0.5 * angle + 1) + dest_height / 2);
            var x3 = (int)((dest_width / 2) * Math.Cos(angle) + dest_width / 2);
            var y3 = (int)((dest_height / 2) * Math.Sin(angle) + dest_height / 2);

            angle += 0.05; // increment for next pass


            for (var ypos = 0; ypos < dest_height; ypos++)
            {
                // find start offsets mod src_width for parallax effect to get waves
                var offset1 = (int)(src_width + src_width / 8 * Math.Sin(angle + 4.0 * ypos / dest_height)) % src_width;
                var offset2 = (int)(src_width + src_width / 8 * Math.Sin(1.2 * angle + 3.5 * ypos / dest_height)) % src_width;
                var offset3 = (int)(src_width + src_width / 8 * Math.Sin(-angle + 2.7 * ypos / dest_height)) % src_width;

                // start for source
                var p1x = x1 + offset1; // new locations, utilizing the parallax effects
                var p2x = x2 + offset2;
                var p3x = x3 + offset3;
                var p1y = y1;
                var p2y = y2;
                var p3y = y3;

                for (var xpos = 0; xpos < dest_width; xpos++)
                {
                    int r1, g1, b1, r2, g2, b2, r3, g3, b3;
                    img1.GetPixel(p1x % src_width, p1y % src_height, out r1, out g1, out b1);
                    img2.GetPixel(p2x % src_width, p2y % src_height, out r2, out g2, out b2);
                    img3.GetPixel(p3x % src_width, p3y % src_height, out r3, out g3, out b3);
                    SetPixel(xpos, ypos, r1 | r2 | r3, g1 | g2 | g3, b1 | b2 | b3);
                    p1x++;
                    p2x++;
                    p3x++;
                }
                y1++; // next line
                y2++; // next line
                y3++; // next line
            }
        }
Exemple #3
0
        private void MakeBackground()
        {
            sw = new Surface(Width, Height);

            sw.Fill(0, 0, 128);

            var top    = new Vector3D(0, 0, 64);
            var bottom = new Vector3D(64, 64, 255);

            // gradient
            for (var j = 0; j < Height; j++)
            {
                var a     = (double)j / Height;
                var color = bottom * a + top * (1 - a);
                var r     = (int)color.X;
                var g     = (int)color.Y;
                var b     = (int)color.Z;
                sw.DrawLine(0, j, Width - 1, j, r, g, b);
            }

#if false
            var font = new FontController();

            int curPos = 0;

            var xpos = curPos;
            var ypos = Height / 2 - font.Font.LineHeight / 2;
            var gap  = (Height - font.Font.LineHeight) * 0.4;

            font.Render(ref xpos, ref ypos, "Hypnocube!",
                        Width, Height,
                        (i, j, r, g, b, a) =>
            {
                if (a != 0)
                {
                    i += 5;
                    int r1, g1, b1;
                    var j2 = (int)(j + Math.Sin(frame / 8.0 + i * 9.0 / Width) * gap);
                    sw.GetPixel(i, j2, out r1, out g1, out b1);

                    //j2 = j;
                    r1 = a * r / 255 + (255 - a) * r1 / 255;
                    g1 = a * g / 255 + (255 - a) * g1 / 255;
                    b1 = a * b / 255 + (255 - a) * b1 / 255;
                    sw.SetPixel(i, j2, r1, g1, b1);
                }
            }
                        );
#endif

            // checkerboard
            //for (var i = 0; i < Width; ++i)
            //    for (var j = 0; j < Height; ++j)
            //    {
            //        var c = (j/16 + i/16) & 1;
            //        int r, g, b;
            //        r = g = b = 255;
            //        if (c==1)
            //            r = g = 0;
            //        sw.SetPixel(i, j, r, g, b);
            //    }
        }
Exemple #4
0
        public override void Update()
        {
            base.Update();

            if (buffer1 == null || buffer2 == null)
            {
                buffer1 = new int[Width + 2 * Border, Height + 2 * Border];
                buffer2 = new int[Width + 2 * Border, Height + 2 * Border];
                MakeBackground();
            }


            var damping = 0.80;

            // update water from bufer 1 to buffer 2
            for (var i = 1; i < buffer1.GetLength(0) - 1; ++i)
            {
                for (var j = 1; j < buffer1.GetLength(1) - 1; ++j)
                {
                    buffer2[i, j] = (buffer1[i - 1, j] + buffer1[i + 1, j] + buffer1[i, j + 1] + buffer1[i, j - 1]) / 2 -
                                    buffer2[i, j];
                    buffer2[i, j] = (int)(buffer2[i, j] * damping);
                }
            }

            // swap buffers
            var temp = buffer1;

            buffer1 = buffer2;
            buffer2 = temp;


            // draw buffer1
            for (var i = Border; i < Width + Border; ++i)
            {
                for (var j = Border; j < Height + Border; ++j)
                {
                    int r, g, b;

                    var xOffset = buffer1[i - 1, j] - buffer1[i + 1, j];
                    var yOffset = buffer1[i, j - 1] - buffer1[i, j + 1];
                    var shade   = xOffset;

                    // texture - get from image using i+xoffset, j+yoffset
                    sw.GetPixel(i - Border + xOffset / 3, j - Border + yOffset / 3, out r, out g, out b);

                    // add shading
                    // (r,g,b)+=shading;

                    r = Math.Max(Math.Min(r + shade, 255), 0);
                    g = Math.Max(Math.Min(g + shade, 255), 0);
                    b = Math.Max(Math.Min(b + shade, 255), 0);

                    SetPixel(i - Border, j - Border, r, g, b);
                }
            }

            // lissajous drops
            for (var p = 0; p < 7; ++p)
            {
                var t  = Frame / 50.0 + 2 * Math.PI * p / 7;
                var x1 = 1.0 * Math.Sin(1 * t + 0);
                var y1 = 1.0 * Math.Sin(4 * t + 0);

                var x = (int)(x1 * Width / 2 + Width / 2);
                var y = (int)(y1 * Height / 2 + Height / 2);
                if (0 <= x && 0 <= y && x < Width && y < Height)
                {
                    var mx = Math.Min(Width, Height);
                    buffer1[x, y] = 2 * mx + 2 * mx;
                }
            }

            if (Rand.NextDouble() < 0.6)
            {
                // add random drop
                var x = Rand.Next(Width);
                var y = Rand.Next(Height);

                var mx = Math.Min(Width, Height);
                buffer1[x, y] = Rand.Next(2 * mx) + 2 * mx;
            }
        }