コード例 #1
0
ファイル: ColorModule.cs プロジェクト: randomcrab/SEParticles
        public static ColorModule Curve(Curve4 curve)
        {
            ColorModule module = new ColorModule();

            module.SetCurve(curve.X, curve.Y, curve.Z, curve.W);
            return(module);
        }
コード例 #2
0
        public static void Subdivide(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, List <Vector3> points, float tolerance = 0.0001f, int recursionLimit = 32)
        {
            points.Clear();
            Stack <Curve4> stack = new Stack <Curve4>(recursionLimit * 2 + 1);

            stack.Push(new Curve4(p0, p1, p2, p3));
            while (stack.Count > 0)
            {
                Curve4  curve   = stack.Pop();
                Vector3 vector  = (curve.p0 + curve.p1) * 0.5f;
                Vector3 vector2 = (curve.p1 + curve.p2) * 0.5f;
                Vector3 vector3 = (curve.p2 + curve.p3) * 0.5f;
                Vector3 vector4 = (vector + vector2) * 0.5f;
                Vector3 vector5 = (vector2 + vector3) * 0.5f;
                Vector3 vector6 = (vector4 + vector5) * 0.5f;
                Vector3 vector7 = curve.p0 + curve.p2 - curve.p1 - curve.p1;
                Vector3 vector8 = curve.p1 + curve.p3 - curve.p2 - curve.p2;
                if (vector7.sqrMagnitude + vector8.sqrMagnitude < tolerance)
                {
                    points.Add(vector6);
                }
                else if (recursionLimit > 0)
                {
                    stack.Push(new Curve4(curve.p0, vector, vector4, vector6));
                    stack.Push(new Curve4(vector6, vector5, vector3, curve.p3));
                    recursionLimit--;
                }
            }
        }
コード例 #3
0
 public CurveConverter(IVertexSource source)
 {
     m_curve3 = new Curve3();
     m_curve4 = new Curve4();
     m_source = (source);
     m_last_x = (0.0);
     m_last_y = (0.0);
 }
コード例 #4
0
 public CurveConverter(IVertexSource source)
 {
     m_curve3 = new Curve3();
     m_curve4 = new Curve4();
     m_source=(source);
     m_last_x=(0.0);
     m_last_y=(0.0);
 }
コード例 #5
0
        internal static NativeCurve4 *CopyCurve4ToNativeCurve4(Curve4 managedCurve)
        {
            NativeCurve *x = CopyCurveToNativeCurve(managedCurve.X);
            NativeCurve *y = CopyCurveToNativeCurve(managedCurve.Y);
            NativeCurve *z = CopyCurveToNativeCurve(managedCurve.Z);
            NativeCurve *w = CopyCurveToNativeCurve(managedCurve.W);

            return(util_Curve4_Ctor(x, y, z, w));
        }
コード例 #6
0
        static Msdfgen.Shape CreateMsdfShape(List <Contour> contours)
        {
            var shape = new Msdfgen.Shape();
            int j     = contours.Count;

            for (int i = 0; i < j; ++i)
            {
                var cnt = new Msdfgen.Contour();
                shape.contours.Add(cnt);

                Contour            contour = contours[i];
                List <ContourPart> parts   = contour.parts;
                int m = parts.Count;
                for (int n = 0; n < m; ++n)
                {
                    ContourPart p = parts[n];
                    switch (p.Kind)
                    {
                    default: throw new NotSupportedException();

                    case PartKind.Curve3:
                    {
                        Curve3 curve3 = (Curve3)p;
                        cnt.AddQuadraticSegment(
                            curve3.FirstPoint.X, curve3.FirstPoint.Y,
                            curve3.x1, curve3.y1,
                            curve3.x2, curve3.y2
                            );
                    }
                    break;

                    case PartKind.Curve4:
                    {
                        Curve4 curve4 = (Curve4)p;
                        cnt.AddCubicSegment(
                            curve4.FirstPoint.X, curve4.FirstPoint.Y,
                            curve4.x1, curve4.y1,
                            curve4.x2, curve4.y2,
                            curve4.x3, curve4.y3);
                    }
                    break;

                    case PartKind.Line:
                    {
                        Line line = (Line)p;
                        cnt.AddLine(
                            line.FirstPoint.X, line.FirstPoint.Y,
                            line.x1, line.y1);
                    }
                    break;
                    }
                }
            }
            return(shape);
        }
コード例 #7
0
 /// <summary>
 /// create lines from curve
 /// </summary>
 /// <param name="curve"></param>
 /// <param name="vxs"></param>
 /// <param name="x1"></param>
 /// <param name="y1"></param>
 /// <param name="p2x"></param>
 /// <param name="p2y"></param>
 /// <param name="p3x"></param>
 /// <param name="p3y"></param>
 /// <param name="x2"></param>
 /// <param name="y2"></param>
 public static void MakeLines(this Curve4 curve, VertexStore vxs, double x1, double y1,
                              double p2x, double p2y,
                              double p3x, double p3y,
                              double x2, double y2)
 {
     CreateBezierVxs4(vxs,
                      x1, y1,
                      p2x, p2y,
                      p3x, p3y,
                      x2, y2);
 }
コード例 #8
0
 public static void MakeLines(this Curve4 curve, VertexStore vxs, double x1, double y1,
                              double p2x, double p2y,
                              double p3x, double p3y,
                              double x2, double y2)
 {
     CreateBezierVxs4(vxs,
                      new PixelFarm.VectorMath.Vector2(x1, y1),
                      new PixelFarm.VectorMath.Vector2(x2, y2),
                      new PixelFarm.VectorMath.Vector2(p2x, p2y),
                      new PixelFarm.VectorMath.Vector2(p3x, p3y));
 }
コード例 #9
0
        static Contour CreateFitContour(Contour contour, float pixelScale, bool x_axis, bool y_axis)
        {
            Contour            newc  = new Contour();
            List <ContourPart> parts = contour.parts;
            int m = parts.Count;

            for (int n = 0; n < m; ++n)
            {
                ContourPart p = parts[n];
                switch (p.Kind)
                {
                default: throw new NotSupportedException();

                case PartKind.Curve3:
                {
                    Curve3 curve3 = (Curve3)p;
                    newc.AddPart(new Curve3(
                                     curve3.FirstPoint.X * pixelScale, curve3.FirstPoint.Y * pixelScale,
                                     curve3.x1 * pixelScale, curve3.y1 * pixelScale,
                                     curve3.x2 * pixelScale, curve3.y2 * pixelScale));
                }
                break;

                case PartKind.Curve4:
                {
                    Curve4 curve4 = (Curve4)p;
                    newc.AddPart(new Curve4(
                                     curve4.FirstPoint.X * pixelScale, curve4.FirstPoint.Y * pixelScale,
                                     curve4.x1 * pixelScale, curve4.y1 * pixelScale,
                                     curve4.x2 * pixelScale, curve4.y2 * pixelScale,
                                     curve4.x3 * pixelScale, curve4.y3 * pixelScale
                                     ));
                }
                break;

                case PartKind.Line:
                {
                    Line line = (Line)p;
                    newc.AddPart(new Line(
                                     line.FirstPoint.X * pixelScale, line.FirstPoint.Y * pixelScale,
                                     line.x1 * pixelScale, line.y1 * pixelScale
                                     ));
                }
                break;
                }
            }
            return(newc);
        }
コード例 #10
0
ファイル: ParticleSystem.cs プロジェクト: randomcrab/SE
        protected override void OnInitialize()
        {
            //Emitter = new Emitter(shape: new CircleEmitterShape(64.0f, EmissionDirection.Out, true, true, 0.5f));

            CircleEmitterShape    circleShape    = new CircleEmitterShape(32.0f, EmissionDirection.Out, false, false);
            RectangleEmitterShape rectangleShape = new RectangleEmitterShape(
                new Vector2(128.0f, 128.0f),
                EmissionDirection.Out,
                true,
                true);

            Emitter         = new Emitter(4096, shape: circleShape);
            Emitter.Texture = Texture;
            //Emitter.Space = Space.Local;

            Curve angleCurve = new Curve();

            angleCurve.Keys.Add(0.0f, 0.0f);
            angleCurve.Keys.Add(0.25f, 0.1f);
            angleCurve.Keys.Add(0.5f, 1.0f);
            angleCurve.Keys.Add(1.0f, 10.0f);

            Curve forwardVelocityCurve = new Curve();

            forwardVelocityCurve.Keys.Add(0.0f, 0.0f);
            forwardVelocityCurve.Keys.Add(0.20f, 128.0f);
            forwardVelocityCurve.Keys.Add(0.5f, 512.0f);
            forwardVelocityCurve.Keys.Add(1.0f, 3000.0f);

            Curve4 colorCurve = new Curve4();

            colorCurve.Add(0.0f, new Vector4(0.0f, 1.0f, 0.5f, 1.0f));
            colorCurve.Add(0.25f, new Vector4(30.0f, 1.0f, 0.5f, 1.0f));
            colorCurve.Add(0.5f, new Vector4(120.0f, 1.0f, 0.5f, 1.0f));
            colorCurve.Add(0.8f, new Vector4(30.0f, 1.0f, 0.5f, 1.0f));
            colorCurve.Add(1.0f, new Vector4(240.0f, 1.0f, 0.5f, 0.0f));

            //Emitter.Config.Color.SetNormal(new Vector4(300.0f, 1.0f, 0.5f, 1.0f));

            Emitter.Config.Color.SetRandomBetween(
                new Vector4(0.0f, 1.0f, 0.5f, 0.0f),
                new Vector4(30.0f, 1.0f, 0.6f, 0.0f));

            //Emitter.Config.Color.SetNormal(new Vector4(0f, 1.0f, 0.5f, 1.0f));

            Emitter.Config.Scale.SetRandomBetween(0.0333f, 0.0667f);
            Emitter.Config.Life.SetRandomBetween(0.2f, 1.0f);
            Emitter.Config.Speed.SetRandomBetween(32.0f, 128.0f);
            Emitter.Config.Speed.SetNormal(256.0f);

            ScaleModule s = ScaleModule.Lerp(0.5f, 2.0f);

            //Emitter.AddModule(RotationModule.RandomCurve(angleCurve));
            //Emitter.AddModule(SpeedModule.Lerp(64.0f, 512.0f));
            Emitter.AddModule(s);
            Emitter.AddModule(TextureAnimationModule.OverLifetime(5, 5));
            //Emitter.AddModule(AttractorModule.Basic(new Vector2(512.0f, 512.0f), 64.0f, 1024.0f, 10, 8.0f));

            //ColorModule baseColorModule = ColorModule.RandomLerp(
            //    new Vector4(0f, 1.0f, 0.5f, 0.0f),
            //    new Vector4(360f, 1.0f, 0.5f, 0.0f));

            //Emitter.AddModule(baseColorModule);
            //Emitter.AddModule(baseColorModule);

            Curve alphaCurve = new Curve();

            alphaCurve.Keys.Add(0.0f, 0.0f);
            alphaCurve.Keys.Add(0.1f, 1.0f);
            alphaCurve.Keys.Add(0.667f, 1.0f);
            alphaCurve.Keys.Add(1.0f, 0.0f);

            Emitter.AddModule(HueModule.RandomLerp(0.0f, 30.0f));
            Emitter.AddModule(LightnessModule.Lerp(0.667f));
            Emitter.AddModule(AlphaModule.Curve(alphaCurve));

            //Emitter.RemoveModules(s, baseColorModule);

            //Emitter.Enabled = true;
        }
コード例 #11
0
 public void SetRandomCurve(Curve4 curve)
 {
     Curve          = curve;
     StartValueType = StartingValue.RandomCurve;
 }
コード例 #12
0
        static unsafe void Main(String[] args)
        {
            rng = new Random(123);

            // Allocate the framebuffer
            byte[] buf = new byte[width * height * 3];

            // Create the rendering buffer
            RenderingBuffer rbuf = new RenderingBuffer(buf, width, height, width * 3);

            // Create the renderer and the rasterizer
            Renderer   ren = new Renderer(rbuf, new SpanBgr24());
            Rasterizer ras = new Rasterizer();

            // Setup the rasterizer
            ras.SetGamma(1.3);
            ras.FillRule = FillingRule.FillNonZero;

            ren.Clear(new Color(255, 255, 255));
#if !TEST_CURVE
            double  pieceWidth  = 0.59 * width / 2;
            double  pieceHeight = 0.59 * height / 2;
            double  ox          = rbuf.Width / 4;
            double  oy          = rbuf.Height / 3;
            double  cx          = rbuf.Width / 2;
            double  cy          = rbuf.Height / 2;
            Point[] cpts        = new Point[] {
                new Point(-1, 0),
                new Point(1 - 1.0 / 8, 1.0 / 3),
                new Point(-1, -1.0 / 3),
                new Point(0, -1.0 / 3),

                new Point(0, -1.0 / 3),
                new Point(1, -1.0 / 3),
                new Point(-1 + 1.0 / 8, 1.0 / 3),
                new Point(1, 0),

                Point.Empty, Point.Empty, Point.Empty, Point.Empty,
                Point.Empty, Point.Empty, Point.Empty, Point.Empty,

                Point.Empty, Point.Empty, Point.Empty, Point.Empty,
                Point.Empty, Point.Empty, Point.Empty, Point.Empty,
            };

            int             ci2 = 8;
            int             ci3 = 16;
            double          x;
            double          y;
            AffineTransform trans =
                AffineTransform.CreateScale(1, 1.5) *
                AffineTransform.CreateTranslation(0, -1);
            AffineTransform rot =
                AffineTransform.CreateTranslation(0, -1) *
                AffineTransform.CreateScale(-1, 1) *
                AffineTransform.CreateRotation(-Math.PI / 2);
            AffineTransform rot2 =
                AffineTransform.CreateScale(1, 1.5) *
                AffineTransform.CreateTranslation(0, 1) *
                AffineTransform.CreateScale(1, -1) *
                AffineTransform.CreateRotation(-Math.PI);
            for (int ci = 0; ci < ci2; ci++)
            {
                double sx = cpts[ci].X;
                double sy = cpts[ci].Y;
                x = sx;
                y = sy;
                trans.Transform(ref x, ref y);
                cpts[ci].X = x;
                cpts[ci].Y = y;

                x = sx;
                y = sy;
                rot.Transform(ref x, ref y);
                cpts[ci2 + ci].X = x;
                cpts[ci2 + ci].Y = y;

                x = sx;
                y = sy;
                rot2.Transform(ref x, ref y);
                cpts[ci3 + ci].X = x;
                cpts[ci3 + ci].Y = y;
            }

            trans = new AffineTransform(
                pieceWidth, 0,
                0, pieceHeight,
                rbuf.Width / 2, rbuf.Height / 2);
            for (int ci = 0; ci < cpts.Length; ci++)
            {
                x = cpts[ci].X;
                y = cpts[ci].Y;
                trans.Transform(ref x, ref y);
                cpts[ci].X = x;
                cpts[ci].Y = y;
            }

            Curve4 curve = new Curve4();
            curve.ApproximationMethod = CurveApproximationMethod.Incremental;

            PathCommand cmd;
            for (int ci = 0; ci < cpts.Length; ci += 4)
            {
                curve.Initialize(
                    cpts[ci + 0].X, cpts[ci + 0].Y,
                    cpts[ci + 1].X, cpts[ci + 1].Y,
                    cpts[ci + 2].X, cpts[ci + 2].Y,
                    cpts[ci + 3].X, cpts[ci + 3].Y);

                do
                {
                    cmd = curve.GetVertex(out x, out y);
                    if (ci == 0 && cmd == PathCommand.MoveTo)
                    {
                        ras.MoveToD(x, y);
                    }
                    else if (cmd == PathCommand.LineTo)
                    {
                        ras.LineToD(x, y);
                    }
                } while (cmd != PathCommand.Stop);
            }

            ras.Render(ren, Color.Red);

            for (int i = 1; i < 4; i++)
            {
                draw_line(ras, cpts[i - 1].X, cpts[i - 1].Y, cpts[i].X, cpts[i].Y, 1.0);
                ras.Render(ren, Color.Gray);

                int j = ci2 + i;
                draw_line(ras, cpts[j - 1].X, cpts[j - 1].Y, cpts[j].X, cpts[j].Y, 1.0);
                ras.Render(ren, Color.Gray);

                j = ci3 + i;
                draw_line(ras, cpts[j - 1].X, cpts[j - 1].Y, cpts[j].X, cpts[j].Y, 1.0);
                ras.Render(ren, Color.Gray);
            }
#endif
#if HIDE
            int i;

            // Draw random polygons
            for (i = 0; i < 10; i++)
            {
                int n = rng.Next() % 6 + 3;

                // Make the polygon. One can call move_to() more than once.
                // In this case the rasterizer behaves like Win32 API PolyPolygon().
                ras.MoveToD(random(-30, rbuf.Width + 30), random(-30, rbuf.Height + 30));

                for (int j = 1; j < n; j++)
                {
                    ras.LineToD(random(-30, rbuf.Width + 30), random(-30, rbuf.Height + 30));
                }

                // Render
                ras.Render(ren, new Color((byte)(rng.Next() & 0xFF), (byte)(rng.Next() & 0xFF), (byte)(rng.Next() & 0xFF), (byte)((rng.Next() & 0x7F) + 100)));
            }

            // Draw random ellipses
            for (i = 0; i < 50; i++)
            {
                draw_ellipse(ras,
                             random(-30, rbuf.Width + 30),
                             random(-30, rbuf.Height + 30),
                             random(3, 50),
                             random(3, 50));
                ras.Render(ren, new Color((byte)(rng.Next() & 0x7F), (byte)(rng.Next() & 0x7F), (byte)(rng.Next() & 0x7F), (byte)((rng.Next() & 0x7F) + 100)));
            }

            // Draw random straight lines
            for (i = 0; i < 20; i++)
            {
                draw_line(ras,
                          random(-30, rbuf.Width + 30),
                          random(-30, rbuf.Height + 30),
                          random(-30, rbuf.Width + 30),
                          random(-30, rbuf.Height + 30),
                          random(0.1, 10));

                ras.Render(ren, new Color((byte)(rng.Next() & 0x7F), (byte)(rng.Next() & 0x7F), (byte)(rng.Next() & 0x7F), (byte)(rng.Next() & 0x7F)));
            }
#endif
            System.Drawing.Rectangle rc  = new System.Drawing.Rectangle(0, 0, (int)rbuf.Width, (int)rbuf.Height);
            System.Drawing.Bitmap    bmp = new System.Drawing.Bitmap(rc.Width, rc.Height, PixelFormat.Format24bppRgb);
            BitmapData bmpData           = bmp.LockBits(
                rc,
                System.Drawing.Imaging.ImageLockMode.WriteOnly,
                bmp.PixelFormat);

            IntPtr p     = bmpData.Scan0;
            int    bytes = bmpData.Stride * bmp.Height;
            System.Runtime.InteropServices.Marshal.Copy(buf, 0, p, bytes);

            bmp.UnlockBits(bmpData);
            bmp.Save("agg_test.bmp");
#if PPM
            // Write a .ppm file
            String hdr    = String.Format("P6\n{0} {1}\n255\n", rbuf.width(), rbuf.height());
            byte[] hdrBuf = ASCIIEncoding.ASCII.GetBytes(hdr);
            using (FileStream strm = new FileStream("agg_test.ppm", FileMode.Create))
            {
                strm.Write(hdrBuf, 0, hdrBuf.Length);
                strm.Write(buf, 0, (int)(rbuf.width() * rbuf.height() * 3));
            }
#endif
        }