private void Rec_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { NewCanvas temp = sender as NewCanvas; // Clone selected item DraggedItem = temp.Clone(); // Add event handler DraggedItem.MouseLeftButtonUp += new MouseButtonEventHandler(Rec_MouseLeftButtonUp); DraggedItem.MouseMove += new System.Windows.Input.MouseEventHandler(Rec_MouseMove); // Add to parent element //Console.WriteLine(DraggedItem.Parent); // Move clone to RootCanvas // Group_Basic.Children.Add(DraggedItem); var canvas = temp.Parent as Canvas; //var grid = canvas.Parent as Border; RecPos.X = (Double)DraggedItem.GetValue(Canvas.LeftProperty) + (Double)canvas.Parent.GetValue(Canvas.LeftProperty) + (Double)Canvas1.GetValue(Canvas.LeftProperty); RecPos.Y = (Double)DraggedItem.GetValue(Canvas.TopProperty) + (Double)canvas.Parent.GetValue(Canvas.TopProperty) + (Double)Canvas1.GetValue(Canvas.TopProperty) + Define.YPosOffset_OnDragging; DraggedItem.SetValue(Canvas.TopProperty, RecPos.Y); DraggedItem.SetValue(Canvas.LeftProperty, RecPos.X); //Console.WriteLine("(x, y) = (" + RecPos.X + ", " + RecPos.Y + ")"); RootCanvas.Children.Add(DraggedItem); // drag setup MousePos = e.GetPosition(null); PosDelta.X = RecPos.X - MousePos.X; PosDelta.Y = RecPos.Y - MousePos.Y; IsDragging = true; // Update log Console.WriteLine(DateTime.Now.ToString() + " : Start dragging <" + DraggedItem.Name + ">"); }
public Image(System.Uri source) { myImage.Width = 200/Canvas1.mm(1); // Create source BitmapImage myBitmapImage = new BitmapImage(); // BitmapImage.UriSource must be in a BeginInit/EndInit block myBitmapImage.BeginInit(); myBitmapImage.UriSource = source; //new Uri(@"C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Water Lilies.jpg"); // To save significant application memory, set the DecodePixelWidth or // DecodePixelHeight of the BitmapImage value of the image source to the desired // height or width of the rendered image. If you don't do this, the application will // cache the image as though it were rendered as its normal size rather then just // the size that is displayed. // Note: In order to preserve aspect ratio, set DecodePixelWidth // or DecodePixelHeight but not both. myBitmapImage.DecodePixelWidth = myBitmapImage.PixelWidth; myBitmapImage.EndInit(); //set image source myImage.Source = myBitmapImage; Canvas.SetLeft(myImage, 10); Canvas.SetBottom(myImage, 20); gp.Children.Add(myImage); }
private void butOk_Click(object sender, RoutedEventArgs e) { var rc = Canvas1.Focus(); if (rc == true) { } }
// Just for fun/test void RotateCubeAnimation() { axis = new AxisAngleRotation3D(new Vector3D(1, 0, 1), 0); Cube2.Transform = new RotateTransform3D(axis); RotAngle.From = 0; RotAngle.To = 360; RotAngle.Duration = new Duration(TimeSpan.FromSeconds(1.0)); RotAngle.RepeatBehavior = RepeatBehavior.Forever; NameScope.SetNameScope(Canvas1, new NameScope()); Canvas1.RegisterName("cubeaxis", axis); Storyboard.SetTargetName(RotAngle, "cubeaxis"); Storyboard.SetTargetProperty(RotAngle, new PropertyPath(AxisAngleRotation3D.AngleProperty)); RotCube.Children.Add(RotAngle); RotCube.Begin(Canvas1); }
private void UpdateCircles() { if (_useOpacity) { for (var i = 0; i < _circles.Length; i++) { _circles[i].Opacity = 1 - ((i + _offset) % _circles.Length) * 0.11; } _offset = (_offset + 1) % _circles.Length; } else { _rotateTransform.Angle = (_rotateTransform.Angle + 36) % 360; } Canvas1.InvalidateVisual(); }
public void new_tube_sample() { TubeSample.Width = 0; for (var i = 0; i <= _count; i++) { Canvas1.Children.Remove((UIElement)Canvas1.FindName("errorLine" + i)); try { Canvas1.UnregisterName("errorLine" + i); } catch { } } _count = 0; }
private void Canvas1_TouchDown(object sender, TouchEventArgs e) { var pt = e.GetTouchPoint(Canvas1); // 縦線を作ります。 var lineV = new Line(); lineV.X1 = lineV.X2 = pt.Position.X; lineV.Y1 = 0; lineV.Y2 = ActualHeight; lineV.Stroke = Brushes.Red; Canvas1.Children.Add(lineV); lineVList[e.TouchDevice] = lineV; // 横線を作ります。 var lineH = new Line(); lineH.X1 = 0; lineH.X2 = ActualWidth; lineH.Y1 = lineH.Y2 = pt.Position.Y; lineH.Stroke = Brushes.Red; Canvas1.Children.Add(lineH); lineHList[e.TouchDevice] = lineH; // 円を作ります。 var ellipse = new Ellipse(); ellipse.Width = 50; ellipse.Height = 50; ellipse.Fill = Brushes.Blue; ellipse.RenderTransform = new TranslateTransform(pt.Position.X - ellipse.RenderSize.Width / 2, pt.Position.Y - ellipse.RenderSize.Height / 2); Canvas1.Children.Add(ellipse); ellipseList[e.TouchDevice] = ellipse; // idを表すラベルを作ります。 var label = new Label(); label.Foreground = Brushes.White; label.FontSize = 36; label.Content = e.TouchDevice.Id; label.RenderTransform = new TranslateTransform(pt.Position.X - label.RenderSize.Width / 2, pt.Position.Y - label.RenderSize.Height / 2); Canvas1.Children.Add(label); labelList[e.TouchDevice] = label; Canvas1.InvalidateVisual(); Canvas1.CaptureTouch(e.TouchDevice); }
public MainWindow() { InitializeComponent(); Canvas1.Focus(); stopwatch = new Stopwatch(); stopwatch.Start(); tiempoAnterior = stopwatch.Elapsed; //1.Establecer instrucciones ThreadStart threadStart = new ThreadStart(moverObjetos); //2.Inicializar el Thread Thread threadMoverObjetos = new Thread(threadStart); //3.Ejecutar el Thread threadMoverObjetos.Start(); }
private void ChangeScreens() { GameLayout.IsEnabled = !GameLayout.IsEnabled; MenuLayout.IsEnabled = !MenuLayout.IsEnabled; if (StartMenuLayout.IsEnabled) { StartMenuLayout.IsEnabled = false; StartMenuLayout.Visibility = Visibility.Collapsed; } else if (_isGameOver) { _isGameOver = !_isGameOver; GameLayout.Visibility = Visibility.Collapsed; MenuLayout.IsEnabled = false; _isPaused = true; } else if (_isLevelFinished) { _isLevelFinished = !_isLevelFinished; GameLayout.Visibility = Visibility.Collapsed; MenuLayout.IsEnabled = false; _isPaused = true; } if (GameLayout.Visibility == Visibility.Visible) { GameLayout.Visibility = Visibility.Collapsed; MenuLayout.Visibility = Visibility.Visible; MenuLayout.Focus(); _isPaused = true; } else { GameLayout.IsEnabled = true; GameLayout.Visibility = Visibility.Visible; MenuLayout.Visibility = Visibility.Collapsed; Canvas1.Focus(); _isPaused = false; TimerMoveAsync(); BulletMoveAsync(); HordeMoveAsync(); } }
private void Canvas1_TouchUp(object sender, TouchEventArgs e) { if (e.TouchDevice.Captured == Canvas1) { Canvas1.ReleaseTouchCapture(e.TouchDevice); Canvas1.Children.Remove(ellipseList[e.TouchDevice]); ellipseList.Remove(e.TouchDevice); Canvas1.Children.Remove(labelList[e.TouchDevice]); labelList.Remove(e.TouchDevice); Canvas1.Children.Remove(lineVList[e.TouchDevice]); lineVList.Remove(e.TouchDevice); Canvas1.Children.Remove(lineHList[e.TouchDevice]); lineHList.Remove(e.TouchDevice); label1.Content = "CurrentTouchPoints:" + ellipseList.Count; } }
private void ButtonStart_OnClick(object sender, RoutedEventArgs e) { if (_isStarted) { Canvas1.Focus(); ChangeScreens(); } else { if (_isGameOver || _isLevelFinished) { Canvas1.Children.Clear(); } Pawn = new Player(ref Canvas1, "MainCube", LayoutMain.ActualWidth / 2, LayoutMain.ActualHeight / 2, 10, 10); Pawn.OnGameOver += GameOver; Canvas1.Children.Add(Pawn.PawnSprite); Canvas1.Focus(); ChangeScreens(); Countdown(); _isStarted = true; } }
public void error_sample_segment(int segment) { Dispatcher.BeginInvoke(new ThreadStart(delegate { var redBrush = new SolidColorBrush { Color = Colors.Red }; var errorLine = new Line(); Canvas.SetLeft(errorLine, (Canvas.GetLeft(Tube) + (segment * 4))); errorLine.X1 = 0; errorLine.X2 = 0; errorLine.Y1 = 151; errorLine.Y2 = 151 + 70; errorLine.StrokeThickness = 4; errorLine.Stroke = redBrush; errorLine.Fill = redBrush; Canvas1.RegisterName("errorLine" + _count, errorLine); _count++; Canvas1.Children.Add(errorLine); })); }
private void Canvas1_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { #region Menu if (Stage == 0) { Rect[] MenuRectangle = new Rect[2]; for (int i = 0; i < 2; i++) { MenuRectangle[i] = new Rect((int)((Canvas1.ActualWidth / 2) - 23), (int)((Canvas1.ActualHeight / 2) - 47 + (50 * i)), 50, 25); if (!MenuRectangle[i].Contains(MouseCords)) { args.DrawingSession.DrawRectangle(MenuRectangle[i], Colors.Black); } else { args.DrawingSession.DrawRectangle(MenuRectangle[i], Colors.Gold); } } args.DrawingSession.DrawText("Train", (int)((Canvas1.ActualWidth / 2) - 20), (int)((Canvas1.ActualHeight / 2) - 50 + (50 * 0)), Colors.LightGreen); args.DrawingSession.DrawText("Fight", (int)((Canvas1.ActualWidth / 2) - 20), (int)((Canvas1.ActualHeight / 2) - 50 + (50 * 1)), Colors.LightGreen); if (MouseDown[0] && MenuRectangle[0].Contains(MouseCords)) { Stage = 1; MouseDown[0] = false; } if (MouseDown[0] && MenuRectangle[1].Contains(MouseCords)) { Stage = 2; MouseDown[0] = false; } } #endregion args.DrawingSession.DrawText(TrainerCount + "", 10, 10, Colors.LightGreen); #region Trainer if (Stage == 1) { #region BoardControl if (GameOver) { if (Tie) { args.DrawingSession.DrawText("You both win!!!", (int)((Canvas1.ActualWidth / 2) - 40), (int)((Canvas1.ActualHeight / 2) - 50 - (50 * 4)), Colors.LightGreen); } else if (Turn) { args.DrawingSession.DrawText("O Won", (int)((Canvas1.ActualWidth / 2) - 30), (int)((Canvas1.ActualHeight / 2) - 50 - (50 * 4)), Colors.LightGreen); } else if (!Turn) { args.DrawingSession.DrawText("X Won", (int)((Canvas1.ActualWidth / 2) - 30), (int)((Canvas1.ActualHeight / 2) - 50 - (50 * 4)), Colors.LightGreen); } } else if (Turn) { args.DrawingSession.DrawText("X's Turn", (int)((Canvas1.ActualWidth / 2) - 30), (int)((Canvas1.ActualHeight / 2) - 50 - (50 * 4)), Colors.LightGreen); } else if (!Turn) { args.DrawingSession.DrawText("O's Turn", (int)((Canvas1.ActualWidth / 2) - 30), (int)((Canvas1.ActualHeight / 2) - 50 - (50 * 4)), Colors.LightGreen); } args.DrawingSession.DrawLine((int)((Canvas1.ActualWidth / 2) - 50), (int)((Canvas1.ActualHeight / 2) - 150), (int)((Canvas1.ActualWidth / 2) - 50), (int)((Canvas1.ActualHeight / 2) + 150), Colors.Black); args.DrawingSession.DrawLine((int)((Canvas1.ActualWidth / 2) + 50), (int)((Canvas1.ActualHeight / 2) - 150), (int)((Canvas1.ActualWidth / 2) + 50), (int)((Canvas1.ActualHeight / 2) + 150), Colors.Black); args.DrawingSession.DrawLine((int)((Canvas1.ActualWidth / 2) - 150), (int)((Canvas1.ActualHeight / 2) - 50), (int)((Canvas1.ActualWidth / 2) + 150), (int)((Canvas1.ActualHeight / 2) - 50), Colors.Black); args.DrawingSession.DrawLine((int)((Canvas1.ActualWidth / 2) - 150), (int)((Canvas1.ActualHeight / 2) + 50), (int)((Canvas1.ActualWidth / 2) + 150), (int)((Canvas1.ActualHeight / 2) + 50), Colors.Black); Rect[] GameRectangle = new Rect[9]; for (int i = 0; i < 9; i++) { GameRectangle[i] = new Rect((int)((Canvas1.ActualWidth / 2) - 150 + (100 * (i % 3))), (int)((Canvas1.ActualHeight / 2) - 150 + (100 * (Math.Floor((double)(i / 3))))), 100, 100); if (!GameOver) { if (MouseDown[0] && GameRectangle[i].Contains(MouseCords) && GameState[i] == 0 && Turn) { OldGameState[i] = GameState[i]; GameState[i] = 1; MoveMemory = i; Turn = !Turn; } else if (MouseDown[0] && GameRectangle[i].Contains(MouseCords) && GameState[i] == 0 && !Turn) { //OldGameState[i] = GameState[i]; GameState[i] = 2; Turn = !Turn; } } if (GameState[i] == 1) { args.DrawingSession.DrawLine((int)(GameRectangle[i].X + 5), (int)(GameRectangle[i].Y + 5), (int)(GameRectangle[i].X + GameRectangle[i].Width - 5), (int)(GameRectangle[i].Y + GameRectangle[i].Height - 5), Colors.Black); args.DrawingSession.DrawLine((int)(GameRectangle[i].X + 5), (int)(GameRectangle[i].Y + GameRectangle[i].Height - 5), (int)(GameRectangle[i].X + GameRectangle[i].Width - 5), (int)(GameRectangle[i].Y + 5), Colors.Black); } if (GameState[i] == 2) { args.DrawingSession.DrawEllipse((int)(GameRectangle[i].X + 50), (int)(GameRectangle[i].Y + 50), 45, 45, Colors.Black); } } if (GameOver) { args.DrawingSession.DrawText("Rematch", (int)((Canvas1.ActualWidth / 2) - 20), (int)((Canvas1.ActualHeight / 2) - 50 + (50 * 4)), Colors.LightGreen); args.DrawingSession.DrawText("Go Home", (int)((Canvas1.ActualWidth / 2) - 20), (int)((Canvas1.ActualHeight / 2) - 50 + (50 * 5)), Colors.LightGreen); Rect[] MenuRectangle = new Rect[2]; for (int i = 0; i < 2; i++) { MenuRectangle[i] = new Rect((int)((Canvas1.ActualWidth / 2) - 23), (int)((Canvas1.ActualHeight / 2) - 47 + (50 * (i + 4))), 90, 25); if (!MenuRectangle[i].Contains(MouseCords)) { args.DrawingSession.DrawRectangle(MenuRectangle[i], Colors.Black); } else { args.DrawingSession.DrawRectangle(MenuRectangle[i], Colors.Gold); } } if (MouseDown[0] && MenuRectangle[0].Contains(MouseCords)) { for (int i = 0; i < 9; i++) { GameState[i] = 0; } GameOver = false; Tie = false; } else if (MouseDown[0] && MenuRectangle[1].Contains(MouseCords)) { for (int i = 0; i < 9; i++) { GameState[i] = 0; } GameOver = false; Stage = 4; Tie = false; } } #region GameCheck for (int i = 0; i < 3; i++) { if (GameState[i] != 0 && GameState[i] == GameState[i + 3] && GameState[i] == GameState[i + 6]) { GameOver = true; args.DrawingSession.DrawLine((int)((Canvas1.ActualWidth / 2) - 100 + (100 * (i % 3))), (int)((Canvas1.ActualHeight / 2) - 150), (int)((Canvas1.ActualWidth / 2) - 100 + (100 * (i % 3))), (int)((Canvas1.ActualHeight / 2) + 150), Colors.Red); } else if (GameState[i * 3] != 0 && GameState[i * 3] == GameState[(i * 3) + 1] && GameState[i * 3] == GameState[(i * 3) + 2]) { GameOver = true; args.DrawingSession.DrawLine((int)((Canvas1.ActualWidth / 2) - 150), (int)((Canvas1.ActualHeight / 2) - 100 + (100 * (i % 3))), (int)((Canvas1.ActualWidth / 2) + 150), (int)((Canvas1.ActualHeight / 2) - 100 + (100 * (i % 3))), Colors.Red); } else if (GameState[i * 2] != 0 && i != 2 && GameState[i * 2] == GameState[4] && GameState[i * 2] == GameState[8 - (i * 2)]) { GameOver = true; args.DrawingSession.DrawLine((int)((Canvas1.ActualWidth / 2) - (150 + (-300 * i))), (int)((Canvas1.ActualHeight / 2) - 150), (int)((Canvas1.ActualWidth / 2) + (150 + (-300 * i))), (int)((Canvas1.ActualHeight / 2) + 150), Colors.Red); } else if (!GameState.Contains(0)) { GameOver = true; Tie = true; } } #endregion #endregion if (GameState != OldGameState) { TrainerCount++; for (int i = 0; i < 9; i++) { Input[TrainerCount][i] = OldGameState[i]; } DesiredOutput[TrainerCount][0] = MoveMemory; OldGameState = GameState; } } #endregion if (Stage == 4) { double[] Output = new double[1]; double Error = 0.0, ErrorResult = 1.0, ErrorSum = 1.0, ErrorAverage = 0.0, PreviousErrorAverage = 0.0; int Unstuck = 0; while (ErrorResult > 0.001) { Error = 0.0; for (int i = 0; i < TrainerCount; i++) { Error += bp.Train(ref Input[i], ref DesiredOutput[i], 0.15, 0.1); ErrorResult = Error; ErrorSum += Error; if ((PreviousErrorAverage / ErrorSum) < 1.001) // Only run if error is increasing on average { bp.Stuck(0.1); Unstuck++; } ErrorSum = 0.0; PreviousErrorAverage = ErrorAverage; } } Stage = 0; } #region Fight if (Stage == 2) { double[] SingleInput = new double[9]; for (int i = 0; i < 9; i++) { SingleInput[i] = OldGameState[i]; } double[] Output = new double[1]; bp.Run(ref SingleInput, out Output); #region BoardControl if (GameOver) { if (Tie) { args.DrawingSession.DrawText("You both win!!!", (int)((Canvas1.ActualWidth / 2) - 40), (int)((Canvas1.ActualHeight / 2) - 50 - (50 * 4)), Colors.LightGreen); } else if (Turn) { args.DrawingSession.DrawText("O Won", (int)((Canvas1.ActualWidth / 2) - 30), (int)((Canvas1.ActualHeight / 2) - 50 - (50 * 4)), Colors.LightGreen); } else if (!Turn) { args.DrawingSession.DrawText("X Won", (int)((Canvas1.ActualWidth / 2) - 30), (int)((Canvas1.ActualHeight / 2) - 50 - (50 * 4)), Colors.LightGreen); } } else if (Turn) { args.DrawingSession.DrawText("X's Turn", (int)((Canvas1.ActualWidth / 2) - 30), (int)((Canvas1.ActualHeight / 2) - 50 - (50 * 4)), Colors.LightGreen); } else if (!Turn) { args.DrawingSession.DrawText("O's Turn", (int)((Canvas1.ActualWidth / 2) - 30), (int)((Canvas1.ActualHeight / 2) - 50 - (50 * 4)), Colors.LightGreen); } args.DrawingSession.DrawLine((int)((Canvas1.ActualWidth / 2) - 50), (int)((Canvas1.ActualHeight / 2) - 150), (int)((Canvas1.ActualWidth / 2) - 50), (int)((Canvas1.ActualHeight / 2) + 150), Colors.Black); args.DrawingSession.DrawLine((int)((Canvas1.ActualWidth / 2) + 50), (int)((Canvas1.ActualHeight / 2) - 150), (int)((Canvas1.ActualWidth / 2) + 50), (int)((Canvas1.ActualHeight / 2) + 150), Colors.Black); args.DrawingSession.DrawLine((int)((Canvas1.ActualWidth / 2) - 150), (int)((Canvas1.ActualHeight / 2) - 50), (int)((Canvas1.ActualWidth / 2) + 150), (int)((Canvas1.ActualHeight / 2) - 50), Colors.Black); args.DrawingSession.DrawLine((int)((Canvas1.ActualWidth / 2) - 150), (int)((Canvas1.ActualHeight / 2) + 50), (int)((Canvas1.ActualWidth / 2) + 150), (int)((Canvas1.ActualHeight / 2) + 50), Colors.Black); Rect[] GameRectangle = new Rect[9]; for (int i = 0; i < 9; i++) { GameRectangle[i] = new Rect((int)((Canvas1.ActualWidth / 2) - 150 + (100 * (i % 3))), (int)((Canvas1.ActualHeight / 2) - 150 + (100 * (Math.Floor((double)(i / 3))))), 100, 100); if (!GameOver) { if (MouseDown[0] && GameRectangle[i].Contains(MouseCords) && GameState[i] == 0 && Turn) { OldGameState[i] = GameState[i]; GameState[i] = 1; Turn = !Turn; } else if (!Turn) { if (Output[0] > -0.5 && Output[0] < 8.5) { GameState[Convert.ToInt32(Output[0])] = 2; } Turn = !Turn; MouseDown[0] = false; args.DrawingSession.DrawText(Output[0] + "", 10, 10, Colors.LightGreen); } } if (GameState[i] == 1) { args.DrawingSession.DrawLine((int)(GameRectangle[i].X + 5), (int)(GameRectangle[i].Y + 5), (int)(GameRectangle[i].X + GameRectangle[i].Width - 5), (int)(GameRectangle[i].Y + GameRectangle[i].Height - 5), Colors.Black); args.DrawingSession.DrawLine((int)(GameRectangle[i].X + 5), (int)(GameRectangle[i].Y + GameRectangle[i].Height - 5), (int)(GameRectangle[i].X + GameRectangle[i].Width - 5), (int)(GameRectangle[i].Y + 5), Colors.Black); } if (GameState[i] == 2) { args.DrawingSession.DrawEllipse((int)(GameRectangle[i].X + 50), (int)(GameRectangle[i].Y + 50), 45, 45, Colors.Black); } } if (GameOver) { args.DrawingSession.DrawText("Rematch", (int)((Canvas1.ActualWidth / 2) - 20), (int)((Canvas1.ActualHeight / 2) - 50 + (50 * 4)), Colors.LightGreen); args.DrawingSession.DrawText("Go Home", (int)((Canvas1.ActualWidth / 2) - 20), (int)((Canvas1.ActualHeight / 2) - 50 + (50 * 5)), Colors.LightGreen); Rect[] MenuRectangle = new Rect[2]; for (int i = 0; i < 2; i++) { MenuRectangle[i] = new Rect((int)((Canvas1.ActualWidth / 2) - 23), (int)((Canvas1.ActualHeight / 2) - 47 + (50 * (i + 4))), 90, 25); if (!MenuRectangle[i].Contains(MouseCords)) { args.DrawingSession.DrawRectangle(MenuRectangle[i], Colors.Black); } else { args.DrawingSession.DrawRectangle(MenuRectangle[i], Colors.Gold); } } if (MouseDown[0] && MenuRectangle[0].Contains(MouseCords)) { for (int i = 0; i < 9; i++) { GameState[i] = 0; } GameOver = false; } else if (MouseDown[0] && MenuRectangle[1].Contains(MouseCords)) { for (int i = 0; i < 9; i++) { GameState[i] = 0; } GameOver = false; Stage = 0; } } #region GameCheck for (int i = 0; i < 3; i++) { if (GameState[i] != 0 && GameState[i] == GameState[i + 3] && GameState[i] == GameState[i + 6]) { GameOver = true; args.DrawingSession.DrawLine((int)((Canvas1.ActualWidth / 2) - 100 + (100 * (i % 3))), (int)((Canvas1.ActualHeight / 2) - 150), (int)((Canvas1.ActualWidth / 2) - 100 + (100 * (i % 3))), (int)((Canvas1.ActualHeight / 2) + 150), Colors.Red); } else if (GameState[i * 3] != 0 && GameState[i * 3] == GameState[(i * 3) + 1] && GameState[i * 3] == GameState[(i * 3) + 2]) { GameOver = true; args.DrawingSession.DrawLine((int)((Canvas1.ActualWidth / 2) - 150), (int)((Canvas1.ActualHeight / 2) - 100 + (100 * (i % 3))), (int)((Canvas1.ActualWidth / 2) + 150), (int)((Canvas1.ActualHeight / 2) - 100 + (100 * (i % 3))), Colors.Red); } else if (GameState[i * 2] != 0 && i != 2 && GameState[i * 2] == GameState[4] && GameState[i * 2] == GameState[8 - (i * 2)]) { GameOver = true; args.DrawingSession.DrawLine((int)((Canvas1.ActualWidth / 2) - (150 + (-300 * i))), (int)((Canvas1.ActualHeight / 2) - 150), (int)((Canvas1.ActualWidth / 2) + (150 + (-300 * i))), (int)((Canvas1.ActualHeight / 2) + 150), Colors.Red); } else if (!GameState.Contains(0)) { GameOver = true; } } #endregion #endregion } #endregion /* * double[][] Input = new double[4][]; * double[][] DesiredOutput = new double[4][]; * for (int i = 0; i < 4; i++) * { * Input[i] = new double[2]; * DesiredOutput[i] = new double[1]; * } * Input[0][0] = 0.0; Input[0][1] = 0.0; DesiredOutput[0][0] = 0.0; * Input[1][0] = 1.0; Input[1][1] = 0.0; DesiredOutput[1][0] = 1.0; * Input[2][0] = 0.0; Input[2][1] = 1.0; DesiredOutput[2][0] = 1.0; * Input[3][0] = 1.0; Input[3][1] = 1.0; DesiredOutput[3][0] = 2.0; * * * double[] Output = new double[1]; * double Error = 0.0, ErrorResult = 1.0, ErrorSum = 1.0, ErrorAverage = 0.0, PreviousErrorAverage = 0.0; * int Count = 0, Unstuck = 0; * while (ErrorResult > 0.001) * { * Count++; * Error = 0.0; * for (int j = 0; j < 4; j++) * { * Error += bp.Train(ref Input[j], ref DesiredOutput[j], 0.15, 0.1); * // bp.Run(ref Input[j], out Output); * } * ErrorResult = Error; * ErrorSum += Error; * if (Count % 1000 == 0) * { * //Console.WriteLine("Trial:" + Count + " Error:" + Math.Round(Error, 3)); * } * //Compareing average error change to detect being stuck * if (Count % 100 == 0) * { * ErrorAverage = ErrorSum / 100; * ErrorSum = 0.0; * // Console.WriteLine("ErrorChange: " + PreviousErrorAverage / ErrorAverage); * * if (Count != 100 && (PreviousErrorAverage / ErrorAverage) < 1.001) // Only run if error is increasing on average * { * bp.Stuck(0.1); * Unstuck++; * * } * PreviousErrorAverage = ErrorAverage; * } * * } * //Console.WriteLine("Finished on Trial:" + Count + " Error:" + Math.Round(Error, 3) + " TimesStuck:" + Unstuck); * * for (int i = 0; i < 4; i++) * { * bp.Run(ref Input[i], out Output); * // Console.WriteLine(Input[i][0] + " + " + Input[i][1] + " = " + Output[0]); * } * * * // Console.ReadKey(); */ Canvas1.Invalidate(); }
private void Canvas_MouseDown(object sender, MouseButtonEventArgs e) { Keyboard.ClearFocus(); Canvas1.Focus(); }
private void Canvas1_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { CanvasDrawingSession ds = args.DrawingSession; if (!ListBoxItem1.IsSelected) { //Drawing 1 //Sun ds.FillEllipse(0, 0, 150, 100, Colors.Yellow); //Grass ds.FillRectangle(new Rect(0, 700, 5000, 200), Colors.Green); //Tree ds.FillRectangle(new Rect(200, 325, 80, 400), Colors.SaddleBrown); ds.FillEllipse(240, 325, 100, 100, Colors.Green); ds.FillEllipse(200, 350, 100, 100, Colors.Green); ds.FillEllipse(260, 350, 100, 100, Colors.Green); //House ds.FillRectangle(new Rect(800, 475, 350, 300), Colors.DarkRed); ds.DrawLine(new Vector2(800, 475), new Vector2(1150, 775), Colors.White, 10); ds.DrawLine(new Vector2(800, 775), new Vector2(1150, 475), Colors.White, 10); Vector2[] roof = { new Vector2(800, 475), new Vector2(975, 375), new Vector2(1150, 475) }; CanvasPathBuilder pathBuilder = new CanvasPathBuilder(Canvas1); pathBuilder.AddGeometry(CanvasGeometry.CreatePolygon(Canvas1, roof)); ds.FillGeometry(CanvasGeometry.CreatePath(pathBuilder), Colors.SaddleBrown); } else { Color[] rainbow = { Colors.Red, Colors.Orange, Colors.Yellow, Colors.Green, Colors.Blue, Colors.Indigo, Colors.Violet }; //Drawing 2 Vector2 startingPoint = new Vector2((float)(ActualWidth / 2), (float)(ActualHeight / 2)); int angleIncrement = 3; int sideLength = 60; int angle = 0; hexagonsDrawn++; if (hexagonsDrawn == 1000) { //Draw hexagons for (int i = 0; i < hexagonsDrawn; i++) { for (int j = 0; j < 6; j++) { startingPoint = DrawLine(ds, startingPoint, angle, sideLength, rainbow[i % rainbow.Length]); angle += 60; } angle += angleIncrement; sideLength++; } hexagonsDrawn = 0; } else { //Draw hexagons for (int i = 0; i < hexagonsDrawn; i++) { for (int j = 0; j < 6; j++) { startingPoint = DrawLine(ds, startingPoint, angle, sideLength, rainbow[i % rainbow.Length]); angle += 60; } angle += angleIncrement; sideLength++; } Task.Delay(10).Wait(); Canvas1.Invalidate(); } } }
private void IconListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { Canvas1.Invalidate(); }
public MainWindow() { InitializeComponent(); Canvas1.Focus(); }
private void Canvas1_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { CanvasDrawingSession ds = args.DrawingSession; if (gameOver) { ds.DrawText("Game Over, You Win!!!", (float)Canvas1.ActualWidth / 2, (float)Canvas1.ActualHeight / 2, Colors.Green); ds.DrawText("Restarting in " + restartCountdown / 60 + "s.", (float)Canvas1.ActualWidth / 2, (float)(Canvas1.ActualHeight / 2) + 50, Colors.Lime); if (restartCountdown <= 0) { //Starting positions mainCharacter.x = 40; mainCharacter.y = Canvas1.ActualHeight - 115; mainCharacter.box = new Rect(mainCharacter.x, mainCharacter.y, 40, 40); gameOver = false; restartCountdown = 600; } else { restartCountdown--; } Canvas1.Invalidate(); return; } if (mainCharacter == null) { mainCharacter = new GameCharacter(Canvas1); } if (mainCharacter.y > Canvas1.ActualHeight) { mainCharacter.y = 0; } if (mainCharacter.x > Canvas1.ActualWidth) { mainCharacter.x = 0; } else if (mainCharacter.x < 0) { mainCharacter.x = Canvas1.ActualWidth - mainCharacter.box.Width; } //true when the box intersects with a single box. mainCharacter.onGround = !shapes.Keys.ToList().TrueForAll(rect => !checkIntersect(mainCharacter.box, rect)); //Handle character horizontal acceleration if (Window.Current.CoreWindow.GetKeyState(VirtualKey.D).HasFlag(CoreVirtualKeyStates.Down)) { if (mainCharacter.hSpeed < 10) { mainCharacter.hSpeed++; } } else if (Window.Current.CoreWindow.GetKeyState(VirtualKey.A).HasFlag(CoreVirtualKeyStates.Down)) { if (mainCharacter.hSpeed > -10) { mainCharacter.hSpeed--; } } else { if (mainCharacter.hSpeed > 0) { mainCharacter.hSpeed--; } else if (mainCharacter.hSpeed < 0) { mainCharacter.hSpeed++; } } if (!mainCharacter.onGround) { mainCharacter.box.Y -= mainCharacter.vSpeed; foreach (Rect rect in shapes.Keys) { if (checkIntersect(mainCharacter.box, rect)) { mainCharacter.y = rect.Y - mainCharacter.box.Height; mainCharacter.onGround = true; } } if (!mainCharacter.onGround) { mainCharacter.y -= mainCharacter.vSpeed; mainCharacter.vSpeed--; } else { mainCharacter.vSpeed = -2; } } else { mainCharacter.box.Y -= mainCharacter.vSpeed; foreach (Rect rect in shapes.Keys) { if (checkIntersect(mainCharacter.box, rect) && mainCharacter.y - mainCharacter.box.Height > rect.Y) { mainCharacter.y = rect.Y - mainCharacter.box.Height; } } } //Character Movement adjustments mainCharacter.x += mainCharacter.hSpeed; //Draw Rectangles foreach (KeyValuePair <Rect, Color> item in shapes) { ds.FillRectangle(item.Key, item.Value); } mainCharacter.draw(ds); //Check win condition if (mainCharacter.y < 300 && mainCharacter.x > 1000 && mainCharacter.x < 1140) { gameOver = true; } Canvas1.Invalidate(); }