public HitTestResultBehavior myHitTestResult(HitTestResult result) { if (result.VisualHit is System.Windows.Shapes.Ellipse && result.VisualHit != CurrentRec) { System.Windows.Shapes.Ellipse rect = result.VisualHit as System.Windows.Shapes.Ellipse; // rect.Fill = new SolidColorBrush(Colors.Red); //if (currentshapX > oldpositionX + 25 || currentshapX < oldpositionX - 25 || currentshapY > oldpositionY + 25 || currentshapY < oldpositionY - 25) //if (((currentshapX - oldpositionX) * (currentshapX - oldpositionX) + (currentshapY - oldpositionY) * (currentshapY - oldpositionY)) > 1200) { double tempX = 0, tempY = 0; int temp; tempX = (double)rect.GetValue(Canvas.LeftProperty); tempY = (double)rect.GetValue(Canvas.TopProperty); if (tempX != oldpositionX || tempY != oldpositionY) { rect.SetValue(Canvas.LeftProperty, oldpositionX); rect.SetValue(Canvas.TopProperty, oldpositionY); // lb1.Content = currentshapX; // lb2.Content = currentshapY; temp = orb[(int)(oldpositionY - 40) / 55, (int)(oldpositionX - 40) / 55]; orb[(int)(oldpositionY - 40) / 55, (int)(oldpositionX - 40) / 55] = orb[(int)(tempY - 40) / 55, (int)(tempX - 40) / 55]; orb[(int)(tempY - 40) / 55, (int)(tempX - 40) / 55] = temp; oldpositionX = tempX; oldpositionY = tempY; } // lb1.Content = oldpositionX; // lb2.Content = oldpositionY; } } return(HitTestResultBehavior.Continue); }
public void Draw(UIElementCollection children) { if (!isAlive) return; DateTime cur = DateTime.Now; foreach (var segment in segments) { PlayerUtils.Segment seg = segment.Value.GetEstimatedSegment(cur); if (seg.IsCircle()) { var circle = new Ellipse(); circle.Width = seg.radius * 2; circle.Height = seg.radius * 2; circle.SetValue(Canvas.LeftProperty, seg.x1 - seg.radius); circle.SetValue(Canvas.TopProperty, seg.y1 - seg.radius); circle.Stroke = brJoints; circle.StrokeThickness = 1; circle.Fill = brBones; children.Add(circle); } } // Remove unused players after 1/2 second. if (DateTime.Now.Subtract(lastUpdated).TotalMilliseconds > 500) isAlive = false; }
public void DrawAnnotations() { RemoveAllAnnotations(); var xAxis = Chart.XAxis as DateTimeAxis; if (xAxis == null || xAxis.ActualRange == null) return; foreach (var sensor in _viewModel.SensorsToCheckMethodsAgainst) { foreach (var calibration in sensor.Calibrations.Where(calibration => calibration.TimeStamp >= xAxis.ActualRange.EffectiveMinimum && calibration.TimeStamp <= xAxis.ActualRange.EffectiveMaximum)) { var ellipse = new Ellipse { Width = 10, Height = 10, ToolTip = string.Format( "[{0}] {1}", sensor.Name, calibration), Stroke = Brushes.Chartreuse, Fill = new SolidColorBrush(sensor.Colour) }; ellipse.SetValue(Canvas.TopProperty, 0d); ellipse.SetValue(Canvas.LeftProperty, xAxis.GetDataValueAsRenderPositionWithoutZoom(calibration.TimeStamp) - ellipse.Width / 2); _annotations.Add(ellipse); } } foreach (var annotation in _annotations) { _canvas.Children.Add(annotation); } }
private void drawPoint(Point p, Canvas testCanvas) { //create shape System.Diagnostics.Debug.WriteLine("Creating shape"); Shape userShape; Shape shape = new Ellipse(); shape.SetValue(Canvas.LeftProperty, p.X); shape.SetValue(Canvas.TopProperty, p.Y); //shape.HorizontalAlignment = HorizontalAlignment.Left; //shape.VerticalAlignment = VerticalAlignment.Center; shape.Width = 4; shape.Height = 4; shape.Stroke = new SolidColorBrush(Colors.Black); shape.StrokeThickness = 3.0; GradientBrush gb = new LinearGradientBrush(); gb.GradientStops = new GradientStopCollection(); GradientStop g1 = new GradientStop(); g1.Color = Colors.Red; gb.GradientStops.Add(g1); g1 = new GradientStop(); g1.Color = Colors.Blue; g1.Offset = 2; gb.GradientStops.Add(g1); shape.Fill = gb; shape.Visibility = System.Windows.Visibility.Visible; shape.Opacity = 0.5; testCanvas.Children.Add(shape); }
private void AddRotationHandle(Canvas element) { if (!registeredObjects.Contains(element)) { registeredObjects.Add(element); Ellipse ellipse = new Ellipse(); ellipse.Tag = RotationElementTag; ellipse.Width = ellipse.Height = RotationElementRadius * 2; ellipse.Fill = new SolidColorBrush(Colors.Blue); ellipse.SetValue(Canvas.TopProperty, -RotationElementRadius); ellipse.SetValue(Canvas.LeftProperty, -RotationElementRadius); ellipse.SetValue(Canvas.ZIndexProperty, (int)short.MaxValue); ellipse.MouseLeftButtonDown += MouseDown; ellipse.MouseLeftButtonUp += MouseUp; ellipse.MouseMove += MouseMoving; if (!(element.RenderTransform is RotateTransform)) { element.RenderTransform = new RotateTransform() { CenterX = element.Width / 2, CenterY = element.Height / 2 }; } element.Children.Add(ellipse); } }
private void Ellipse_MouseMove(object sender, MouseEventArgs e) { System.Windows.Shapes.Ellipse item = sender as System.Windows.Shapes.Ellipse; if (item.IsMouseCaptured) { System.Windows.Point pt = new System.Windows.Point(mouseX, mouseY); VisualTreeHelper.HitTest(this, null, new HitTestResultCallback(myHitTestResult), new PointHitTestParameters(pt)); // Calculate the current position of the object. double deltaX = e.GetPosition(null).X - mouseX; double deltaY = e.GetPosition(null).Y - mouseY; double newLeft = deltaX + (double)item.GetValue(Canvas.LeftProperty); double newTop = deltaY + (double)item.GetValue(Canvas.TopProperty); // Set new position of object. item.SetValue(Canvas.LeftProperty, newLeft); item.SetValue(Canvas.TopProperty, newTop); //add by me currentshapX = (double)item.GetValue(Canvas.LeftProperty); currentshapY = (double)item.GetValue(Canvas.TopProperty); // Update position global variables. mouseX = e.GetPosition(null).X; mouseY = e.GetPosition(null).Y; // 將正方形形圖轉成幾何圖形 /*Geometry g = item.RenderedGeometry; * // 座標位置轉換為視窗的座標 * g.Transform = item.TransformToAncestor(this) as MatrixTransform; * VisualTreeHelper.HitTest(this, null, * new HitTestResultCallback(myHitTestResult), * new GeometryHitTestParameters(g));*/ } }
private void CreateCircles() { var centerX = MainCanvas.ActualWidth/2.0; var centerY = MainCanvas.ActualHeight/2.0; Color[] colors = {Colors.White, Colors.Green, Colors.Green, Colors.Lime}; for (var i = 0; i < 24; ++i) { var e = new Ellipse(); var alpha = (byte) _rand.Next(96, 192); var colorIndex = _rand.Next(4); e.Stroke = new SolidColorBrush(Color.FromArgb(alpha, colors[colorIndex].R, colors[colorIndex].G, colors[colorIndex].B)); e.StrokeThickness = _rand.Next(1, 4); e.Width = 0.0; e.Height = 0.0; double offsetX = 16 - _rand.Next(32); double offsetY = 16 - _rand.Next(32); MainCanvas.Children.Add(e); e.SetValue(Canvas.LeftProperty, centerX + offsetX); e.SetValue(Canvas.TopProperty, centerY + offsetY); var duration = 6.0 + 10.0*_rand.NextDouble(); var delay = 16.0*_rand.NextDouble(); var offsetTransform = new TranslateTransform(); var offsetXAnimation = new DoubleAnimation(0.0, -256.0, new Duration(TimeSpan.FromSeconds(duration))) { RepeatBehavior = RepeatBehavior.Forever, BeginTime = TimeSpan.FromSeconds(delay) }; offsetTransform.BeginAnimation(TranslateTransform.XProperty, offsetXAnimation); offsetTransform.BeginAnimation(TranslateTransform.YProperty, offsetXAnimation); e.RenderTransform = offsetTransform; var sizeAnimation = new DoubleAnimation(0.0, 512.0, new Duration(TimeSpan.FromSeconds(duration))) { RepeatBehavior = RepeatBehavior.Forever, BeginTime = TimeSpan.FromSeconds(delay) }; e.BeginAnimation(WidthProperty, sizeAnimation); e.BeginAnimation(HeightProperty, sizeAnimation); var opacityAnimation = new DoubleAnimation(duration - 1.0, 0.0, new Duration(TimeSpan.FromSeconds(duration))) { BeginTime = TimeSpan.FromSeconds(delay), RepeatBehavior = RepeatBehavior.Forever }; e.BeginAnimation(OpacityProperty, opacityAnimation); } }
private void SetPosition(Ellipse ellipse, double offset, double posOffSet, double step) { ellipse.SetValue(Canvas.LeftProperty, 50.0 + Math.Sin(offset + posOffSet * step) * 50.0); ellipse.SetValue(Canvas.TopProperty, 50 + Math.Cos(offset + posOffSet * step) * 50.0); }
private void SetPosition(System.Windows.Shapes.Ellipse ellipse, double offset, double posOffSet, double step) { ellipse.SetValue(Canvas.LeftProperty, 50.0 + Math.Sin(offset + posOffSet * step) * 50.0); ellipse.SetValue(Canvas.TopProperty, 50 + Math.Cos(offset + posOffSet * step) * 50.0); }
//http://cespage.com/silverlight/tutorials/wp7tut7.html private void Add(Grid grid, int row, int column) { Ellipse _dot = new Ellipse(); _dot.Width = 20; _dot.Height = 20; _dot.Fill = new SolidColorBrush(Colors.Black); _dot.SetValue(Grid.ColumnProperty, column); _dot.SetValue(Grid.RowProperty, row); grid.Children.Add(_dot); }
private void SetPosition(Ellipse ellipse, double offset, double posOffSet, double step) { var rotation = (double)(2.5M * BallSize); ellipse.SetValue(Canvas.LeftProperty, rotation + Math.Sin(offset + posOffSet * step) * rotation); ellipse.SetValue(Canvas.TopProperty, rotation + Math.Cos(offset + posOffSet * step) * rotation); }
public void DrawDot(int x, int y, int radius, Color color) { Ellipse dot = new Ellipse(); dot.Width = 2 * radius; dot.Height = 2 * radius; dot.SetValue(Canvas.LeftProperty, (double)(x - radius)); dot.SetValue(Canvas.TopProperty, (double)(y - radius)); dot.Fill = new SolidColorBrush(color); Canvas.Children.Add(dot); }
private static void SetPosition(Ellipse ellipse, double offset, double posOffSet, double step) { const double diff = 20.0; ellipse.SetValue(Canvas.LeftProperty, diff + Math.Sin(offset + posOffSet * step) * diff); ellipse.SetValue(Canvas.TopProperty, diff + Math.Cos(offset + posOffSet * step) * diff); }
private void displayPadAndBall() { canvasField.Cursor = Cursors.None; ball.SetValue(Canvas.TopProperty, Convert.ToDouble(pad.GetValue(Canvas.TopProperty)) - 30); ball.SetValue(Canvas.LeftProperty, Convert.ToDouble(pad.GetValue(Canvas.LeftProperty)) + 15); pad.Visibility = Visibility.Visible; ball.Visibility = Visibility.Visible; IsBallOnPad = true; canvasField.MouseDown += canvasField_MouseDown; }
private void DrawRectangle() { Ellipse e = new Ellipse(); e.Width = 30; e.Height = 30; e.Fill = Brushes.Black; e.Stroke = Brushes.Red; e.SetValue(Canvas.LeftProperty, 100.0); e.SetValue(Canvas.TopProperty, 100.0); // myCanvass.Children.Add(e); }
private void CreateCircles() { double centerX = this.MainCanvas.ActualWidth / 2.0; double centerY = this.MainCanvas.ActualHeight / 2.0; Color[] colors = new Color[] { Colors.White, Colors.Green, Colors.Green, Colors.Lime }; for (int i = 0; i < 24; ++i) { Ellipse e = new Ellipse(); byte alpha = (byte)rand.Next(96, 192); int colorIndex = rand.Next(4); e.Stroke = new SolidColorBrush(Color.FromArgb(alpha, colors[colorIndex].R, colors[colorIndex].G, colors[colorIndex].B)); e.StrokeThickness = rand.Next(1, 4); e.Width = 0.0; e.Height = 0.0; double offsetX = 16 - rand.Next(32); double offsetY = 16 - rand.Next(32); this.MainCanvas.Children.Add(e); e.SetValue(Canvas.LeftProperty, centerX + offsetX); e.SetValue(Canvas.TopProperty, centerY + offsetY); double duration = 6.0 + 10.0 * rand.NextDouble(); double delay = 16.0 * rand.NextDouble(); TranslateTransform offsetTransform = new TranslateTransform(); DoubleAnimation offsetXAnimation = new DoubleAnimation(0.0, -256.0, new Duration(TimeSpan.FromSeconds(duration))); offsetXAnimation.RepeatBehavior = RepeatBehavior.Forever; offsetXAnimation.BeginTime = TimeSpan.FromSeconds(delay); offsetTransform.BeginAnimation(TranslateTransform.XProperty, offsetXAnimation); offsetTransform.BeginAnimation(TranslateTransform.YProperty, offsetXAnimation); e.RenderTransform = offsetTransform; DoubleAnimation sizeAnimation = new DoubleAnimation(0.0, 512.0, new Duration(TimeSpan.FromSeconds(duration))); sizeAnimation.RepeatBehavior = RepeatBehavior.Forever; sizeAnimation.BeginTime = TimeSpan.FromSeconds(delay); e.BeginAnimation(Ellipse.WidthProperty, sizeAnimation); e.BeginAnimation(Ellipse.HeightProperty, sizeAnimation); DoubleAnimation opacityAnimation = new DoubleAnimation(duration - 1.0, 0.0, new Duration(TimeSpan.FromSeconds(duration))); opacityAnimation.BeginTime = TimeSpan.FromSeconds(delay); opacityAnimation.RepeatBehavior = RepeatBehavior.Forever; e.BeginAnimation(Ellipse.OpacityProperty, opacityAnimation); } }
public System.Windows.Shapes.Ellipse GetCanvasCircle(netDxf.Entities.Circle circle, Vector3 startVector, double canvasHeight) { var tempEllipse = new System.Windows.Shapes.Ellipse(); tempEllipse.Height = 2 * circle.Radius; tempEllipse.Width = 2 * circle.Radius; tempEllipse.StrokeThickness = 1; tempEllipse.Stroke = Brushes.Black; tempEllipse.SetValue(Canvas.LeftProperty, -InputCircle.Radius + InputCircle.Center.X - startVector.X); tempEllipse.SetValue(Canvas.TopProperty, -InputCircle.Radius - InputCircle.Center.Y + canvasHeight + startVector.Y); return(tempEllipse); }
private void Ellipse_MouseUp(object sender, MouseButtonEventArgs e) { System.Windows.Shapes.Ellipse item = sender as System.Windows.Shapes.Ellipse; if (!changemode && item.IsMouseCaptured) //如果是上色模式就不執行 { timershow.Stop(); timersec.Stop(); item.ReleaseMouseCapture(); Canvas.SetZIndex(item, 0); //物體位置回歸水平 mouseX = -1; mouseY = -1; item.SetValue(Canvas.LeftProperty, oldpositionX); //轉完自動歸位圓圈 item.SetValue(Canvas.TopProperty, oldpositionY); // } }
public void circle(int x, int y, int width, int height) { System.Windows.Shapes.Ellipse circle = new System.Windows.Shapes.Ellipse() { Width = width, Height = height, Stroke = System.Windows.Media.Brushes.Red, StrokeThickness = 6 }; drawPanel.Children.Add(circle); circle.SetValue(Canvas.LeftProperty, (double)x); circle.SetValue(Canvas.TopProperty, (double)y); }
private void Activate(Point2D item) { if (Map == null || Map.Layers == null) { return; } ellipse = new Ellipse(); #region 所有风格的控制 ellipse.Stroke = Stroke; ellipse.StrokeThickness = StrokeThickness; ellipse.Fill = Fill; ellipse.StrokeMiterLimit = StrokeMiterLimit; ellipse.StrokeDashOffset = StrokeDashOffset; ellipse.StrokeDashArray = StrokeDashArray; ellipse.StrokeDashCap = StrokeDashCap; ellipse.StrokeEndLineCap = StrokeEndLineCap; ellipse.StrokeLineJoin = StrokeLineJoin; ellipse.StrokeStartLineCap = StrokeStartLineCap; ellipse.Opacity = Opacity; #endregion DrawLayer = new ElementsLayer(); Map.Layers.Add(DrawLayer); ellipse.SetValue(ElementsLayer.BBoxProperty, new Rectangle2D(item, item)); DrawLayer.Children.Add(ellipse); isActivated = true; isDrawing = true; }
private void drawPoints() { if (simplePolygon == null) return; StringBuilder s = new StringBuilder(); for (int i = 0; i < simplePolygon.GeometryPoints.Length; i++) { Ellipse elps = new Ellipse(); elps.Height = 3; elps.Width = 3; elps.Fill = Brushes.Black; elps.SetValue(Canvas.LeftProperty, simplePolygon.GeometryPoints[i].X + Coordinates_X_OFFSET); elps.SetValue(Canvas.TopProperty, simplePolygon.GeometryPoints[i].Y + Coordinates_Y_OFFSET); canvas.Children.Add(elps); s = s.AppendLine(simplePolygon.GeometryPoints[i].ToString()); } tb.Text = s.ToString(); }
private void SetPosition(Ellipse ellipse, double offset, double posOffSet, double step, double ew, double eh, double w, double h, double r) { double t = 2 * Math.PI * posOffSet / 10; ellipse.Width = ew; ellipse.Height = eh; ellipse.SetValue(Canvas.LeftProperty, w + r * Math.Cos(t)); ellipse.SetValue(Canvas.TopProperty, h + r * Math.Sin(t)); //ellipse.SetValue(Canvas.LeftProperty,w // + Math.Sin(offset + posOffSet * step) * w); //ellipse.SetValue(Canvas.TopProperty, h // + Math.Cos(offset + posOffSet * step) * h); }
private void DrawSharp() { Line l = new Line(); l.StrokeThickness = 1.0; l.X1 = 10.0; l.X2 = 100.0; DrawCanvas.Children.Add(l); ellipse = new Ellipse(); ellipse.Width = 30; ellipse.Height = 30; ellipse.Fill = Brushes.Black; ellipse.Stroke = Brushes.Red; ellipse.StrokeThickness = 1.0; ellipse.SetValue(Canvas.LeftProperty, 100.0); ellipse.SetValue(Canvas.TopProperty, 100.0); DrawCanvas.Children.Add(ellipse); }
/// <summary> /// Método para generar el tablero en pantalla /// </summary> /// <param name="tablero"></param> public void GeneraTablero(Tablero tablero) { TableroReinas.ColumnDefinitions.Clear(); TableroReinas.RowDefinitions.Clear(); TableroReinas.Children.Clear(); for (int i = 0; i < tablero.NumeroReinas; i++) { TableroReinas.ColumnDefinitions.Add(new ColumnDefinition() { Width = CellSize }); TableroReinas.RowDefinitions.Add(new RowDefinition() { Height = CellSize }); } for (int i = 0; i < tablero.NumeroReinas; i++) { for (int j = 0; j < tablero.NumeroReinas; j++) { Rectangle r = new Rectangle(); <<<<<<< HEAD r.SetValue(Grid.RowProperty, j); r.SetValue(Grid.ColumnProperty, i); if (((i * tablero.NumeroReinas) + j) % 2 == 0) ======= r.SetValue(Grid.RowProperty, i); r.SetValue(Grid.ColumnProperty, j); if ((i + j) % 2 == 0) >>>>>>> Práctica 6 completa r.Fill = new SolidColorBrush(Colors.Black); else r.Fill = new SolidColorBrush(Colors.White); TableroReinas.Children.Add(r); if (tablero.Reinas[i, j] == 1) { Ellipse c = new Ellipse(); c.Fill = new SolidColorBrush(Color.FromArgb(255, 164, 16, 52)); c.SetValue(Grid.ColumnProperty, j); c.SetValue(Grid.RowProperty, i); TableroReinas.Children.Add(c); } } } }
public System.Windows.Shapes.Ellipse GetCanvasEllipse(netDxf.Entities.Ellipse ellipse, Vector3 startVector, double canvasHeight) { var tempEllipse = new System.Windows.Shapes.Ellipse(); tempEllipse.Height = ellipse.MinorAxis; tempEllipse.Width = ellipse.MajorAxis; tempEllipse.StrokeThickness = 1; tempEllipse.Stroke = Brushes.Black; tempEllipse.SetValue(Canvas.LeftProperty, -ellipse.MajorAxis / 2 + ellipse.Center.X - startVector.X); tempEllipse.SetValue(Canvas.TopProperty, -ellipse.MinorAxis / 2 - ellipse.Center.Y + canvasHeight + startVector.Y); return(tempEllipse); }
public static Ellipse DrawEllipse(Brush fillColor, int strokeThickness, Brush strokeColor, int width, int height, int xPos, int yPos) { Ellipse ellipse = new Ellipse(); ellipse.Fill = fillColor; if (strokeThickness > 0) { ellipse.StrokeThickness = strokeThickness; ellipse.Stroke = strokeColor; } ellipse.Width = width; ellipse.Height = height; ellipse.SetValue(Canvas.LeftProperty, (double)xPos); ellipse.SetValue(Canvas.TopProperty, (double)yPos); return ellipse; }
public MainPage() { InitializeComponent(); _manager = new ShapeManager(ThePanel); _num = 10; _dot = new Ellipse[_num]; _x = new double[_num]; _y = new double[_num]; _dx = new double[_num]; _dy = new double[_num]; for (int i = 0; i < _num; i++) { Ellipse z = new Ellipse(); if( i==0 || i==_num-1 ) z.Fill = new SolidColorBrush(Colors.Red); else z.Fill = new SolidColorBrush(Colors.Green); z.Width = 20; z.Height = 20; _dot[i] = z; double x = (i+1) * ThePanel.Width / (_num+2); double y = ThePanel.Height / 2; _x[i] = x; _y[i] = y; z.SetValue(Canvas.TopProperty, y); z.SetValue(Canvas.LeftProperty, x); ThePanel.Children.Add(z); _manager.Add(z); } _timer = new DispatcherTimer(); _timer.Interval = new TimeSpan(0, 0, 0, 0, 100); _timer.Tick += new EventHandler(_timer_Tick); _timer.Start(); }
private void DrawCell(int columnCount, int rowCount) { var cellRectangle = new Ellipse { Fill = Brushes.Tomato, Width = GetCellWidth(), Height = GetCellHeight(), Margin = new Thickness(columnCount * GetCellWidth(), rowCount * GetCellHeight(), 0, 0) }; cellRectangle.SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Unspecified); PlayingField.Children.Add(cellRectangle); }
private void DrawCircleMove() { Dispatcher.BeginInvoke(new Action(() => { Ellipse drawEllipse = new Ellipse(); SolidColorBrush solidColorBrush = new SolidColorBrush(Color.FromArgb(200, 200, 210, 0)); drawEllipse.Fill = solidColorBrush; drawEllipse.Height = 70; drawEllipse.Width = 70; drawEllipse.SetValue(Canvas.LeftProperty, (double)0); drawEllipse.SetValue(Canvas.TopProperty, (double)0); DrawCanvas.Children.Clear(); DrawCanvas.Children.Add(drawEllipse); for (int i = 0; i < 100; i++) { DrawCanvas.Children.Clear(); drawEllipse.SetValue(Canvas.LeftProperty, (double)i); drawEllipse.SetValue(Canvas.TopProperty, (double)i); DrawCanvas.Children.Add(drawEllipse); System.Threading.Thread.Sleep(100); } })); }
private void DrawCircle_Clicked(object sender, RoutedEventArgs e) { var window = new EditPosition() { Owner = this, WindowStartupLocation = WindowStartupLocation.CenterOwner }; var vm = new EditPositionVm(); window.DataContext = vm; window.ShowDialog(); if (window.DialogResult == true) { var ellipse = new Ellipse() { Width = 100, Height = 100, Stroke = new SolidColorBrush(Colors.Gold), StrokeThickness = 2 , Fill = new SolidColorBrush(Colors.Green)}; Canvas.SetLeft(ellipse, vm.Left); Canvas.SetTop(ellipse, vm.Top); this.DrawCanvas.Children.Add(ellipse); //Add drag drop behavior ellipse.SetValue(DragDropBehavior.PlacementTarget, this.DrawCanvas); } }
public void ItemsRequest(object sender, ItemsRequestEventArgs e) { List<object> items = new List<object>(); double minZoom = e.MinZoom; Location upperLeft = e.UpperLeft; Location lowerRight = e.LowerRight; HotSpot centerSpot = new HotSpot(); centerSpot.X = 0.5; centerSpot.Y = 0.5; Location bulgariaLocation = new Location(42.7669999748468, 25.2819999307394); LocationRect currentRegion = new LocationRect(upperLeft, lowerRight); if (currentRegion.Contains(bulgariaLocation)) { if (minZoom == 3) { Ellipse ellipse = new Ellipse(); ellipse.Width = 15; ellipse.Height = 15; ellipse.Fill = new SolidColorBrush(Colors.Red); ellipse.SetValue(MapLayer.LocationProperty, bulgariaLocation); MapLayer.SetHotSpot(ellipse, centerSpot); ToolTipService.SetToolTip(ellipse, "Bulgaria"); items.Add(ellipse); } else if (minZoom == 6) { Ellipse sofiaEllipse = new Ellipse(); sofiaEllipse.Width = 20; sofiaEllipse.Height = 20; sofiaEllipse.Stroke = new SolidColorBrush(Colors.Red); sofiaEllipse.Fill = new SolidColorBrush(Colors.Transparent); sofiaEllipse.StrokeThickness = 3; sofiaEllipse.SetValue(MapLayer.LocationProperty, new Location(42.6957539183824, 23.3327663758679)); MapLayer.SetHotSpot(sofiaEllipse, centerSpot); ToolTipService.SetToolTip(sofiaEllipse, "Sofia"); items.Add(sofiaEllipse); } } e.CompleteItemsRequest(items); }
public void Draw(UIElementCollection children) { if (!isAlive) return; // Draw all bones first, then circles (head and hands). DateTime cur = DateTime.Now; foreach (var segment in segments) { Segment seg = segment.Value.GetEstimatedSegment(cur); if (!seg.IsCircle()) { var line = new Line(); line.StrokeThickness = seg.radius * 2; line.X1 = seg.x1; line.Y1 = seg.y1; line.X2 = seg.x2; line.Y2 = seg.y2; line.Stroke = brBones; line.StrokeEndLineCap = PenLineCap.Round; line.StrokeStartLineCap = PenLineCap.Round; children.Add(line); } } foreach (var segment in segments) { Segment seg = segment.Value.GetEstimatedSegment(cur); if (seg.IsCircle()) { var circle = new Ellipse(); circle.Width = seg.radius * 2; circle.Height = seg.radius * 2; circle.SetValue(Canvas.LeftProperty, seg.x1 - seg.radius); circle.SetValue(Canvas.TopProperty, seg.y1 - seg.radius); circle.Stroke = brJoints; circle.StrokeThickness = 1; circle.Fill = brBones; children.Add(circle); } } // Remove unused players after 1/2 second. if (DateTime.Now.Subtract(lastUpdated).TotalMilliseconds > 500) isAlive = false; }
private static Image <Hsv, Byte> processedred; //Casts bitmap to image<Hsv, byte> //Red Segmentation public static void Proc(BitmapSource Image, Canvas Canvas3, System.Windows.Controls.Image outputimage) { if (Image != null) { //Red Processing //Converts to image<> MemoryStream Streamred = new MemoryStream(); BitmapEncoder encodedred = new BmpBitmapEncoder(); encodedred.Frames.Add(BitmapFrame.Create(Image)); encodedred.Save(Streamred); System.Drawing.Bitmap myBmpred = new System.Drawing.Bitmap(Streamred); //Casts image to bitmap processedred = new Image <Hsv, Byte>(myBmpred); //Casts bitmap to image<Hsv, byte> //Main processing CvInvoke.Flip(processedred, processedred, Emgu.CV.CvEnum.FlipType.Horizontal); //Flips the image in the horizontal Image <Gray, Byte> Thrred; //Creates two Grayscale images that will be used when segmenting Thrred = processedred.InRange(new Hsv(165, 125, 120), new Hsv(180, 255, 255)); //Handles second range for RED //Handles noise and cleans image Mat kernel = Mat.Ones(3, 3, Emgu.CV.CvEnum.DepthType.Cv32F, 1); //Creates 3x3 kernelred for use as kernelred CvInvoke.MorphologyEx(Thrred, Thrred, Emgu.CV.CvEnum.MorphOp.Open, kernel, new System.Drawing.Point(0, 0), 1, Emgu.CV.CvEnum.BorderType.Default, new MCvScalar(1)); CvInvoke.MorphologyEx(Thrred, Thrred, Emgu.CV.CvEnum.MorphOp.Dilate, kernel, new System.Drawing.Point(0, 0), 1, Emgu.CV.CvEnum.BorderType.Default, new MCvScalar(1)); // Used to display red parts of original image //Extracts only RED parts from orignal image //Mat Mask; //Creates Mat for converting mask to Mat //Mask = Thrred.Mat; //Casts mask to Mat //Image<Hsv, byte> Redisolated = new Image<Hsv, byte>(processedred.Width, processedred.Height); //Creates Image<Hsv,byte> for final processedred image //CvInvoke.BitwiseAnd(processedred, processedred, Redisolated, Mask); //ANDS mask with orignal image to retain only portions that are RED //Extracts biggest blob //Variables double largestareared = 0; int largestcontourindexred = 0; Image <Hsv, Byte> Output = new Image <Hsv, Byte>(processedred.Width, processedred.Height); Image <Gray, Byte> ContourdrawnRed = new Image <Gray, Byte>(processedred.Width, processedred.Height); VectorOfVectorOfPoint ContoursRed = new VectorOfVectorOfPoint(); Mat HierarchyRed = new Mat(); //Processing CvInvoke.FindContours(Thrred, ContoursRed, HierarchyRed, Emgu.CV.CvEnum.RetrType.Ccomp, Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxSimple); //Finds contours in image //Iterates through each contour for (int i = 0; i < ContoursRed.Size; i++) { double a = CvInvoke.ContourArea(ContoursRed[i], false); // Find the area of contour if (a > largestareared) { largestareared = a; largestcontourindexred = i; //Stores the index of largest contour boundingrectred = CvInvoke.BoundingRectangle(ContoursRed[i]); // Creates bounding rectangle for biggest contour } } //Compute centre of rectangle XRed = boundingrectred.X + (boundingrectred.Width / 2); YRed = boundingrectred.Y + (boundingrectred.Height / 2); //Old Method used for overlay //CvInvoke.DrawContours(processedred, ContoursRed, largestcontourindexred, new MCvScalar(255, 255, 255), 10, Emgu.CV.CvEnum.LineType.Filled, HierarchyRed, 0); //Draws biggest contour on blank image //processedred.Draw(boundingrectred,new Hsv(255,255,255), 3); //CvInvoke.Circle(processedred, new System.Drawing.Point(640-XRed, YRed), 4, new MCvScalar(255),2, Emgu.CV.CvEnum.LineType.Filled); //outputimage.Source = BitmapSourceConvert.ToBitmapSource1(processedred1); //Cleanup //Mask.Dispose(); Thrred.Dispose(); Streamred.Dispose(); myBmpred.Dispose(); //Blue Image <Gray, Byte> ThrBlue; //Creates two Grayscale images that will be used when segmenting ThrBlue = processedred.InRange(new Hsv(85, 110, 80), new Hsv(135, 230, 220)); //Handles second range for Blue //Handles noise and cleans image CvInvoke.MorphologyEx(ThrBlue, ThrBlue, Emgu.CV.CvEnum.MorphOp.Open, kernel, new System.Drawing.Point(0, 0), 1, Emgu.CV.CvEnum.BorderType.Default, new MCvScalar(1)); CvInvoke.MorphologyEx(ThrBlue, ThrBlue, Emgu.CV.CvEnum.MorphOp.Dilate, kernel, new System.Drawing.Point(0, 0), 1, Emgu.CV.CvEnum.BorderType.Default, new MCvScalar(1)); //Used to display blue parts of original image //Extracts only RED parts from orignal image //Mat Mask1; //Creates Mat for converting mask to Mat //Mask1 = ThrBlue.Mat; //Casts mask to Mat //Image<Hsv, byte> Bluleisolated = new Image<Hsv, byte>(processedred.Width, processedred.Height); //Creates Image<Hsv,byte> for final processedred image //CvInvoke.BitwiseAnd(processedred, processedred, Redisolated, Mask); //ANDS mask with orignal image to retain only portions that are RED //Extracts biggest blob //Variables double LargestAreaBlue = 0; int LargestContourIndexBlue = 0; MCvPoint2D64f CenterBlue = new MCvPoint2D64f(0, 0); Image <Gray, Byte> ContourDrawnBlue = new Image <Gray, Byte>(processedred.Width, processedred.Height); VectorOfVectorOfPoint ContoursBlue = new VectorOfVectorOfPoint(); Moments MomentsBlue = new Moments(); Mat HierarchyBlue = new Mat(); //Processing CvInvoke.FindContours(ThrBlue, ContoursBlue, HierarchyBlue, Emgu.CV.CvEnum.RetrType.Ccomp, Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxSimple); //Finds contours in image //Iterates through each contour for (int i = 0; i < ContoursBlue.Size; i++) { double a = CvInvoke.ContourArea(ContoursBlue[i], false); // Find the area of contour if (a > LargestAreaBlue) { LargestAreaBlue = a; LargestContourIndexBlue = i; //Stores the index of largest contour boundingrectBlue = CvInvoke.BoundingRectangle(ContoursBlue[LargestContourIndexBlue]); // Creates bounding rectangle for biggest contour } } //Compute center of rectangle XBlue = boundingrectBlue.X + boundingrectBlue.Width / 2; YBlue = boundingrectBlue.Y + boundingrectBlue.Height / 2; //Cleanup //Mask1.Dispose(); ThrBlue.Dispose(); //Add point to images Canvas3.Children.Clear(); System.Windows.Shapes.Ellipse PointRed = CreateEllipse.CircleRed(); System.Windows.Shapes.Ellipse PointBlue = CreateEllipse.CircleBlue(); Canvas3.Children.Add(PointRed); Canvas3.Children.Add(PointBlue); PointRed.SetValue(Canvas.LeftProperty, (640 - XRed) * .6); //0.6 used as the stream sizes are 0.6 times the actual resolution PointRed.SetValue(Canvas.TopProperty, YRed * .6); PointBlue.SetValue(Canvas.LeftProperty, (640 - XBlue) * .6); PointBlue.SetValue(Canvas.TopProperty, YBlue * .6); return; } else { return; } }
//GRAFO ALEATORIO private void button1_Click(object sender, RoutedEventArgs e) { ser.creaAsync(); OpenFileDialog odlg = new OpenFileDialog(); odlg.Filter = "Text files|*.txt"; odlg.Multiselect = false; if ((bool)odlg.ShowDialog()){ StreamReader sr = new StreamReader(odlg.File.OpenRead()); //int n=100000; canvas1.Height = 19000;//1009000 para 1000000 //19000 para 100000 canvas1.Width = 19000;//19000 para 1000000 string line; int j = 0; int cont = 0; int ar = 0; int d=0; int g=0; int h=0; //int distancia; while ((line = sr.ReadLine()) != null){ if (line == "&"){ ar = 1; cont=3; } while (cont < 3){ if (cont == 2){ h = int.Parse(line.Substring(0, line.Length)); break; } j = line.IndexOf(" "); if (cont == 0) d=int.Parse(line.Substring(0, j)); if (cont==1) g=int.Parse(line.Substring(0, j)); line = line.Substring(j + 2, line.Length - j - 2); cont++; } if (ar == 0 && cont < 3){ var b = new Ellipse(); b.Width = 3; b.Height = 3; b.Fill = new System.Windows.Media.SolidColorBrush(Colors.Blue); b.SetValue(Canvas.LeftProperty, (double)g); b.SetValue(Canvas.TopProperty, (double)h); b.Name = d.ToString(); b.Cursor = Cursors.Hand; canvas1.Children.Add(b); Nodo nodo = new Nodo(g, h); nodos.Add(nodo); } if (ar == 1 && cont < 3) { Line edge = new Line(); edge.Stroke = new System.Windows.Media.SolidColorBrush(Colors.Black); //distancia = dist(nodos[g].get_x(), nodos[h].get_x(), nodos[g].get_y(), nodos[h].get_y()); //edge.Name = distancia.ToString(); edge.X1 = nodos[g].x; edge.Y1 = nodos[g].y; edge.X2 = nodos[h].x; edge.Y2 = nodos[h].y; canvas1.Children.Insert(0, edge); } cont = 0; } sr.Close(); } }
//CREA_NODO private void functionNodes(object sender, MouseButtonEventArgs e) { Random random = new Random(DateTime.Now.Millisecond); var b = new Ellipse(); b.Width = 3; b.Height = 3; byte[] rgb = new byte[2]; random.NextBytes(rgb); Color color = new Color() { A = 255, B = 0, G = rgb[0], R = rgb[1] };//Color color = Color.FromArgb(0, 0, 0, 0); b.Fill = new System.Windows.Media.SolidColorBrush(color); Point p = e.GetPosition(canvas1); int xn = (int)p.X; int yn = (int)p.Y; b.SetValue(Canvas.LeftProperty, p.X); b.SetValue(Canvas.TopProperty, p.Y); b.Name = cont.ToString(); b.Cursor = Cursors.Hand; canvas1.Children.Add(b); Nodo nodo = new Nodo(xn, yn); nodos.Add(nodo); ser.InsertNodeAsync(cont, xn, yn); cont++; }
private void button_Click(object sender, RoutedEventArgs e) { // variable para crear aleatoriedad basica Random random = new Random(DateTime.Now.Millisecond); if (textBox3.Text == "") { MessageBox.Show("Ingrese el numero de nodos!"); return; } int n = int.Parse(textBox3.Text.ToString()); canvas1.Height = 19000;//1009000 para 1000000 //19000 para 100000 canvas1.Width = 19000;//19000 para 1000000 int i=1; for (; i < n; i++){ var b = new Ellipse(); b.Width = 3; b.Height = 3; // asignar el color del nodo b.Fill = new System.Windows.Media.SolidColorBrush(Colors.Blue); // posicion aleatoria entre un minimo y un maximo deseado b.SetValue(Canvas.LeftProperty, (double)random.Next(0, 19000)); b.SetValue(Canvas.TopProperty, (double)random.Next(0, 19000)); // establecer nombre y evento b.Name = i.ToString(); // drag and drop //b.MouseLeftButtonDown += new MouseButtonEventHandler(ellipse1_MouseLeftButtonDown); // añadir al cavas la elipse creada canvas1.Children.Add(b); } }
private Shape makeSimpleShape(int numSides, int skip, double size, double spin, Point center, Brush brush, Brush brushStroke, double strokeThickness, double opacity) { if (numSides <= 1) { var circle = new Ellipse(); circle.Width = size * 2; circle.Height = size * 2; circle.Stroke = brushStroke; if (circle.Stroke != null) circle.Stroke.Opacity = opacity; circle.StrokeThickness = strokeThickness * ((numSides == 1) ? 1 : 2); circle.Fill = (numSides == 1) ? brush : null; circle.SetValue(Canvas.LeftProperty, center.X - size); circle.SetValue(Canvas.TopProperty, center.Y - size); return circle; } else { var points = new PointCollection(numSides + 2); double theta = spin; for (int i = 0; i <= numSides + 1; ++i) { points.Add(new Point(Math.Cos(theta) * size + center.X, Math.Sin(theta) * size + center.Y)); theta = theta + 2.0 * Math.PI * skip / numSides; } var polyline = new Polyline(); polyline.Points = points; polyline.Stroke = brushStroke; if (polyline.Stroke != null) polyline.Stroke.Opacity = opacity; polyline.Fill = brush; polyline.FillRule = FillRule.Nonzero; polyline.StrokeThickness = strokeThickness; return polyline; } }
private void AddEllipseOnParentPanel(Point location, bool is_first) { Ellipse el = new Ellipse() { Width = 3.5 * Zoom, Height = 3.5 * Zoom, Stroke = Brushes.BlueViolet, StrokeThickness = 0.7 * Zoom, Fill = Brushes.White, Tag = is_first }; el.SetValue(Canvas.TopProperty, location.Y * Zoom); el.SetValue(Canvas.LeftProperty, location.X * Zoom); GraphPanel.Children.Add(el); elList.Add(el); }
private void Paint(Size size) { try { var width = size.Width; // _canvas 有margin 所以要减去 _canvas.Children.Clear(); var background1 = new Border(); background1.BorderThickness = new Thickness(1d, 1d, 1d, 0d); background1.BorderBrush = new SolidColorBrush(Color.FromArgb(0xff, 0x74, 0x6A, 0x59)); background1.Background = new SolidColorBrush(Colors.White); background1.SetValue(Canvas.LeftProperty, width * 39d / 657d); background1.SetValue(Canvas.TopProperty, width * 42d / 657d); background1.Width = width * 579d / 657d; background1.Height = width * 343d / 657d; _canvas.Children.Add(background1); var brush1 = new SolidColorBrush(Colors.White); var brush2 = new SolidColorBrush(Color.FromArgb(0xff, 0x84, 0x7B, 0x6C)); PaintBorder1(width, brush1, brush2); PaintBorder2(width, brush1, brush2); PaintBorder3(width, brush1, brush2); PaintBorder4(width, brush1, brush2); PaintBorder5(width, brush1, brush2); PaintBorder6(width, brush1, brush2); PaintBorder7(width, brush1, brush2); var ellipse1 = new Ellipse(); ellipse1.SetValue(Canvas.LeftProperty, width * 3.5d / 657d); ellipse1.SetValue(Canvas.TopProperty, width * 136d / 657d); ellipse1.Width = ellipse1.Height = width * 650d / 657d; ellipse1.Stroke = new SolidColorBrush(Color.FromArgb(0xff, 0xAF, 0xAF, 0x00)); ellipse1.StrokeThickness = 3d; ellipse1.Clip = new RectangleGeometry() { Rect = new Rect(0d, 0d, ellipse1.Width, width * 120d / 657d) }; _canvas.Children.Add(ellipse1); PaintCalibration(size); _canvas.Children.Add(_pointLine); var ellipse2 = new Ellipse(); ellipse2.SetValue(Canvas.LeftProperty, width * 199.5d / 657d); ellipse2.SetValue(Canvas.TopProperty, width * 332d / 657d); ellipse2.Width = ellipse2.Height = width * 258d / 657d; ellipse2.Fill = new SolidColorBrush(Colors.Black); ellipse2.Clip = new RectangleGeometry() { Rect = new Rect(0d, 0d, ellipse2.Width, width * 50d / 657d) }; _canvas.Children.Add(ellipse2); } catch { } }