public ApplicationCanvas() { //r.Fill = Brushes.Red; //r.AttachTo(this); //r.MoveTo(8, 8); //this.SizeChanged += (s, e) => r.SizeTo(this.Width - 16.0, this.Height - 16.0); var Scene = new Canvas().AttachTo(this); this.SizeChanged += (s, e) => Scene.MoveTo(this.Width / 2, this.Height / 2); var EgoSpeed = 0.5; var EgoPosition = 0.0; { var ego = new ski1(); ego.AttachTo(Scene); (1000 / 60).AtIntervalWithCounter( c => { EgoPosition += EgoSpeed; ego.MoveTo(0, (EgoPosition) % this.Height - this.Height / 2); } ); } Action<double, double> tree = (x, y) => new ski51().AttachTo(Scene).MoveTo(x, y); Action<double, double> deadtree = (x, y) => new ski50().AttachTo(Scene).MoveTo(x, y); Action<double, double> stone = (x, y) => new ski45().AttachTo(Scene).MoveTo(x, y); Action<double, double> stonefield = (x, y) => new ski27().AttachTo(Scene).MoveTo(x, y); tree(-64, 32); tree(64, 32); tree(-64, -32); tree(64, -32); var logo = new Avalon.Images.jsc().AttachTo(this); this.RotateScene = a => { Scene.RenderTransform = new RotateTransform(a); }; RotateScene(12); this.Accelerate = (ax, ay, az) => { Scene.RenderTransform = new RotateTransform(ax * 90); EgoSpeed = (1 - az) * 2; }; }
public MouseMazeCanvas() { Width = DefaultWidth; Height = DefaultHeight; #region Gradient for (int i = 0; i < DefaultHeight; i += 4) { new Rectangle { Fill = ((uint)(0xff00007F + (int)(128 * i / DefaultHeight))).ToSolidColorBrush(), Width = DefaultWidth, Height = 4, }.MoveTo(0, i).AttachTo(this); } #endregion var img = new Avalon.Images.jsc { }.MoveTo(DefaultWidth - 128, DefaultHeight - 128).AttachTo(this); var mouse = new Avalon.Images.mouse { }.MoveTo(0, 0).AttachTo(this); var container = new Canvas { Width = DefaultWidth, Height = DefaultHeight }.AttachTo(this); var mousehollow = new Avalon.Images.mouse_hollow { }.MoveTo(0, 0).AttachTo(this); var canvasdrawing = new Canvas { Width = DefaultWidth, Height = DefaultHeight }.AttachTo(container); InitializeCanvasDrawing(canvasdrawing); var canvas = new Rectangle { Fill = Brushes.Red, Width = DefaultWidth, Height = DefaultHeight, Opacity = 0 }.MoveTo(0, 0).AttachTo(this); canvas.MouseLeftButtonUp += delegate { canvasdrawing.Visibility = Visibility.Hidden; canvasdrawing = new Canvas { Width = DefaultWidth, Height = DefaultHeight }.AttachTo(container); maze = new MazeGenerator(maze.Width, maze.Height, null); InitializeCanvasDrawing(canvasdrawing); }; this.Cursor = Cursors.None; canvas.MouseEnter += delegate { mouse.Visibility = Visibility.Visible; }; canvas.MouseLeave += delegate { mouse.Visibility = Visibility.Hidden; }; canvas.MouseMove += (s, ev) => { var p = ev.GetPosition(canvas); mouse.MoveTo(p.X - 8, p.Y - 8); mousehollow.MoveTo(p.X - 8, p.Y - 8); }; }
void InitializeContent() { //new[] { // Colors.Black, // Colors.Blue, // Colors.Black //}.ToGradient(Convert.ToInt32( Height) / 2).Select( // (c, i) => // new Rectangle // { // Fill = new SolidColorBrush(c), // Width = Width, // Height = 3, // }.MoveTo(0, i * 2).AttachTo(this) //).ToArray(); //var help = new Image //{ // Source = (KnownAssets.Path.Assets + "/help.png").ToSource() //}.AttachTo(this); //help.Opacity = 0; var img = new Avalon.Images.jsc().MoveTo(Width - 128, Height - 128).AttachTo(this); var t = new TextBox { FontSize = 10, Text = "powered by jsc", BorderThickness = new Thickness(0), Foreground = 0xffffffff.ToSolidColorBrush(), Background = Brushes.Transparent, IsReadOnly = true, Width = Width }.MoveTo(8, 8).AttachTo(this); AffineContent = new Canvas { }.AttachTo(this); InfoContent = new Canvas { }.AttachTo(this); var a = new AffineMesh(); // front AddCubeFace(a, "front", new AffinePoint(-100, -100, 100), new AffinePoint(100, -100, 100), new AffinePoint(-100, 100, 100), new AffinePoint(100, 100, 100) ); // right AddCubeFace(a, "right", new AffinePoint(100, -100, 100), new AffinePoint(100, -100, -100), new AffinePoint(100, 100, 100), new AffinePoint(100, 100, -100) ); // left AddCubeFace(a, "left", new AffinePoint(-100, -100, 100), new AffinePoint(-100, -100, -100), new AffinePoint(-100, 100, 100), new AffinePoint(-100, 100, -100) ); // back AddCubeFace(a, "back", new AffinePoint(-100, -100, -100), new AffinePoint(100, -100, -100), new AffinePoint(-100, 100, -100), new AffinePoint(100, 100, -100) ); // top AddCubeFace(a, "top", new AffinePoint(-100, 100, -100), new AffinePoint(100, 100, -100), new AffinePoint(-100, 100, 100), new AffinePoint(100, 100, 100) ); // bottom AddCubeFace(a, "bottom", new AffinePoint(-100, -100, -100), new AffinePoint(100, -100, -100), new AffinePoint(-100, -100, 100), new AffinePoint(100, -100, 100) ); // AddCubeFace(a, "back", // new AffinePoint(-100, -100, -100), // new AffinePoint(100, -100, -100), // new AffinePoint(-100, 100, -100), // new AffinePoint(100, 100, -100) //); //a = a.ToZoom(new AffineZoom { X = 2 }); //a = a.ToZoom(0.8); //a = a.ToZoom(1.2); var pp_X = 0.0; var pp = new Point(Width / 2, Height / 2); Action Update = () => { var Rotation = new AffineRotation { XY = 0.01 * pp.X * 0.5, YZ = 0.02 * pp.X * 0.5, XZ = 0.03 * pp.X * 0.5 + pp_X }; t.Text = new { XY = Rotation.XZ.RadiansToDegrees(), YZ = Rotation.YZ.RadiansToDegrees(), XZ = Rotation.XZ.RadiansToDegrees() }.ToString(); // rotate floor var _a = a.ToZoom((Height / 2 + pp.Y) / (Height)).ToRotation(Rotation); foreach (var k in _a.Vertecies) { k.Element.Orphanize(); k.Element.AttachTo(AffineContent); k.Element.RenderTransform = new AffineTransform { Left = 0, Top = 0, Width = k.ElementWidth, Height = k.ElementHeight, X1 = k.B.X + Width / 2, Y1 = k.B.Y + Height / 2, X2 = k.C.X + Width / 2, Y2 = k.C.Y + Height / 2, X3 = k.A.X + Width / 2, Y3 = k.A.Y + Height / 2, }; //((Action<AffineVertex>)k.Tag)(k); } }; this.MouseMove += (sender, args) => { pp = args.GetPosition(this); Update(); }; var tt = new DispatcherTimer(); tt.Tick += delegate { pp_X += 0.02; Update(); }; tt.Interval = TimeSpan.FromMilliseconds(1000 / 30); tt.Start(); }
public ApplicationCanvas() { Width = DefaultWidth; Height = DefaultHeight; //this.ClipToBounds = true; Colors.Blue.ToGradient(Colors.Red, DefaultHeight / 4).Select( (c, i) => new Rectangle { Fill = new SolidColorBrush(c), Width = DefaultWidth, Height = 4, }.MoveTo(0, i * 4).AttachTo(this) ).ToArray(); //var help = new Image //{ // Source = (KnownAssets.Path.Assets + "/help.png").ToSource() //}.AttachTo(this); //help.Opacity = 0; var img = new Avalon.Images.jsc().MoveTo(DefaultWidth - 128, DefaultHeight - 128).AttachTo(this); var t = new TextBox { FontSize = 10, Text = "powered by jsc", BorderThickness = new Thickness(0), Foreground = 0xffffffff.ToSolidColorBrush(), Background = Brushes.Transparent, IsReadOnly = true, Width = DefaultWidth }.MoveTo(8, 8).AttachTo(this); this.WriteStatus = o => t.Text = o.ToString(); var t2 = new TextBox { FontSize = 10, AcceptsReturn = true, Text = @" ie and opera are not supported firefox reports after transform chrome reports before transform we cannot rely on mouse position currently shall wait for improvements like touch API ", BorderThickness = new Thickness(0), Foreground = 0xffffffff.ToSolidColorBrush(), Background = Brushes.Transparent, IsReadOnly = true, Width = DefaultWidth, Height = 128, }.MoveTo(8, 32).AttachTo(this); //help.Opacity = 1; img.Opacity = 0.5; t.MouseEnter += delegate { //help.Opacity = 0.5; img.Opacity = 1; t.Foreground = 0xffffff00.ToSolidColorBrush(); }; t.MouseLeave += delegate { //help.Opacity = 1; img.Opacity = 0.5; t.Foreground = 0xffffffff.ToSolidColorBrush(); }; var sand = new Avalon.Images.sand() { Width = 100, Height = 100, }.AttachTo(this); // structs are not that good for translations... // we might be able to skip them it seems sand.RenderTransform = new MatrixTransform(1.2, 0.5, 0.2, 1, 100, 100); sand.Cursor = Cursors.Hand; // jsc/mxmlc cannot handle property name "this" :) sand.Opacity = 0.7; sand.MouseMove += (sender, args) => { var p1 = args.GetPosition(sand); var p2 = args.GetPosition(this); t.Text = new { sand = new { p1.X, p1.Y }, that = new { p2.X, p2.Y } }.ToString(); }; var tri = new Avalon.Images._17() { Width = 100, Height = 100, }.AttachTo(this); var trig = new Avalon.Images._17g() { Width = 100, Height = 100, }.AttachTo(this); var tri2 = new Avalon.Images._17() { Width = 100, Height = 100, }.AttachTo(this); var trig2 = new Avalon.Images._17g() { Width = 100, Height = 100, }.AttachTo(this); // cursor position calculations are not ready // for transofrmed elements. // we will provide a floor for those events... var shadow = new Rectangle { Width = DefaultWidth, Height = DefaultHeight, Fill = Brushes.Black, }.AttachTo(this); var shadowa = shadow.ToAnimatedOpacity(); shadowa.Opacity = 0; Func<Brush, int, int, Movable> m = (Color, X, Y) => { var m0 = new Movable { Context = this, Color = Color }; m0.MoveTo(X, Y); return m0; }; var m1 = m(Brushes.Green, 250, 50); var m2 = m(Brushes.Red, 250 + 100, 50); var m3 = m(Brushes.Blue, 250, 50 + 100); var m4 = m(Brushes.Yellow, 250 + 100, 50 + 100); var m5 = m(Brushes.Green, 250 + 200, 50); var m6 = m(Brushes.Blue, 250 + 200, 50 + 100); Movables = new[] { m1, m2, m3, m4, m5, m6}; Action Update = delegate { tri.RenderTransform = new AffineTransform { Left = 0, Top = 0, Width = 100, Height = 100, X1 = m2.X, Y1 = m2.Y, X2 = m3.X, Y2 = m3.Y, X3 = m1.X, Y3 = m1.Y, }; trig.RenderTransform = new AffineTransform { Left = 0, Top = 0, Width = 100, Height = 100, X1 = m3.X, Y1 = m3.Y, X2 = m2.X, Y2 = m2.Y, X3 = m4.X, Y3 = m4.Y, }; tri2.RenderTransform = new AffineTransform { Left = 0, Top = 0, Width = 100, Height = 100, X1 = m5.X, Y1 = m5.Y, X2 = m4.X, Y2 = m4.Y, X3 = m2.X, Y3 = m2.Y, }; trig2.RenderTransform = new AffineTransform { Left = 0, Top = 0, Width = 100, Height = 100, X1 = m4.X, Y1 = m4.Y, X2 = m5.X, Y2 = m5.Y, X3 = m6.X, Y3 = m6.Y, }; }; foreach (var k in this.Movables) { k.Container.MouseLeftButtonDown += delegate { shadowa.Opacity = 0.2; }; k.Container.MouseLeftButtonUp += delegate { shadowa.Opacity = 0; }; k.Changed += Update; } Update(); }
public ApplicationCanvas() { //r.Fill = Brushes.Red; //r.AttachTo(this); //r.MoveTo(8, 8); //this.SizeChanged += (s, e) => r.SizeTo(this.Width - 16.0, this.Height - 16.0); var Scene = new Canvas().AttachTo(this); this.SizeChanged += (s, e) => Scene.MoveTo(this.Width / 2, this.Height / 2); var EgoSpeed = 0.5; var EgoPosition = 0.0; { var ego = new ski1(); ego.AttachTo(Scene); (1000 / 60).AtIntervalWithCounter( c => { EgoPosition += EgoSpeed; ego.MoveTo(0, (EgoPosition) % this.Height - this.Height / 2); } ); } Action <double, double> tree = (x, y) => new ski51().AttachTo(Scene).MoveTo(x, y); Action <double, double> deadtree = (x, y) => new ski50().AttachTo(Scene).MoveTo(x, y); Action <double, double> stone = (x, y) => new ski45().AttachTo(Scene).MoveTo(x, y); Action <double, double> stonefield = (x, y) => new ski27().AttachTo(Scene).MoveTo(x, y); tree(-64, 32); tree(64, 32); tree(-64, -32); tree(64, -32); var logo = new Avalon.Images.jsc().AttachTo(this); this.RotateScene = a => { Scene.RenderTransform = new RotateTransform(a); }; RotateScene(12); this.Accelerate = (ax, ay, az) => { Scene.RenderTransform = new RotateTransform(ax * 90); EgoSpeed = (1 - az) * 2; }; }
public ApplicationCanvas() { this.Background = Brushes.Red; r.Fill = Brushes.White; r.AttachTo(this); r.MoveTo(4, 4); this.SizeChanged += (s, e) => r.SizeTo(this.Width - 8.0, this.Height - 8.0); { var ego = new ski1(); ego.AttachTo(this).MoveTo(164, 96); (1000 / 60).AtIntervalWithCounter( c => { ego.MoveTo(164, c % this.Height); } ); } { var ego = new ski1(); var dc = -64; ego.AttachTo(this).MoveTo(320, dc); (1000 / 60).AtIntervalWithCounter( c => { ego.MoveTo(320, (c + dc) % this.Height); } ); } Action<double, double> tree = (x, y) => new ski51().AttachTo(this).MoveTo(x, y); Action<double, double> deadtree = (x, y) => new ski50().AttachTo(this).MoveTo(x, y); Action<double, double> stone = (x, y) => new ski45().AttachTo(this).MoveTo(x, y); Action<double, double> stonefield = (x, y) => new ski27().AttachTo(this).MoveTo(x, y); tree(64, 32); var logo = new Avalon.Images.jsc().AttachTo(this); this.SizeChanged += (s, e) => logo.MoveTo(this.Width - logo.Width, this.Height - logo.Height); this.MouseLeftButtonUp += (s, a) => { var pos = a.GetPosition(this); var f = new[] { tree, tree, tree, tree, deadtree, deadtree, stone, stone, stone, stonefield }; f.Random()(pos.X, pos.Y); }; var t = new TextBox { Text = "ski", Background = Brushes.Transparent, BorderThickness = new Thickness(0) }; t.AttachTo(this).MoveTo(96, 8); var ax = 0.0; var ay = 0.0; var az = 0.0; Action SizeChangedOrAccelerated = delegate { t.Text = "ski: " + new { this.Width, this.Height, ax, ay, az }; }; this.SizeChanged += (s, e) => { SizeChangedOrAccelerated(); }; t2.AttachTo(this).MoveTo(96, 24); Accelerate = (_ax, _ay, _az) => { ax = _ax; ay = _ay; az = _az; SizeChangedOrAccelerated(); }; }
public ApplicationCanvas() { Width = DefaultWidth; Height = DefaultHeight; //this.ClipToBounds = true; Colors.Blue.ToGradient(Colors.Red, DefaultHeight / 4).Select( (c, i) => new Rectangle { Fill = new SolidColorBrush(c), Width = DefaultWidth, Height = 4, }.MoveTo(0, i * 4).AttachTo(this) ).ToArray(); //var help = new Image //{ // Source = (KnownAssets.Path.Assets + "/help.png").ToSource() //}.AttachTo(this); //help.Opacity = 0; var img = new Avalon.Images.jsc().MoveTo(DefaultWidth - 128, DefaultHeight - 128).AttachTo(this); var t = new TextBox { FontSize = 10, Text = "powered by jsc", BorderThickness = new Thickness(0), Foreground = 0xffffffff.ToSolidColorBrush(), Background = Brushes.Transparent, IsReadOnly = true, Width = DefaultWidth }.MoveTo(8, 8).AttachTo(this); this.WriteStatus = o => t.Text = o.ToString(); var t2 = new TextBox { FontSize = 10, AcceptsReturn = true, Text = @" ie and opera are not supported firefox reports after transform chrome reports before transform we cannot rely on mouse position currently shall wait for improvements like touch API ", BorderThickness = new Thickness(0), Foreground = 0xffffffff.ToSolidColorBrush(), Background = Brushes.Transparent, IsReadOnly = true, Width = DefaultWidth, Height = 128, }.MoveTo(8, 32).AttachTo(this); //help.Opacity = 1; img.Opacity = 0.5; t.MouseEnter += delegate { //help.Opacity = 0.5; img.Opacity = 1; t.Foreground = 0xffffff00.ToSolidColorBrush(); }; t.MouseLeave += delegate { //help.Opacity = 1; img.Opacity = 0.5; t.Foreground = 0xffffffff.ToSolidColorBrush(); }; var sand = new Avalon.Images.sand() { Width = 100, Height = 100, }.AttachTo(this); // structs are not that good for translations... // we might be able to skip them it seems sand.RenderTransform = new MatrixTransform(1.2, 0.5, 0.2, 1, 100, 100); sand.Cursor = Cursors.Hand; // jsc/mxmlc cannot handle property name "this" :) sand.Opacity = 0.7; sand.MouseMove += (sender, args) => { var p1 = args.GetPosition(sand); var p2 = args.GetPosition(this); t.Text = new { sand = new { p1.X, p1.Y }, that = new { p2.X, p2.Y } }.ToString(); }; var tri = new Avalon.Images._17() { Width = 100, Height = 100, }.AttachTo(this); var trig = new Avalon.Images._17g() { Width = 100, Height = 100, }.AttachTo(this); var tri2 = new Avalon.Images._17() { Width = 100, Height = 100, }.AttachTo(this); var trig2 = new Avalon.Images._17g() { Width = 100, Height = 100, }.AttachTo(this); // cursor position calculations are not ready // for transofrmed elements. // we will provide a floor for those events... var shadow = new Rectangle { Width = DefaultWidth, Height = DefaultHeight, Fill = Brushes.Black, }.AttachTo(this); var shadowa = shadow.ToAnimatedOpacity(); shadowa.Opacity = 0; Func <Brush, int, int, Movable> m = (Color, X, Y) => { var m0 = new Movable { Context = this, Color = Color }; m0.MoveTo(X, Y); return(m0); }; var m1 = m(Brushes.Green, 250, 50); var m2 = m(Brushes.Red, 250 + 100, 50); var m3 = m(Brushes.Blue, 250, 50 + 100); var m4 = m(Brushes.Yellow, 250 + 100, 50 + 100); var m5 = m(Brushes.Green, 250 + 200, 50); var m6 = m(Brushes.Blue, 250 + 200, 50 + 100); Movables = new[] { m1, m2, m3, m4, m5, m6 }; Action Update = delegate { tri.RenderTransform = new AffineTransform { Left = 0, Top = 0, Width = 100, Height = 100, X1 = m2.X, Y1 = m2.Y, X2 = m3.X, Y2 = m3.Y, X3 = m1.X, Y3 = m1.Y, }; trig.RenderTransform = new AffineTransform { Left = 0, Top = 0, Width = 100, Height = 100, X1 = m3.X, Y1 = m3.Y, X2 = m2.X, Y2 = m2.Y, X3 = m4.X, Y3 = m4.Y, }; tri2.RenderTransform = new AffineTransform { Left = 0, Top = 0, Width = 100, Height = 100, X1 = m5.X, Y1 = m5.Y, X2 = m4.X, Y2 = m4.Y, X3 = m2.X, Y3 = m2.Y, }; trig2.RenderTransform = new AffineTransform { Left = 0, Top = 0, Width = 100, Height = 100, X1 = m4.X, Y1 = m4.Y, X2 = m5.X, Y2 = m5.Y, X3 = m6.X, Y3 = m6.Y, }; }; foreach (var k in this.Movables) { k.Container.MouseLeftButtonDown += delegate { shadowa.Opacity = 0.2; }; k.Container.MouseLeftButtonUp += delegate { shadowa.Opacity = 0; }; k.Changed += Update; } Update(); }
public ApplicationCanvas() { this.Background = Brushes.Red; r.Fill = Brushes.White; r.AttachTo(this); r.MoveTo(4, 4); this.SizeChanged += (s, e) => r.SizeTo(this.Width - 8.0, this.Height - 8.0); { var ego = new ski1(); ego.AttachTo(this).MoveTo(164, 96); (1000 / 60).AtIntervalWithCounter( c => { ego.MoveTo(164, c % this.Height); } ); } { var ego = new ski1(); var dc = -64; ego.AttachTo(this).MoveTo(320, dc); (1000 / 60).AtIntervalWithCounter( c => { ego.MoveTo(320, (c + dc) % this.Height); } ); } Action <double, double> tree = (x, y) => new ski51().AttachTo(this).MoveTo(x, y); Action <double, double> deadtree = (x, y) => new ski50().AttachTo(this).MoveTo(x, y); Action <double, double> stone = (x, y) => new ski45().AttachTo(this).MoveTo(x, y); Action <double, double> stonefield = (x, y) => new ski27().AttachTo(this).MoveTo(x, y); tree(64, 32); var logo = new Avalon.Images.jsc().AttachTo(this); this.SizeChanged += (s, e) => logo.MoveTo(this.Width - logo.Width, this.Height - logo.Height); this.MouseLeftButtonUp += (s, a) => { var pos = a.GetPosition(this); var f = new[] { tree, tree, tree, tree, deadtree, deadtree, stone, stone, stone, stonefield }; f.Random()(pos.X, pos.Y); }; var t = new TextBox { Text = "ski", Background = Brushes.Transparent, BorderThickness = new Thickness(0) }; t.AttachTo(this).MoveTo(96, 8); var ax = 0.0; var ay = 0.0; var az = 0.0; Action SizeChangedOrAccelerated = delegate { t.Text = "ski: " + new { this.Width, this.Height, ax, ay, az }; }; this.SizeChanged += (s, e) => { SizeChangedOrAccelerated(); }; t2.AttachTo(this).MoveTo(96, 24); Accelerate = (_ax, _ay, _az) => { ax = _ax; ay = _ay; az = _az; SizeChangedOrAccelerated(); }; }