Esempio n. 1
0
        private void DoTest(TestCase test)
        {
            var canvas = new Canvas();
            canvas.Width = 300;
            canvas.Height = 700;
            ICanvasRenderingContext2D ctx = new CanvasRenderingContext2D(canvas, this, true);
            string url = test(ctx);
            ctx.commit();
            string location = Application.ResourceAssembly.Location;
            string path = location.Remove(location.LastIndexOf("\\"));

            var di = new DirectoryInfo(path);
            url = di.Parent.Parent.Parent.FullName + "\\SharpCanvas.Tests\\" + url;
            if (File.Exists(url))
            {
                pctOriginal.Source = new BitmapImage(new Uri(url));
                pctOriginal.Visibility = Visibility.Visible;
            }
            else
            {
                pctOriginal.Visibility = Visibility.Hidden;
            }
            ctResults.Children.Clear();
            ctResults.Children.Add(canvas);
        }
Esempio n. 2
0
        public void flyMe(CanvasRenderingContext2D ctx, int i)
        {
            container.Children.Clear();

            ctx.save();
            ctx.translate(0, Math.Cos(i*0.1)*40);

            double a = Math.Sin(i*0.1);

            // right wing
            ctx.save();
            ctx.rotate(Math.PI*0.4);
            wing(ctx, 8, a);

            ctx.commit();

            ctx.restore();

            // left wing
            ctx._path.GetNumberOfCommits();
            ctx._path.GetNumberOfPaths();

            ctx.save();
            ctx.scale(-1, 1);
            ctx.rotate(Math.PI*0.4);
            wing(ctx, 8, a);

            ctx.commit();

            ctx.restore();

            Debugger.Log(0, "Timing", "Left wing, Commits:" + ctx._path.GetNumberOfCommits());
            Debugger.Log(0, "Timing", "Left wing, Paths:" + ctx._path.GetNumberOfPaths());

            // tail
            ctx.save();
            tail(ctx, 10, Math.Sin(i*0.05));
            ctx.commit();
            ctx.restore();

            // head
            neck(ctx, 12);
            ctx.commit();
            ctx.restore();
        }
Esempio n. 3
0
 public FlyingDragon(HTMLElement container)
 {
     this.container = container;
     _ctx = new CanvasRenderingContext2D(container, this, true);
     _ctx.translate(280, 200);
 }
Esempio n. 4
0
 private void wing(CanvasRenderingContext2D ctx, double r, double a)
 {
     if (r < 2.9) return;
     fillCircle(ctx, r);
     branch(ctx, r, 0.9561, 0.03*Math.PI, a);
     ctx.save();
     ctx.rotate(0.55*Math.PI);
     feather(ctx, 0.8*r);
     ctx.restore();
 }
Esempio n. 5
0
 private void tail(CanvasRenderingContext2D ctx, double s, double a)
 {
     if (s < 0.5) return;
     double d = 0.98; // decay
     fillCircle(ctx, s);
     ctx.rotate(-0.15*a);
     ctx.translate(0, s*(1 + d));
     tail(ctx, s*d, a);
 }
Esempio n. 6
0
        private void neck(CanvasRenderingContext2D ctx, double s)
        {
            if (s < 10)
            {
                head(ctx);
                return;
            }

            double d = 0.85;
            fillCircle(ctx, s);

            ctx.save();
            ctx.rotate(-Math.PI/2);
            ctx.translate(0, s);
            fillCircle(ctx, s/2);
            ctx.restore();

            ctx.rotate(-0.15);
            ctx.translate(0, -s*(1 + d));
            neck(ctx, s*d);
        }
Esempio n. 7
0
        private void head(CanvasRenderingContext2D ctx)
        {
            fillCircle(ctx, 22);

            // mouth
            ctx.save();
            ctx.translate(-15, -3);
            //ctx.beginPath();
            ctx.fillStyle = "white";
            ctx.arc(0, 0, 10, 0, Math.PI*2, true);
            ctx.fill();
            ctx.restore();

            // eye
            ctx.translate(9, -4);
            //ctx.beginPath();
            ctx.fillStyle = "black";
            ctx.arc(0, 0, 5, 0, Math.PI*2, true);
            ctx.fill();

            // horn
            ctx.translate(6, -8);
            ctx.rotate(0.6*Math.PI);
            wing(ctx, 5.5, 1.8);
        }
Esempio n. 8
0
 private void fillCircle(CanvasRenderingContext2D ctx, double r)
 {
     //ctx.beginPath();
     ctx.moveTo(r, 0);
     ctx.fillStyle = "rgb(245,50,50)";
     ctx.arc(0, 0, r, 0, Math.PI*2, true);
     ctx.fill();
 }
Esempio n. 9
0
 private void feather(CanvasRenderingContext2D ctx, double r)
 {
     if (r < 3) return;
     double d = 0.85;
     ctx.rotate(-0.03*Math.PI);
     ctx.translate(0, -r*(1 + d));
     fillCircle(ctx, r);
     feather(ctx, r*d);
 }
Esempio n. 10
0
 private void branch(CanvasRenderingContext2D ctx, double r, double d, double t, double a)
 {
     ctx.save();
     ctx.rotate(t*a);
     ctx.translate(0, -r*(1 + d));
     wing(ctx, r*d, a);
     ctx.restore();
 }