static void Main(string[] args) { Console.WriteLine("Введите количество фигур: "); int n = Convert.ToInt32(Console.ReadLine()); Random rand = new Random(); Ellipse[] ellipse = new Ellipse[n]; for (int i = 0; i < ellipse.Length; i++) { ellipse[i] = new Ellipse(); ellipse[i].VerticalRad = rand.Next(1, 100); ellipse[i].HorisontalRad = rand.Next(1, 100); Console.WriteLine("Эллипс по номером: {0}", i); Console.WriteLine(""); ellipse[i].print(); Console.WriteLine(""); } int minP = 0; int minS = 0; for (int i = 1; i < ellipse.Length; i++) { if (ellipse[minS].GetSquare() > ellipse[i].GetSquare()) minS = i; if (ellipse[minP].GetPerimetr() > ellipse[i].GetPerimetr()) minP = i; } Console.WriteLine("Минимальный периметр у эллипса №{0} с параметрами: а = {1}, b = {2}", minP, ellipse[minP].HorisontalRad, ellipse[minP].VerticalRad); Console.WriteLine("Минимальная площадь у эллипса №{0} с параметрами: а = {1}, b = {2}", minS, ellipse[minS].HorisontalRad, ellipse[minS].VerticalRad); Console.ReadKey(); }
public void RenderedGeometry () { Ellipse e = new Ellipse (); Geometry g = e.RenderedGeometry; StreamGeometry stream_geometry = (StreamGeometry)g; Assert.AreEqual (stream_geometry.ToString (), ""); }
public void RenderingHiddenEllipseDoesNotThrowException() { var ellipse = new Ellipse(Vector2D.Half, 0.4f, 0.2f, Color.Red); ellipse.Add(new OutlineColor(Color.Yellow)); ellipse.OnDraw<DrawPolygon2DOutlines>(); Assert.DoesNotThrow(() => AdvanceTimeAndUpdateEntities()); }
public static Ellipse CreateEllipse(double x, double y, double w, double h) { double x2 = x + w; double y2 = y + h; var ellipse = new Ellipse { Margin = new Thickness(x, y, x2, y2), Width = Math.Abs(x2 - x), Height = Math.Abs(y2 - y) }; return ellipse; }
/// <summary> /// Initializes a new instance of the <see cref="EllipseRenderUnit" /> class. /// </summary> /// <param name="ellipse">The ellipse.</param> /// <param name="stroke">The stroke.</param> /// <param name="fill">The fill.</param> /// <param name="thickness">The thickness.</param> public EllipseRenderUnit(Ellipse ellipse, Brush stroke, Brush fill, float thickness) { this.ellipse = ellipse; this.bounds = new RectangleF(ellipse.Point.X - ellipse.RadiusX, ellipse.Point.Y - ellipse.RadiusY, ellipse.RadiusX * 2, ellipse.RadiusY * 2); this.stroke = stroke; this.fill = fill; this.thickness = thickness; }
internal EllipseShape(Paint2DForm parent, Ellipse ellipse, float strokeWidth, int selectedBrush, bool fill) : base(parent, fill) { _startPoint = ellipse.Point; _ellipse = ellipse; _strokeWidth = strokeWidth; _selectedBrushIndex = selectedBrush; }
public void RadiusIsAlwaysTheMaximumValue() { const float BigValue = 0.4f; const float SmallValue = 0.2f; var ellipseWidth = new Ellipse(Vector2D.Half, BigValue, SmallValue, Color.Red); var ellipseHeight = new Ellipse(Vector2D.Half, SmallValue, BigValue, Color.Red); Assert.AreEqual(BigValue, ellipseWidth.Radius); Assert.AreEqual(BigValue, ellipseHeight.Radius); }
public void RenderingPolygonWithNoPointsDoesNotError() { var ellipse = new Ellipse(Vector2D.Half, 0.4f, 0.2f, Color.Blue); var points = ellipse.Get<List<Vector2D>>(); points.Clear(); ellipse.Remove<Ellipse.UpdatePointsIfRadiusChanges>(); ellipse.Add(new OutlineColor(Color.Red)); ellipse.OnDraw<DrawPolygon2DOutlines>(); }
/// <summary> /// Determines if an ellipse and a rectangle intersect. /// </summary> /// <param name="ellipse">The ellipse.</param> /// <param name="rectangle">The rectangle.</param> /// <returns></returns> public static bool EllipseRectangleTest(Ellipse ellipse, OrthoRectangle rectangle) { bool testXpos = (ellipse.Center.X + ellipse.RadiusX) > rectangle.Right; bool testXneg = (ellipse.Center.X - ellipse.RadiusX) < rectangle.Left; bool testYpos = (ellipse.Center.Y + ellipse.RadiusY) > rectangle.Top; bool testYneg = (ellipse.Center.Y - ellipse.RadiusY) < rectangle.Bottom; return testXpos || testXneg || testYpos || testYneg; }
private void add(Grid grid, int row, int column) { Ellipse dot = new Ellipse(); dot.Width = 20; dot.Height = 20; dot.Fill = new SolidColorBrush(Colors.White); dot.SetValue(Grid.ColumnProperty, column); dot.SetValue(Grid.RowProperty, row); grid.Children.Add(dot); }
public void RenderingWithEntityHandlersInAnyOrder() { var ellipse1 = new Ellipse(Vector2D.Half, 0.4f, 0.2f, Color.Blue) { RenderLayer = 0 }; ellipse1.Add(new OutlineColor(Color.Red)); ellipse1.OnDraw<DrawPolygon2D>(); ellipse1.OnDraw<DrawPolygon2DOutlines>(); var ellipse2 = new Ellipse(Vector2D.Half, 0.1f, 0.2f, Color.Green) { RenderLayer = 1 }; ellipse2.Add(new OutlineColor(Color.Red)); ellipse2.OnDraw<DrawPolygon2DOutlines>(); ellipse2.OnDraw<DrawPolygon2D>(); }
public void ManuallySetTheRadius() { const float OriginalRadius = 0.2f; const float NewRadius = 0.4f; var ellipse = new Ellipse(Vector2D.Half, OriginalRadius, OriginalRadius, Color.Red); Assert.AreEqual(OriginalRadius, ellipse.RadiusX); Assert.AreEqual(OriginalRadius, ellipse.RadiusY); ellipse.Radius = NewRadius; Assert.AreEqual(NewRadius, ellipse.RadiusX); Assert.AreEqual(NewRadius, ellipse.RadiusY); }
/// <summary> /// 构造函数 /// </summary> /// <param name="elp">椭球类型</param> /// <param name="a">椭球参数a(如果为自定义的椭球)</param> /// <param name="b">椭球参数b(如果为自定义的椭球)</param> public CoordinateTrans(Ellipse elp,double a=0,double b=0) { ep = new Ellipsoid(); switch (elp) { case Ellipse.International1975: ep.International_ellipsoid1975(); break; case Ellipse.WGS84: ep.WGS84_ellipsoid(); break; case Ellipse.CGCS2000: ep.CGCS2000_ellipsoid(); break; case Ellipse.Other: ep = new Ellipsoid(a, b); break; } }
/// <summary> /// Clones this instance. /// </summary> /// <returns> /// The same shape /// </returns> /// <exception cref="System.NotImplementedException"></exception> public override ShapeBase Clone() { var shape = new Ellipse { Location = Location, Size = Size, DrawMethod = DrawMethod, OutlineColor = OutlineColor, OutlineWidth = OutlineWidth, FillColor = FillColor }; return shape; }
public RecordButton() { var s = new Ellipse() { VerticalAlignment = System.Windows.VerticalAlignment.Center, HorizontalAlignment = System.Windows.HorizontalAlignment.Center, Width = 12, Height = 12, Fill = Brushes.Red, }; this.ShapeContainerGrid.Children.Add(s); }
public EllipseShape(RenderTarget initialRenderTarget, Random random, D2DFactory d2DFactory, D2DBitmap bitmap) : base(initialRenderTarget, random, d2DFactory, bitmap) { ellipse = RandomEllipse(); double which = Random.NextDouble(); if (which < 0.67) PenBrush = RandomBrush(); if (which > 0.33) FillBrush = RandomBrush(); if (CoinFlip) StrokeStyle = RandomStrokeStyle(); StrokeWidth = RandomStrokeWidth(); }
public override void Draw(UIElementCollection collection) { Ellipse ellipse; if (DrawedElement == null) ellipse = new Ellipse(); else ellipse = (Ellipse)DrawedElement; UpdateProperties(ellipse); LocateShapeOnCanvas(ellipse); if (DrawedElement == null) collection.Add(ellipse); DrawedElement = ellipse; }
public void RenderedGeometryInWindow () { Window w = new Window (); Ellipse e = new Ellipse (); e.Width = 100; e.Height = 100; w.Content = e; w.Show (); Geometry g = e.RenderedGeometry; EllipseGeometry ellipse_geometry = (EllipseGeometry)g; Assert.AreEqual (ellipse_geometry.Bounds.Width, 100, "1"); DrawingGroup drawing_group = VisualTreeHelper.GetDrawing (e); Assert.IsNull (drawing_group, "2"); }
/// <summary> /// Create a visual for single Series Part /// </summary> /// <returns> /// UIElement /// </returns> public override UIElement CreatePart() { Ellipse = new Ellipse(); Binding heightBinding = new Binding {Path = new PropertyPath("Size"), Source = this}; Ellipse.SetBinding(Ellipse.HeightProperty, heightBinding); Binding widthBinding = new Binding {Path = new PropertyPath("Size"), Source = this}; Ellipse.SetBinding(Ellipse.WidthProperty, widthBinding); Canvas.SetLeft(Ellipse, X1 - (Ellipse.Width / 2)); Canvas.SetTop(Ellipse, Y1 - (Ellipse.Height / 2)); SetBindingForStrokeandStrokeThickness(Ellipse); return Ellipse; }
public static bool EllipsePointTest(Ellipse ellipse, Vector2D point) { double x = point.X; double y = point.Y; double a = ellipse.RadiusX; double b = ellipse.RadiusY; double xComponent = (Math.Pow(point.X - ellipse.Center.X, 2) / Math.Pow(ellipse.RadiusX, 2)); double yComponent = (Math.Pow(point.Y - ellipse.Center.Y, 2) / Math.Pow(ellipse.RadiusY, 2)); double value = xComponent + yComponent; if (value < 1) return true; return false; }
internal static async Task Render(CompositionEngine compositionEngine, SharpDX.Direct2D1.RenderTarget renderTarget, FrameworkElement rootElement, Ellipse ellipse) { var rect = ellipse.GetBoundingRect(rootElement).ToSharpDX(); var d2dEllipse = new D2D.Ellipse( new Vector2( (float)((rect.Left + rect.Right) * 0.5), (float)((rect.Top + rect.Bottom) * 0.5)), (float)(0.5 * rect.Width), (float)(0.5 * rect.Height)); var fill = await ellipse.Fill.ToSharpDX(renderTarget, rect); var layer = ellipse.CreateAndPushLayerIfNecessary(renderTarget, rootElement); var stroke = await ellipse.Stroke.ToSharpDX(renderTarget, rect); if (ellipse.StrokeThickness > 0 && stroke != null) { var halfStrokeThickness = (float)(ellipse.StrokeThickness * 0.5); d2dEllipse.RadiusX -= halfStrokeThickness; d2dEllipse.RadiusY -= halfStrokeThickness; if (fill != null) { renderTarget.FillEllipse(d2dEllipse, fill); } renderTarget.DrawEllipse( d2dEllipse, stroke, (float)ellipse.StrokeThickness, ellipse.GetStrokeStyle(compositionEngine.D2DFactory)); } else if (fill != null) { renderTarget.FillEllipse(d2dEllipse, fill); } if (layer != null) { renderTarget.PopLayer(); layer.Dispose(); } }
internal static void Render(CompositionEngine compositionEngine, SharpDX.Direct2D1.RenderTarget renderTarget, FrameworkElement rootElement, Ellipse ellipse) { var rect = ellipse.GetBoundingRect(rootElement).ToSharpDX(); var d2dEllipse = new D2D.Ellipse( new DrawingPointF( (float)((rect.Left + rect.Right) * 0.5), (float)((rect.Top + rect.Bottom) * 0.5)), (float)(0.5 * rect.Width), (float)(0.5 * rect.Height)); var fill = ellipse.Fill.ToSharpDX(renderTarget, rect); //var layer = new Layer(renderTarget); //var layerParameters = new LayerParameters(); //layerParameters.ContentBounds = rect; //renderTarget.PushLayer(ref layerParameters, layer); var stroke = ellipse.Stroke.ToSharpDX(renderTarget, rect); if (ellipse.StrokeThickness > 0 && stroke != null) { var halfStrokeThickness = (float)(ellipse.StrokeThickness * 0.5); d2dEllipse.RadiusX -= halfStrokeThickness; d2dEllipse.RadiusY -= halfStrokeThickness; if (fill != null) { renderTarget.FillEllipse(d2dEllipse, fill); } renderTarget.DrawEllipse( d2dEllipse, stroke, (float)ellipse.StrokeThickness, ellipse.GetStrokeStyle(compositionEngine.D2DFactory)); } else if (fill != null) { renderTarget.FillEllipse(d2dEllipse, fill); } //renderTarget.PopLayer(); }
public void Draw(ref StackPanel Stack) { Stack.Children.Clear(); foreach (int number in numbers()) { Canvas container = new Canvas(); Ellipse ball = new Ellipse(); TextBlock text = new TextBlock(); container.Margin = new Thickness(2); container.Width = 48; container.Height = 48; ball.Width = container.Width; ball.Height = container.Height; ball.Stroke = new SolidColorBrush(Colors.Black); if (number >= 1 && number <= 9) { ball.Fill = new SolidColorBrush(Colors.White); } else if (number >= 10 && number <= 19) { ball.Fill = new SolidColorBrush(Color.FromArgb(255, 112, 200, 236)); } else if (number >= 20 && number <= 29) { ball.Fill = new SolidColorBrush(Colors.Magenta); } else if (number >= 30 && number <= 39) { ball.Fill = new SolidColorBrush(Color.FromArgb(255, 112, 255, 0)); } else if (number >= 40 && number <= 49) { ball.Fill = new SolidColorBrush(Colors.Yellow); } container.Children.Add(ball); text.Foreground = new SolidColorBrush(Colors.Black); text.FontSize = 16; text.Text = number.ToString(); text.Margin = new Thickness(16, 12, 16, 12); container.Children.Add(text); Stack.Children.Add(container); } }
public void DrawTesting(ref StackPanel Stack, ref List<int> l) { Stack.Children.Clear(); foreach (int number in l) { Canvas container = new Canvas(); Ellipse ball = new Ellipse(); TextBlock text = new TextBlock(); container.Margin = new Thickness(2); container.Width = 62; container.Height = 62; ball.Width = container.Width; ball.Height = container.Height; if (number >= 1 && number <= 9) { ball.Fill = new SolidColorBrush(Colors.Red); } else if (number >= 10 && number <= 19) { ball.Fill = new SolidColorBrush(Colors.Yellow); } else if (number >= 20 && number <= 29) { ball.Fill = new SolidColorBrush(Colors.Magenta); } else if (number >= 30 && number <= 39) { ball.Fill = new SolidColorBrush(Colors.Green); } else { ball.Fill = new SolidColorBrush(Colors.Blue); } container.Children.Add(ball); text.Foreground = new SolidColorBrush(Colors.Black); text.FontSize = 18; text.Text = number.ToString(); text.Margin = new Thickness(15); container.Children.Add(text); Stack.Children.Add(container); } }
public void RenderedGeometryInWindowFillStroke () { Window w = new Window (); Ellipse e = new Ellipse (); e.Fill = Brushes.Red; e.Stroke = Brushes.Blue; e.Width = 100; e.Height = 100; w.Content = e; w.Show (); EllipseGeometry rendered_geometry = (EllipseGeometry)e.RenderedGeometry; Assert.AreEqual (rendered_geometry.Bounds, new Rect (0.5, 0.5, 99, 99), "1"); DrawingGroup drawing_group = VisualTreeHelper.GetDrawing (e); Assert.AreEqual (drawing_group.Children.Count, 1, "2"); EllipseGeometry drawing_geometry = (EllipseGeometry)((GeometryDrawing)drawing_group.Children [0]).Geometry; Assert.AreNotSame (rendered_geometry, drawing_geometry, "3"); Assert.AreEqual (drawing_geometry.Bounds, new Rect (0.5, 0.5, 99, 99), "4"); }
static void Main() { Shape r1 = new Round(15.0); Console.WriteLine(r1.ToString()); Shape k1 = new Ellipse(15.0,7.0); Console.WriteLine(k1.ToString()); Shape a1 = new Diamond(10.0 , 2.0); Console.WriteLine(a1.ToString()); Shape b1 = new Parallelogram(10.0 , 7.0 , 3.0); Console.WriteLine(b1.ToString()); Shape c1 = new Rectangle(10.0 , 5.0); Console.WriteLine(c1.ToString()); Shape d1 = new Square(10.0); Console.WriteLine(d1.ToString()); Shape f1 = new Triangle(10.0 ,5.0,7.0); Console.WriteLine(f1.ToString()); Shape trap1 = new Trapezoid(5, 6, 7, 8, 10); Console.WriteLine(trap1.ToString()); try { Shape tr1 = new Triangle(5.0, 4.0, 10.0); Console.WriteLine(tr1.ToString()); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public static Shape CreatePointShape() { //FrameworkElement result = new PointShape(); //container.Children.Add(result); //return result; int size = 8; Ellipse ellipse = new Ellipse() { Width = size, Height = size, Fill = new SolidColorBrush(Colors.LightYellow), BitmapEffect = new DropShadowBitmapEffect() { ShadowDepth = 4, Opacity = 0.7 //Softness = 0.5 }, Stroke = Brushes.Black, StrokeThickness = 0.5 }; return ellipse; }
public void EllipseConstructor_Test(double a, double b) { IShape ellipse = new Ellipse(a, b); }
void Reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e) { var reference = e.FrameReference.AcquireFrame(); // Color using (var frame = reference.ColorFrameReference.AcquireFrame()) { if (frame != null) { camera.Source = frame.ToBitmap(); } } // Body using (var frame = reference.BodyFrameReference.AcquireFrame()) { if (frame != null) { canvas.Children.Clear(); _bodies = new Body[frame.BodyFrameSource.BodyCount]; frame.GetAndRefreshBodyData(_bodies); for (int i = 0; i < _bodies.Count; i++) { var body = _bodies[i]; double fx = 0, fy = 0, hx = 0, hy = 0; if (body != null && body.TrackingId != 0) { Ellipse rhandellip = new Ellipse { Width = 40, Height = 40, Fill = new SolidColorBrush(Colors.Red), Opacity = 0.7 }; if (body.IsTracked) { // Find the joints Joint handRight = body.Joints[JointType.HandRight]; Joint thumbRight = body.Joints[JointType.ThumbRight]; Joint handLeft = body.Joints[JointType.HandLeft]; Joint thumbLeft = body.Joints[JointType.ThumbLeft]; // Draw hands and thumbs /*canvas.DrawHand(handRight, _sensor.CoordinateMapper); * canvas.DrawHand(handLeft, _sensor.CoordinateMapper); * canvas.DrawThumb(thumbRight, _sensor.CoordinateMapper); * canvas.DrawThumb(thumbLeft, _sensor.CoordinateMapper);*/ // Find the hand states string rightHandState = "-"; string leftHandState = "-"; Ellipse headellip = new Ellipse { Width = 800, Height = 800, Fill = new SolidColorBrush(Colors.Orange), Opacity = 0.7 }; // hx = handRight.Position.X * 1000 + 900; hy = -handRight.Position.Y * 1000 + 800; fx = handRight.Position.X; hx = 500 + fx * 3000; fy = handRight.Position.Y; //tblRightHandState.Text = rightHandState + "\n" + fx.ToString() + "\n" + fy.ToString(); //tblLeftHandState.Text = leftHandState; switch (body.HandRightState) { case HandState.Open: rhandellip.Fill = new SolidColorBrush(Colors.Red); atkState[body.TrackingId] = 1; break; case HandState.Closed: rhandellip.Fill = new SolidColorBrush(Colors.Green); atkState[body.TrackingId] = 2; break; case HandState.Lasso: rhandellip.Fill = new SolidColorBrush(Colors.Yellow); atkState[body.TrackingId] = 3; break; case HandState.Unknown: atkState[body.TrackingId] = 0; break; case HandState.NotTracked: break; default: break; } /* * switch (body.HandLeftState) * { * case HandState.Open: * break; * case HandState.Closed: * break; * case HandState.Lasso: * break; * case HandState.Unknown: * break; * case HandState.NotTracked: * break; * default: * break; * }*/ try { int a = health[body.TrackingId]; } catch { health.Add(body.TrackingId, 400); newchlcount = 0; } try { int a = atkState[body.TrackingId]; } catch { atkState.Add(body.TrackingId, 0); } try { int a = charge[body.TrackingId]; } catch { charge.Add(body.TrackingId, 0); } /*try * { * int a = atkChange[body.TrackingId]; * } * catch * { * atkChange.Add(body.TrackingId, 0); * }*/ //if (atkChange[body.TrackingId] == 1) //{ //} } var headJoint = body.Joints[JointType.Head].Position; CameraSpacePoint pt = new CameraSpacePoint() { X = headJoint.X, Y = headJoint.Y, Z = headJoint.Z }; ColorSpacePoint clpt = this.coordinateMapper.MapCameraPointToColorSpace(pt); clpt1 = this.coordinateMapper.MapCameraPointToColorSpace(pt); facex[i] = clpt.X; facey[i] = clpt.Y; fx -= headJoint.X; fy -= headJoint.Y; Rectangle headbox = new Rectangle { Width = 100, Height = 100, //Fill = new SolidColorBrush(Colors.Orange), Opacity = 0 }; saveWidth = headbox.Width; saveHeight = headbox.Height; Rectangle healthbar = new Rectangle { Width = health[body.TrackingId], //Width = 100, Height = 40, Fill = new SolidColorBrush(Colors.Green), Opacity = 0.7 }; Rectangle chargebar = new Rectangle { Width = charge[body.TrackingId], //Width = 100, Height = 40, Fill = new SolidColorBrush(Colors.Yellow), Opacity = 0.7 }; charge[body.TrackingId] += 3; if (charge[body.TrackingId] > 400) { charge[body.TrackingId] = 400; } if (atkState[body.TrackingId] == 1) { for (int j = 0; j < _bodies.Count; j++) { if (((facex[j] < (40 + 600 + fx * 2000)) && ((facex[j] + 100) > (600 + fx * 2000))) && ((facey[j] < (40 + hy - 200)) && ((facey[j] + 100) > (hy - 200)))) { try { if (atkState[_bodies[j].TrackingId] == 2) { health[_bodies[j].TrackingId] += 20; } else { health[_bodies[j].TrackingId] -= 5; if (health[_bodies[j].TrackingId] <= 0) { health[_bodies[j].TrackingId] = 0; } } } catch { try { health.Add(_bodies[j].TrackingId, 370); } catch { } } } } } if (atkState[body.TrackingId] == 2) { health[body.TrackingId] -= 1; if (health[body.TrackingId] < 0) { health[body.TrackingId] = 0; } } if (atkState[body.TrackingId] == 3) { for (int j = 0; j < _bodies.Count; j++) { if (((facex[j] < (40 + 600 + fx * 2000)) && ((facex[j] + 100) > (600 + fx * 2000))) && ((facey[j] < (40 + hy - 200)) && ((facey[j] + 100) > (hy - 200)))) { try { if (atkState[_bodies[j].TrackingId] == 2) { health[_bodies[j].TrackingId] -= charge[body.TrackingId] / 8; charge[body.TrackingId] = 0; } health[_bodies[j].TrackingId] -= charge[body.TrackingId] / 2; if (health[_bodies[j].TrackingId] <= 0) { health[_bodies[j].TrackingId] = 0; } charge[body.TrackingId] = 0; } catch { try { charge.Add(_bodies[j].TrackingId, 0); } catch { } } } charge[body.TrackingId] /= 2; } //charge[body.TrackingId] = 0; } string Testing = "right hand"; string Facetesting = "Face"; // tblRightHandState.Text = Testing + "\n" + (500 + fx * 3000).ToString() + "\n" + hy.ToString(); //tblLeftHandState.Text = Facetesting + "\n" + (clpt.X - headbox.Width / 2).ToString() + "\n" + (clpt.Y - headbox.Height / 2).ToString(); try { Canvas.SetLeft(rhandellip, 600 + fx * 2000); Canvas.SetTop(rhandellip, hy - 200); canvas.Children.Add(rhandellip); Canvas.SetLeft(headbox, clpt.X - headbox.Width / 2); Canvas.SetTop(headbox, clpt.Y - headbox.Height / 2); canvas.Children.Add(headbox); Canvas.SetLeft(healthbar, clpt.X - healthbar.Width / 2); Canvas.SetTop(healthbar, clpt.Y - 100 - headbox.Height / 2); canvas.Children.Add(healthbar); Canvas.SetLeft(chargebar, clpt.X - healthbar.Width / 2); Canvas.SetTop(chargebar, clpt.Y - 55 - headbox.Height / 2); canvas.Children.Add(chargebar); if (healthbar.Width == 0) { BitmapImage image = new BitmapImage(); image.BeginInit(); image.UriSource = new Uri("bomb.jpg", UriKind.RelativeOrAbsolute); image.EndInit(); ImageBrush myImageBrush = new ImageBrush(image); Canvas myCanvas = new Canvas(); myCanvas.Width = 300; myCanvas.Height = 300; myCanvas.Background = myImageBrush; Canvas.SetLeft(myCanvas, clpt.X - headbox.Width / 2 - (myCanvas.Width / 2)); Canvas.SetTop(myCanvas, clpt.Y - headbox.Height / 2 - (myCanvas.Width / 2)); canvas.Children.Add(myCanvas); chargebar.Width = 0; } } catch { } } } if (gameState == 1) { if (count1 < 100) { BitmapImage image = new BitmapImage(); image.BeginInit(); image.UriSource = new Uri("start.jpg", UriKind.RelativeOrAbsolute); image.EndInit(); ImageBrush myImageBrush = new ImageBrush(image); Canvas myCanvas = new Canvas(); myCanvas.Width = 1000; myCanvas.Height = 200; myCanvas.Background = myImageBrush; Canvas.SetLeft(myCanvas, 500); Canvas.SetTop(myCanvas, 700); canvas.Children.Add(myCanvas); count1++; newchlcount = 0; if (newchlcount < 50) { BitmapImage image1 = new BitmapImage(); image1.BeginInit(); image1.UriSource = new Uri("troll.png", UriKind.RelativeOrAbsolute); image1.EndInit(); ImageBrush myImageBrush1 = new ImageBrush(image1); Canvas myCanvas1 = new Canvas(); myCanvas1.Width = 150; myCanvas1.Height = 150; myCanvas1.Background = myImageBrush1; Canvas.SetLeft(myCanvas1, clpt1.X - this.saveWidth / 2 - (myCanvas1.Width / 2)); Canvas.SetTop(myCanvas1, clpt1.Y - this.saveHeight / 2 - (myCanvas1.Width / 2)); canvas.Children.Add(myCanvas1); newchlcount++; } } else { gameState = 0; } } else { if (newchlcount < 100 && gameState == 0) { BitmapImage image = new BitmapImage(); image.BeginInit(); image.UriSource = new Uri("challenge.png", UriKind.RelativeOrAbsolute); image.EndInit(); ImageBrush myImageBrush = new ImageBrush(image); Canvas myCanvas = new Canvas(); myCanvas.Width = 1000; myCanvas.Height = 200; myCanvas.Background = myImageBrush; Canvas.SetLeft(myCanvas, 500); Canvas.SetTop(myCanvas, 700); canvas.Children.Add(myCanvas); newchlcount++; int newchlcount1 = 0; if (newchlcount1 < 50) { BitmapImage image1 = new BitmapImage(); image1.BeginInit(); image1.UriSource = new Uri("troll.png", UriKind.RelativeOrAbsolute); image1.EndInit(); ImageBrush myImageBrush1 = new ImageBrush(image1); Canvas myCanvas1 = new Canvas(); myCanvas1.Width = 150; myCanvas1.Height = 150; myCanvas1.Background = myImageBrush1; Canvas.SetLeft(myCanvas1, clpt1.X - this.saveWidth / 2 - (myCanvas1.Width / 2)); Canvas.SetTop(myCanvas1, clpt1.Y - this.saveHeight / 2 - (myCanvas1.Width / 2)); canvas.Children.Add(myCanvas1); newchlcount1++; } } } } } }
public override void DrawOrMove(ChartPoint previousDrawn, ChartPoint current, int index, ChartCore chart) { if (IsNew) { Canvas.SetTop(Ellipse, current.ChartLocation.Y); Canvas.SetLeft(Ellipse, current.ChartLocation.X); Ellipse.Width = 0; Ellipse.Height = 0; if (DataLabel != null) { Canvas.SetTop(DataLabel, current.ChartLocation.Y); Canvas.SetLeft(DataLabel, current.ChartLocation.X); } } if (HoverShape != null) { HoverShape.Width = Diameter; HoverShape.Height = Diameter; Canvas.SetLeft(HoverShape, current.ChartLocation.X - Diameter / 2); Canvas.SetTop(HoverShape, current.ChartLocation.Y - Diameter / 2); } if (chart.View.DisableAnimations) { Ellipse.Width = Diameter; Ellipse.Height = Diameter; Canvas.SetTop(Ellipse, current.ChartLocation.Y - Ellipse.Width * .5); Canvas.SetLeft(Ellipse, current.ChartLocation.X - Ellipse.Height * .5); if (DataLabel != null) { DataLabel.UpdateLayout(); var cx = CorrectXLabel(current.ChartLocation.X - DataLabel.ActualHeight * .5, chart); var cy = CorrectYLabel(current.ChartLocation.Y - DataLabel.ActualHeight * .5, chart); Canvas.SetTop(DataLabel, cy); Canvas.SetLeft(DataLabel, cx); } return; } var animSpeed = chart.View.AnimationsSpeed; if (DataLabel != null) { DataLabel.UpdateLayout(); var cx = CorrectXLabel(current.ChartLocation.X - DataLabel.ActualWidth * .5, chart); var cy = CorrectYLabel(current.ChartLocation.Y - DataLabel.ActualHeight * .5, chart); DataLabel.BeginAnimation(Canvas.LeftProperty, new DoubleAnimation(cx, animSpeed)); DataLabel.BeginAnimation(Canvas.TopProperty, new DoubleAnimation(cy, animSpeed)); } Ellipse.BeginAnimation(FrameworkElement.WidthProperty, new DoubleAnimation(Diameter, animSpeed)); Ellipse.BeginAnimation(FrameworkElement.HeightProperty, new DoubleAnimation(Diameter, animSpeed)); Ellipse.BeginAnimation(Canvas.TopProperty, new DoubleAnimation(current.ChartLocation.Y - Diameter * .5, animSpeed)); Ellipse.BeginAnimation(Canvas.LeftProperty, new DoubleAnimation(current.ChartLocation.X - Diameter * .5, animSpeed)); }
private void stopPainting_mlbu(object sender, MouseButtonEventArgs e) { Canvas plotno = (Canvas)sender; stopXY = e.GetPosition(plotno); info_l.Content += ("\nStop X: " + stopXY.X + " Y: " + stopXY.Y); if (clickTool_rb.IsChecked == true) { clicked = null; var mouseWasDownOn = e.Source as FrameworkElement; if (mouseWasDownOn != null) { string elementName = mouseWasDownOn.Name; foreach (Shape child in canvasExerciseOne_c.Children) { if (child.Name == elementName) { clicked = child; break; } } } shapeName_tb.Text = ""; shapeX1_tb.Text = ""; shapeY1_tb.Text = ""; shapeX2_tb.Text = ""; shapeY2_tb.Text = ""; shapeHeight_tb.Text = ""; shapeWidth_tb.Text = ""; if (clicked == null) { } else if (clicked.GetType().ToString() == "System.Windows.Shapes.Line") { Line tmp = (Line)clicked; shapeName_tb.Text = tmp.Name; shapeX1_tb.Text = tmp.X1.ToString(); shapeY1_tb.Text = tmp.Y1.ToString(); shapeX2_tb.Text = tmp.X2.ToString(); shapeY2_tb.Text = tmp.Y2.ToString(); } else if (clicked.GetType().ToString() == "System.Windows.Shapes.Ellipse") { Ellipse tmp = (Ellipse)clicked; shapeName_tb.Text = tmp.Name; shapeX1_tb.Text = tmp.Margin.Left.ToString(); shapeY1_tb.Text = tmp.Margin.Top.ToString(); shapeHeight_tb.Text = tmp.Height.ToString(); shapeWidth_tb.Text = tmp.Width.ToString(); } else if (clicked.GetType().ToString() == "System.Windows.Shapes.Rectangle") { Rectangle tmp = (Rectangle)clicked; shapeName_tb.Text = tmp.Name; shapeX1_tb.Text = tmp.Margin.Left.ToString(); shapeY1_tb.Text = tmp.Margin.Top.ToString(); shapeHeight_tb.Text = tmp.Height.ToString(); shapeWidth_tb.Text = tmp.Width.ToString(); } } else if (lineTool_rb.IsChecked == true) { Line myLine = new Line(); myLine.Name = "Line_" + lines.Count; var brush = (Brush)converter.ConvertFromString(color_l.Content.ToString()); myLine.Stroke = brush; myLine.X1 = startXY.X; myLine.X2 = stopXY.X; myLine.Y1 = startXY.Y; myLine.Y2 = stopXY.Y; myLine.HorizontalAlignment = HorizontalAlignment.Left; myLine.VerticalAlignment = VerticalAlignment.Center; myLine.StrokeThickness = 2; canvasExerciseOne_c.Children.Add(myLine); lines.Add(myLine); } else if (circleTool_rb.IsChecked == true) { Point tmp = new Point(); if (startXY.X >= stopXY.X) { tmp.X = startXY.X; } else { tmp.X = stopXY.X; } if (startXY.Y >= stopXY.Y) { tmp.Y = startXY.Y; } else { tmp.Y = stopXY.Y; } Ellipse myEllipse = CreateEllipse(Math.Abs(startXY.X - stopXY.X), Math.Abs(startXY.Y - stopXY.Y), tmp.X, tmp.Y); myEllipse.Name = "Ellipse_" + ellipses.Count; var brush = (Brush)converter.ConvertFromString(color_l.Content.ToString()); myEllipse.Stroke = brush; if (fill_cb.IsChecked == true) { myEllipse.Fill = brush; } myEllipse.HorizontalAlignment = HorizontalAlignment.Left; myEllipse.VerticalAlignment = VerticalAlignment.Center; myEllipse.StrokeThickness = 2; canvasExerciseOne_c.Children.Add(myEllipse); ellipses.Add(myEllipse); } else if (rectangleTool_rb.IsChecked == true) { Point tmp = new Point(); if (startXY.X >= stopXY.X) { tmp.X = startXY.X; } else { tmp.X = stopXY.X; } if (startXY.Y >= stopXY.Y) { tmp.Y = startXY.Y; } else { tmp.Y = stopXY.Y; } Rectangle myRectangle = CreateRectangle(Math.Abs(startXY.X - stopXY.X), Math.Abs(startXY.Y - stopXY.Y), tmp.X, tmp.Y); myRectangle.Name = "Rectangle_" + rectangles.Count; var brush = (Brush)converter.ConvertFromString(color_l.Content.ToString()); myRectangle.Stroke = brush; if (fill_cb.IsChecked == true) { myRectangle.Fill = brush; } myRectangle.HorizontalAlignment = HorizontalAlignment.Left; myRectangle.VerticalAlignment = VerticalAlignment.Center; myRectangle.StrokeThickness = 2; canvasExerciseOne_c.Children.Add(myRectangle); rectangles.Add(myRectangle); } }
/// <summary> /// 获取原点的中心坐标 /// </summary> /// <param name="ellipse"></param> /// <returns></returns> private Point GetCenterPoint(Ellipse ellipse) { Point p = new Point(Canvas.GetLeft(ellipse) + ellipse.Width / 2, Canvas.GetTop(ellipse) + ellipse.Height / 2); return(p); }
//Ellipse public static SpeckleEllipse ToSpeckle(this Ellipse e) { return(new SpeckleEllipse(e.Plane.ToSpeckle(), e.Radius1, e.Radius2)); }
static void RepaintNodeShapes(Canvas nodeCanvas) { Border nodeCanvasBorder = (Border)nodeCanvas.Parent; RemoveNodeShapes(nodeCanvas); NodeCanvasData ncDInst = GetCanvasNodeData(nodeCanvas); Node node = ncDInst.node; Border rectBorder = new Border() { CornerRadius = new CornerRadius(2), BorderThickness = new Thickness(1), BorderBrush = System.Windows.Media.Brushes.Black }; System.Windows.Shapes.Rectangle heirsPivotRect = new System.Windows.Shapes.Rectangle() { Stroke = new SolidColorBrush(Colors.Black), Fill = new SolidColorBrush(Colors.IndianRed), Width = 25, Height = 25 }; Canvas.SetLeft(rectBorder, Canvas.GetLeft(nodeCanvasBorder) + .5f * nodeCanvasBorder.ActualWidth - 12.5f); Canvas.SetTop(rectBorder, Canvas.GetTop(nodeCanvasBorder) + nodeCanvasBorder.ActualHeight); heirsPivotRect.MouseEnter += new MouseEventHandler(canvasRedRect_MouseEnter); heirsPivotRect.MouseLeave += new MouseEventHandler(canvasRedRect_MouseLeave); heirsPivotRect.MouseLeftButtonDown += new MouseButtonEventHandler(canvasRedRect_LeftMouseDown); heirsPivotRect.MouseRightButtonDown += new MouseButtonEventHandler(canvasRedRect_RightMouseDown); rectBorder.Child = heirsPivotRect; workspaceCanvas.Children.Add(rectBorder); Canvas.SetZIndex(rectBorder, 10000); ncDInst.heirsPivot = heirsPivotRect; Ellipse parentPivotEllipse = new Ellipse() { Stroke = new SolidColorBrush(Colors.Black), Fill = new SolidColorBrush(Colors.CadetBlue), Width = 25, Height = 25 }; Canvas.SetLeft(parentPivotEllipse, Canvas.GetLeft(nodeCanvasBorder) + .5f * nodeCanvas.Width - 12.5f); Canvas.SetTop(parentPivotEllipse, Canvas.GetTop(nodeCanvasBorder) - 25); workspaceCanvas.Children.Add(parentPivotEllipse); Canvas.SetZIndex(parentPivotEllipse, 20000); ncDInst.parentPivot = parentPivotEllipse; if (node.heirs != null && node.heirs.Count > 0) { List <Canvas> heirsCanvases = new List <Canvas>(); foreach (Heir heir in node.heirs) { heirsCanvases.Add(curNodesOnLayout.Where(el => el.Value.node.Equals(heir.heirNode)).ToArray()[0].Key); } for (int i = 0; i < heirsCanvases.Count; i++) { Border heirCanvBorder = (Border)heirsCanvases[i].Parent; Polyline newPLine; PointF p0, p1, p2, p3; p1 = new PointF((float)(Canvas.GetLeft(nodeCanvasBorder) + .5f * nodeCanvasBorder.ActualWidth), (float)(Canvas.GetTop(nodeCanvasBorder) + nodeCanvasBorder.ActualHeight + ncDInst.heirsPivot.ActualHeight * .5f)); p2 = new PointF((float)(Canvas.GetLeft(heirCanvBorder) + .5f * (heirCanvBorder).ActualWidth), (float)(Canvas.GetTop(heirCanvBorder) - GetCanvasNodeData(heirsCanvases[i]).parentPivot.ActualHeight * .5f)); if (!nodeCanvasBorder.Equals(heirCanvBorder)) { p0 = new PointF(p1.X, (float)Canvas.GetTop(nodeCanvasBorder)); p3 = new PointF(p2.X, (float)(Canvas.GetTop(heirCanvBorder) + (heirCanvBorder).ActualHeight)); newPLine = RelationsDrawer.ConstructPolyline(p0, p1, p2, p3); } else { p0 = new PointF(p1.X, p1.Y - 100f); p3 = new PointF(p2.X, p2.Y + 100f); newPLine = RelationsDrawer.ConstructPolyline(p0, p1, p2, p3, true); } int midIndex = (int)(newPLine.Points.Count * .5f); AddArrowsToPolyline(newPLine); newPLine.MouseEnter += new MouseEventHandler(relation_MouseEnter); newPLine.MouseLeave += new MouseEventHandler(relation_MouseLeave); System.Windows.Point textBlockPos = newPLine.Points.ToArray()[midIndex]; Border tmpBorder = (Border)GetBranchTextBlock(nodeCanvas, heirsCanvases[i]).Parent; Canvas.SetLeft(tmpBorder, textBlockPos.X - tmpBorder.ActualWidth * .5f); Canvas.SetTop(tmpBorder, textBlockPos.Y); ncDInst.relations.Add(newPLine); workspaceCanvas.Children.Add(newPLine); Canvas.SetZIndex(newPLine, 0); } } }
private void UpdateUI() { // Device Text TextBlock textDeviceText = FindName("DeviceText") as TextBlock; if (PanelEntity.Attributes.ContainsKey("friendly_name")) { textDeviceText.Text = PanelEntity.Attributes["friendly_name"].ToUpper(); } else { textDeviceText.Text = string.Empty; } // Artist Text TextBlock textArtistText = FindName("ArtistText") as TextBlock; if (PanelEntity.Attributes.ContainsKey("media_artist")) { textArtistText.Text = PanelEntity.Attributes["media_artist"].ToUpper(); } else { textArtistText.Text = string.Empty; } // Spotify only has "media_title" TextBlock textTrackText = FindName("TrackText") as TextBlock; if (PanelEntity.Attributes.ContainsKey("media_title")) { textTrackText.Text = PanelEntity.Attributes["media_title"].ToUpper(); } else { textTrackText.Text = string.Empty; } // Bose has "media_track" and "media_title" but we just want the track name so do this after "media_title" if (PanelEntity.Attributes.ContainsKey("media_track")) { textTrackText.Text = PanelEntity.Attributes["media_track"].ToUpper(); } // Media Picture Image imageMedia = this.FindName("MediaImage") as Image; if (PanelEntity.Attributes.ContainsKey("entity_picture")) { if (!string.Equals(PanelEntity.Attributes["entity_picture"], imageMedia.Tag?.ToString(), StringComparison.InvariantCultureIgnoreCase)) { imageMedia.Tag = PanelEntity.Attributes["entity_picture"]; imageMedia.Source = Imaging.LoadImageSource(PanelEntity.Attributes["entity_picture"]); } } else { imageMedia.Source = null; } // Volume BitmapIcon buttonVolumeUp = this.FindName("ButtonVolumeUp") as BitmapIcon; BitmapIcon buttonVolumeDown = this.FindName("ButtonVolumeDown") as BitmapIcon; Line scobblerLine = this.FindName("ScobblerLine") as Line; Line scobblerProgress1 = this.FindName("ScobblerProgress1") as Line; Line scobblerProgress2 = this.FindName("ScobblerProgress2") as Line; if (PanelEntity.HasSupportedFeatures((uint)MediaPlatformSupportedFeatures.VolumeSet) && PanelEntity.Attributes.ContainsKey("volume_level")) { double percentagePrevious = Convert.ToInt16(15 * scobblerProgress1.X2 / scobblerLine.X2) / 15.0; scobblerProgress1.X2 = scobblerLine.X2 * Convert.ToDouble(PanelEntity.Attributes["volume_level"]); scobblerProgress2.X1 = scobblerProgress1.X2 - scobblerProgress2.StrokeThickness; scobblerProgress1.Visibility = Visibility.Visible; scobblerProgress2.Stroke = this.Foreground; EnableButton(buttonVolumeUp, true); EnableButton(buttonVolumeDown, true); buttonVolumeUp.Foreground = this.Foreground; buttonVolumeDown.Foreground = this.Foreground; } else { // Not supported scobblerProgress2.X1 = 0; scobblerProgress1.Visibility = Visibility.Collapsed; scobblerProgress2.Stroke = DisabledButtonBrush; scobblerLine.Tapped -= ScobblerLine_Tapped; scobblerLine.PointerReleased -= Grid_PointerReleased; EnableButton(buttonVolumeUp, false); EnableButton(buttonVolumeDown, false); buttonVolumeUp.Foreground = DisabledButtonBrush; buttonVolumeDown.Foreground = DisabledButtonBrush; } // Play and Pause Toggle BitmapIcon bitmapIconPlay = FindName("ButtonPlay") as BitmapIcon; Ellipse ellipsePlay = FindName("EllipsePlay") as Ellipse; if (PanelEntity.HasSupportedFeatures((uint)MediaPlatformSupportedFeatures.Pause | (uint)MediaPlatformSupportedFeatures.Play)) { Uri uriSource; if (string.Equals(PanelEntity.State, "playing", StringComparison.InvariantCultureIgnoreCase)) { uriSource = new Uri($"ms-appx:///Assets/media/media-pause.png"); } else { uriSource = new Uri($"ms-appx:///Assets/media/media-play.png"); } // By checking URI source before setting it we ensure no image flickering during content refreshes (e.g. multiple volume sets) if (uriSource != bitmapIconPlay.UriSource) { bitmapIconPlay.UriSource = uriSource; } ellipsePlay.Stroke = this.Foreground; bitmapIconPlay.Foreground = this.Foreground; EnableEllipse(ellipsePlay, true); EnableButton(bitmapIconPlay, true); } else { // Not supported ellipsePlay.Stroke = DisabledButtonBrush; bitmapIconPlay.Foreground = DisabledButtonBrush; EnableEllipse(ellipsePlay, false); EnableButton(bitmapIconPlay, false); } // Previous BitmapIcon previousButton = this.FindName("ButtonPrevious") as BitmapIcon; if (PanelEntity.HasSupportedFeatures((uint)MediaPlatformSupportedFeatures.PreviousTack)) { previousButton.Foreground = this.Foreground; EnableButton(previousButton, true); } else { // Not supported previousButton.Foreground = DisabledButtonBrush; EnableButton(previousButton, false); } // Next BitmapIcon nextButton = this.FindName("ButtonNext") as BitmapIcon; if (PanelEntity.HasSupportedFeatures((uint)MediaPlatformSupportedFeatures.NextTrack)) { nextButton.Foreground = this.Foreground; EnableButton(nextButton, true); } else { // Not supported nextButton.Foreground = DisabledButtonBrush; EnableButton(nextButton, false); } // Power Toggle BitmapIcon bitmapIconPower = FindName("ButtonPower") as BitmapIcon; if (PanelEntity.HasSupportedFeatures((uint)MediaPlatformSupportedFeatures.TurnOff | (uint)MediaPlatformSupportedFeatures.TurnOn)) { bitmapIconPower.Foreground = this.Foreground; EnableButton(bitmapIconPower, true); } else { // Not supported bitmapIconPower.Foreground = DisabledButtonBrush; EnableButton(bitmapIconPower, false); } // Source Select ComboBox comboBox = this.FindName("SourceComboBox") as ComboBox; if (PanelEntity.HasSupportedFeatures((uint)MediaPlatformSupportedFeatures.SelectSource) && PanelEntity.Attributes.ContainsKey("source_list")) { // Ensure clean-slate to handle reentry from due to entity update while the control is open comboBox.SelectionChanged -= SourceComboBox_SelectionChanged; comboBox.Items.Clear(); foreach (string item in PanelEntity.Attributes["source_list"]) { comboBox.Items.Add(item); } if (PanelEntity.Attributes.ContainsKey("source")) { comboBox.SelectedItem = Convert.ToString(PanelEntity.Attributes["source"]); comboBox.SelectionChanged += SourceComboBox_SelectionChanged; } comboBox.IsEnabled = true; SourceSelectTextBlock.Foreground = this.Foreground; } else { comboBox.IsEnabled = false; SourceSelectTextBlock.Foreground = DisabledButtonBrush; } }
public void FillCanvasObjects() { double xdelta = canvas.ActualWidth / data.xlines, ydelta = canvas.ActualHeight / data.ylines, x = 0, y = 0; TextBlock txtblk; Line lnblk; Ellipse elblk; if (xdelta > 100) { xdelta = 100; } canvas.Children.Clear(); foreach (BTreeItem itm in data.branches) { y = itm.relY * ydelta; lnblk = new Line { Y2 = y, StrokeThickness = 1, StrokeDashArray = new DoubleCollection(new double[] { 2, 2 }), Stroke = Brushes.Black }; Canvas.SetLeft(lnblk, x); Canvas.SetTop(lnblk, 10); canvas.Children.Add(lnblk); elblk = new Ellipse { Stroke = Brushes.Red, Fill = Brushes.Red, Height = 20, Width = 20 }; Canvas.SetLeft(elblk, x - 10); Canvas.SetTop(elblk, y); canvas.Children.Add(elblk); lnblk = new Line { Y2 = canvas.ActualHeight - y, Stroke = Brushes.Red, StrokeThickness = 5 }; Canvas.SetLeft(lnblk, x); Canvas.SetTop(lnblk, y + 10); canvas.Children.Add(lnblk); if (itm.parent != null) { lnblk = new Line { X2 = xdelta * (itm.relX - itm.parent.relX), Stroke = Brushes.Red, StrokeThickness = 5 }; Canvas.SetLeft(lnblk, itm.parent.relX * xdelta); Canvas.SetTop(lnblk, y + 10); canvas.Children.Add(lnblk); elblk = new Ellipse { Stroke = Brushes.Red, Fill = Brushes.Red, Height = 20, Width = 20 }; Canvas.SetLeft(elblk, itm.parent.relX * xdelta - 10); Canvas.SetTop(elblk, y); canvas.Children.Add(elblk); } foreach (var ch in itm.Items) { var locY = ch.CreationDate.Subtract(itm.CreationDate).TotalDays *ydelta; elblk = new Ellipse { Stroke = Brushes.Blue, Fill = Brushes.Blue, Height = 10, Width = 10 }; Canvas.SetLeft(elblk, x - 5); Canvas.SetTop(elblk, y + locY); canvas.Children.Add(elblk); txtblk = new TextBlock { Text = ch.ChangesetId.ToString(), FontSize = 8 }; Canvas.SetLeft(txtblk, x + 5); Canvas.SetTop(txtblk, y + locY + 5); canvas.Children.Add(txtblk); } foreach (var relbr in itm.RelatedBranches) { foreach (var ch in relbr.Item2) { var locY = ch.CreationDate.Subtract(itm.CreationDate).TotalDays *ydelta; lnblk = new Line { X2 = xdelta * Math.Abs(itm.relX - relbr.Item1.relX), StrokeThickness = 1, StrokeDashArray = new DoubleCollection(new double[] { 2, 2 }), Stroke = Brushes.Black }; Canvas.SetLeft(lnblk, Math.Min(itm.relX, relbr.Item1.relX) * xdelta); Canvas.SetTop(lnblk, y + locY + 5); canvas.Children.Add(lnblk); } } txtblk = new TextBlock { Text = itm.Path, FontSize = 8 }; Canvas.SetLeft(txtblk, x); Canvas.SetTop(txtblk, y); canvas.Children.Add(txtblk); x += xdelta; } }
private bool CanMoveToThere(int target, string color, Ellipse currentCircle, bool onlyToShow) { var polgyonTarget = _board.GameBoard[target]; var nameSplited = _selectedCircle.Name.Split('_'); var position = nameSplited[0]; if (_selectedCircle.Name.Contains("dead")) { if (onlyToShow == true || color == "Black" && (target == 0 || target == 1 || target == 2 || target == 3 || target == 4 || target == 5) || color == "White" && (target == 23 || target == 22 || target == 21 || target == 20 || target == 19 || target == 18)) { foreach (var dice in _currentTurn.Turns) { if (target == (dice - 1) || (target + dice == 24) || onlyToShow == true) { if (polgyonTarget.Count == 0) { if (onlyToShow == false) { ClearDice(dice.ToString()); _currentTurn.Turns.Remove(dice); } return(true); } else { if (polgyonTarget.FirstOrDefault().Color == color) { if (onlyToShow == false) { ClearDice(dice.ToString()); _currentTurn.Turns.Remove(dice); } return(true); } else { if (polgyonTarget.Count == 1) { if (onlyToShow == false) { if (polgyonTarget[0].Color != color) { if (_currentTurn == _currnetPlayer) { _secondPlayer.NumOfDeadCircels.Add(new Circle() { Color = _secondPlayer.Color }); _secondPlayer.NumOfCircelsOnBasis--; } else { _currnetPlayer.NumOfDeadCircels.Add(new Circle() { Color = _currnetPlayer.Color }); _currnetPlayer.NumOfCircelsOnBasis--; } polgyonTarget.RemoveAt(0); } ClearDice(dice.ToString()); _currentTurn.Turns.Remove(dice); } return(true); } } } } } return(false); } } else { foreach (var dice in _currentTurn.Turns) { if ((color == "Black" && target > int.Parse(position) && int.Parse(position) + dice == target) || (color == "White" && target < int.Parse(position) && int.Parse(position) - dice == target)) { if (polgyonTarget.Count == 0) { if (onlyToShow == false) { ClearDice(dice.ToString()); _currentTurn.Turns.Remove(dice); } return(true); } else { if (polgyonTarget.FirstOrDefault().Color == color) { if (onlyToShow == false) { ClearDice(dice.ToString()); _currentTurn.Turns.Remove(dice); } return(true); } else { if (polgyonTarget.Count == 1) { if (polgyonTarget[0].Color != color) { if (onlyToShow == false) { if (_currentTurn == _currnetPlayer) { _secondPlayer.NumOfDeadCircels.Add(new Circle() { Color = _secondPlayer.Color }); } else { _currnetPlayer.NumOfDeadCircels.Add(new Circle() { Color = _currnetPlayer.Color }); } polgyonTarget.RemoveAt(0); if (color == "Black" && (target == 0 || target == 1 || target == 2 || target == 3 || target == 4 || target == 5) || color == "White" && (target == 23 || target == 22 || target == 21 || target == 20 || target == 19 || target == 18)) { if (_currentTurn == _currnetPlayer) { _secondPlayer.NumOfCircelsOnBasis--; } else { _currnetPlayer.NumOfCircelsOnBasis--; } } ClearDice(dice.ToString()); _currentTurn.Turns.Remove(dice); } ; } return(true); } } } } } return(false); } return(false); }
private async void MakePolygonClick(string polygonName) { await Windows.ApplicationModel.Core.CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { if (_selectedCircle.Name != "noSelceted") { if (polygonName == "basisP1" || polygonName == "basisP2") { basis_Tapped(polygonName); return; } Polygon po = _polygons.FirstOrDefault(o => o.Name == polygonName); var nameWithoutUnderScore = po.Name.Substring(1, po.Name.Length - 1); var getPolygonInBoard = _board.GameBoard[int.Parse(nameWithoutUnderScore)]; if (_selectedCircle.Name.Contains("dead")) { if (CanMoveToThere(int.Parse(nameWithoutUnderScore), _currentTurn.Color, _selectedCircle, false)) { _currentTurn.NumOfDeadCircels.RemoveAt(0); getPolygonInBoard.Add(new Circle() { Color = _currentTurn.Color }); foreach (var item in _currentTurn.NumOfDeadCircels) { item.IsSelected = false; } _selectedCircle = new Ellipse() { Name = "noSelceted" }; ControlPolygonsEvents(false); DrawCircels(); ClearShowWhereCanGo(); if (_currentTurn.Turns.Count == 0) { NewTurn(); return; } } } else { var nameSplited = _selectedCircle.Name.Split('_'); var name = nameSplited[0]; var getInBoard = _board.GameBoard[int.Parse(name)]; if (CanMoveToThere(int.Parse(nameWithoutUnderScore), _currentTurn.Color, _selectedCircle, false)) { var removed = getInBoard.First(); removed.NeedToRemove = true; getInBoard.RemoveAt(getInBoard.Count - 1); getPolygonInBoard.Add(new Circle() { Color = _currentTurn.Color }); if (int.Parse(nameWithoutUnderScore) <= 5 && _currentTurn.Color == "White" && int.Parse(name) > 5) { _currentTurn.NumOfCircelsOnBasis++; } if (int.Parse(nameWithoutUnderScore) >= 18 && _currentTurn.Color == "Black" && int.Parse(name) < 18) { _currentTurn.NumOfCircelsOnBasis++; } foreach (var item in getInBoard) { item.IsSelected = false; } _selectedCircle = new Ellipse() { Name = "noSelceted" }; ControlPolygonsEvents(false); DrawCircels(); ClearShowWhereCanGo(); if (_currentTurn.Turns.Count == 0) { NewTurn(); } return; } } } }); }
private void Calc() { if (VoronoiFeatures.Count > 2) { #region Draw Delaunay if (DelaunayTriangleList == null) { DelaunayTriangleList = VoronoiFeatures.DelaunayTriangulation().ToList(); } if (DelaunayTriangleList != null) { foreach (var DelaunayTriangle in DelaunayTriangleList) { var P1OnScreen = GeoCalculations.GeoCoordinate2ScreenXY(DelaunayTriangle.Triangle.P1, this.MapControl.ZoomLevel); var P2OnScreen = GeoCalculations.GeoCoordinate2ScreenXY(DelaunayTriangle.Triangle.P2, this.MapControl.ZoomLevel); var P3OnScreen = GeoCalculations.GeoCoordinate2ScreenXY(DelaunayTriangle.Triangle.P3, this.MapControl.ZoomLevel); ////DrawLine(P1OnScreen, P2OnScreen, Brushes.Blue, 1.0); ////DrawLine(P2OnScreen, P3OnScreen, Brushes.Blue, 1.0); ////DrawLine(P3OnScreen, P1OnScreen, Brushes.Blue, 1.0); //var GeoCircle = new GeoCircle(_Triangle.P1, _Triangle.P2, _Triangle.P3); var ScreenCircle = new Circle <Double>(new Pixel <Double>(P1OnScreen.X + this.MapControl.ScreenOffset.X, P1OnScreen.Y + this.MapControl.ScreenOffset.Y), new Pixel <Double>(P2OnScreen.X + this.MapControl.ScreenOffset.X, P2OnScreen.Y + this.MapControl.ScreenOffset.Y), new Pixel <Double>(P3OnScreen.X + this.MapControl.ScreenOffset.X, P3OnScreen.Y + this.MapControl.ScreenOffset.Y)); //var r1 = ScreenCircle.Center.DistanceTo(P1OnScreen.X + this.MapControl.ScreenOffset.X, P1OnScreen.Y + this.MapControl.ScreenOffset.Y); //var r2 = ScreenCircle.Center.DistanceTo(P2OnScreen.X + this.MapControl.ScreenOffset.X, P2OnScreen.Y + this.MapControl.ScreenOffset.Y); //var r3 = ScreenCircle.Center.DistanceTo(P3OnScreen.X + this.MapControl.ScreenOffset.X, P3OnScreen.Y + this.MapControl.ScreenOffset.Y); //var CenterOnScreen = GeoCalculations.GeoCoordinate2ScreenXY(GeoCircle.Center, this.MapControl.ZoomLevel); #region DrawCircumCircles if (DrawCircumCircles) { var CircumCircle = new Ellipse() { Width = ScreenCircle.Diameter, Height = ScreenCircle.Diameter, Stroke = Brushes.DarkGreen, StrokeThickness = 1.0 }; this.Children.Add(CircumCircle); //Canvas.SetLeft(CircumCircle, CenterOnScreen.X + this.MapControl.ScreenOffset.X); //Canvas.SetTop (CircumCircle, CenterOnScreen.Y + this.MapControl.ScreenOffset.Y); Canvas.SetLeft(CircumCircle, ScreenCircle.X - ScreenCircle.Radius); // + this.MapControl.ScreenOffset.X); Canvas.SetTop(CircumCircle, ScreenCircle.Y - ScreenCircle.Radius); // + this.MapControl.ScreenOffset.Y); } #endregion } } foreach (var tr1 in DelaunayTriangleList) { tr1.Neighbors.Clear(); } HashSet <GeoCoordinate> tr1_h, tr2_h; IEnumerable <GeoCoordinate> Intersection; foreach (var tr1 in DelaunayTriangleList) { foreach (var tr2 in DelaunayTriangleList) { tr1_h = new HashSet <GeoCoordinate>(); tr1_h.Add(tr1.Triangle.P1); tr1_h.Add(tr1.Triangle.P2); tr1_h.Add(tr1.Triangle.P3); tr2_h = new HashSet <GeoCoordinate>(); tr2_h.Add(tr2.Triangle.P1); tr2_h.Add(tr2.Triangle.P2); tr2_h.Add(tr2.Triangle.P3); Intersection = tr1_h.Intersect(tr2_h); if (Intersection.Count() == 2) { tr1.Neighbors.Add(tr2); tr2.Neighbors.Add(tr1); foreach (var bo in tr1.Triangle.Borders) { if (Intersection.Contains(bo.P1) && Intersection.Contains(bo.P2)) { bo.Tags.Add("shared"); } } foreach (var bo in tr2.Triangle.Borders) { if (Intersection.Contains(bo.P1) && Intersection.Contains(bo.P2)) { bo.Tags.Add("shared"); } } } } } var aaa = DelaunayTriangleList.SelectMany(v => v.Triangle.Borders).Select(v => v.Tags); foreach (var DelaunayTriangle in DelaunayTriangleList) { foreach (var Edge in DelaunayTriangle.Triangle.Borders) { DrawLine(GeoCalculations.GeoCoordinate2ScreenXY(Edge.P1, this.MapControl.ZoomLevel), GeoCalculations.GeoCoordinate2ScreenXY(Edge.P2, this.MapControl.ZoomLevel), (Edge.Tags.Contains("shared")) ? Brushes.LightBlue : Brushes.Blue, 1.0); } } foreach (var tr1 in DelaunayTriangleList)//.Skip(2).Take(1)) { var Borders = tr1.Triangle.Borders.ToList(); var Center = new GeoLine(Borders[0].Center, Borders[0].Normale). Intersection(new GeoLine(Borders[1].Center, Borders[1].Normale)); var Vector1 = Borders[0].Vector; var Vector2 = Borders[0].Vector; var Vector3 = Borders[0].Vector; var Normale1 = Borders[0].Normale; var Normale2 = Borders[0].Normale; var Normale3 = Borders[0].Normale; //var Center1 = new GeoCoordinate(new Latitude(Borders[0].Center.Longitude.Value), new Longitude(Borders[0].Center.Latitude.Value)); //var Center2 = new GeoCoordinate(new Latitude(Borders[1].Center.Longitude.Value), new Longitude(Borders[1].Center.Latitude.Value)); //var Center3 = new GeoCoordinate(new Latitude(Borders[2].Center.Longitude.Value), new Longitude(Borders[2].Center.Latitude.Value)); DrawLine(Center, Borders[0].Center, Brushes.Green, 1.0); DrawLine(Center, Borders[1].Center, Brushes.Green, 1.0); DrawLine(Center, Borders[2].Center, Brushes.Green, 1.0); } #endregion //var Center1 = new GeoCoordinate(new Latitude(49.7316155727453), new Longitude(10.1409612894059)); //var LineX_3_4 = new GeoLine(new GeoCoordinate(new Latitude(49.732745964269350), new Longitude(10.135724544525146)), // new GeoCoordinate(new Latitude(49.731761237693235), new Longitude(10.135746002197264))); //var Line_S3S4 = new GeoLine(new GeoCoordinate(new Latitude(49.732552), new Longitude(10.139216)), // new GeoCoordinate(new Latitude(49.731004), new Longitude(10.138913))); //var Line_S3S4Center2Center1 = new GeoLine(Line_S3S4.Center, // Center1); //var Intersection1 = Line_S3S4Center2Center1.Intersection(LineX_3_4); //DrawLine(Line_S3S4.Center, Intersection1, Brushes.Red, 1.0); //// ------------------------------------------------------------------------ //var LineX_7_8 = new GeoLine(new GeoCoordinate(new Latitude(49.729930425324014), new Longitude(10.137097835540771)), // new GeoCoordinate(new Latitude(49.729347879633465), new Longitude(10.138492584228516))); //var Line_S4S5 = new GeoLine(new GeoCoordinate(new Latitude(49.731004), new Longitude(10.138913)), // new GeoCoordinate(new Latitude(49.730237), new Longitude(10.140107))); //var Line_S4S5Center2Center1 = new GeoLine(Line_S4S5.Center, // Center1); //var Intersection2 = Line_S4S5Center2Center1.Intersection(LineX_7_8); //DrawLine(Line_S4S5.Center, Intersection2, Brushes.Red, 1.0); //// ------------------------------------------------------------------------ //var Center2 = new GeoCoordinate(new Latitude(49.7302216912131), new Longitude(10.1434879302979)); //var LineX_14_15 = new GeoLine(new GeoCoordinate(new Latitude(49.728695974976030), new Longitude(10.143170356750488)), // new GeoCoordinate(new Latitude(49.728987252607084), new Longitude(10.144414901733398))); //var Line_S5S7 = new GeoLine(new GeoCoordinate(new Latitude(49.730237), new Longitude(10.140107)), // new GeoCoordinate(new Latitude(49.730664), new Longitude(10.146802))); //var Line_S5S7Center2Center2 = new GeoLine(Line_S5S7.Center, // Center2); //var Intersection3 = Line_S5S7Center2Center2.Intersection(LineX_14_15); //DrawLine(Center2, Intersection3, Brushes.Red, 1.0); //// ------------------------------------------------------------------------ //var LineX_17_18 = new GeoLine(new GeoCoordinate(new Latitude(49.732413101183180), new Longitude(10.149564743041992)), // new GeoCoordinate(new Latitude(49.731469976708340), new Longitude(10.148684978485107))); //var Line_S7S6 = new GeoLine(new GeoCoordinate(new Latitude(49.730664), new Longitude(10.146802)), // new GeoCoordinate(new Latitude(49.731791), new Longitude(10.145903))); //var Line_S7S6Center2Center2 = new GeoLine(Line_S7S6.Center, // Center2); //var Intersection4 = Line_S7S6Center2Center2.Intersection(LineX_17_18); //DrawLine(Line_S7S6.Center, Intersection4, Brushes.Red, 1.0); //// ------------------------------------------------------------------------ //var Center3 = new GeoCoordinate(new Latitude(49.7318726185525), new Longitude(10.1424804925919)); //var LineX_23_24 = new GeoLine(new GeoCoordinate(new Latitude(49.734146738072006), new Longitude(10.144844055175781)), // new GeoCoordinate(new Latitude(49.733966442720840), new Longitude(10.142934322357178))); //var Line_S6S3 = new GeoLine(new GeoCoordinate(new Latitude(49.731791), new Longitude(10.145903)), // new GeoCoordinate(new Latitude(49.732552), new Longitude(10.139216))); //var Line_S6S3Center2Center3 = new GeoLine(Line_S6S3.Center, // Center3); //var Intersection5 = Line_S6S3Center2Center3.Intersection(LineX_23_24); //DrawLine(Line_S6S3.Center, Intersection5, Brushes.Red, 1.0); } }
private static void RenderElement(Canvas parent, CompositeTransform textRotation, ElementDescription element) { switch (element.Type) { case ElementType.Circle: Ellipse e = new Ellipse() { Width = element.Width, Height = element.Height, Fill = BrushForColor(element.Fill), Stroke = BrushForColor(element.Stroke), }; parent.Children.Add(e); Canvas.SetLeft(e, element.CenterX); Canvas.SetTop(e, element.CenterY); break; case ElementType.Path: Path path = new Path() { Data = ProcessPathData(element.Path), Tag = element.Text, Fill = BrushForColor(element.Fill), Stroke = BrushForColor(element.Stroke), }; parent.Children.Add(path); break; case ElementType.Text: Grid g = new Grid() { Width = 200, Height = 200 }; parent.Children.Add(g); Canvas.SetLeft(g, element.CenterX - g.Width / 2); Canvas.SetTop(g, element.CenterY - g.Height / 2); TextBlock tb = new TextBlock() { HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, RenderTransform = textRotation, Foreground = BrushForColor(element.Stroke), FontSize = element.FontSize, Text = element.Text, }; g.Children.Add(tb); break; default: throw new InvalidOperationException("Unexpected node: " + element.Type); } }
public override void Plot(bool animate = true) { var points = new List <Point>(); for (int index = 0; index < PrimaryValues.Count; index++) { var value = new Point(SecondaryValues[index], PrimaryValues[index]); var point = ToPlotArea(value); points.Add(point); var e = new Ellipse { Width = PointRadius * 2, Height = PointRadius * 2, Fill = new SolidColorBrush { Color = Color }, Stroke = new SolidColorBrush { Color = Chart.PointHoverColor }, StrokeThickness = 2 }; Panel.SetZIndex(e, int.MaxValue - 2); Canvas.SetLeft(e, point.X - e.Width * .5); Canvas.SetTop(e, point.Y - e.Height * .5); Chart.Canvas.Children.Add(e); if (Chart.Hoverable) { var r = new Rectangle { Fill = Brushes.Transparent, Width = 40, Height = 40, StrokeThickness = 0 }; r.MouseEnter += Chart.OnDataMouseEnter; r.MouseLeave += Chart.OnDataMouseLeave; Canvas.SetLeft(r, point.X - r.Width / 2); Canvas.SetTop(r, point.Y - r.Height / 2); Panel.SetZIndex(r, int.MaxValue); Chart.Canvas.Children.Add(r); Chart.HoverableShapes.Add(new HoverableShape { Serie = this, Shape = r, Target = e, Value = value }); } Shapes.Add(e); } var c = Chart as ScatterChart; if (c == null) { return; } if (c.LineType == LineChartLineType.Bezier) { Shapes.AddRange(_addSerieAsBezier(points.ToArray(), Color, StrokeThickness, animate)); } if (c.LineType == LineChartLineType.Polyline) { Shapes.AddRange(_addSeriesAsPolyline(points.ToArray(), Color, StrokeThickness, animate)); } }
static public void ChangeElipse(Ellipse E, Brush B, Double X, Double Y, double W, double H, bool DontMove) { if (!E.Dispatcher.CheckAccess()) { E.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() => { E.Fill = B; E.Width = W; E.Height = H; if (DontMove) { return; } if (X < -200) { X = -200; } if (X > 200) { X = 200; } if (Y < -200) { Y = -200; } if (Y > 200) { Y = 200; } E.Margin = new Thickness(MainWindow.InitAimPos.Left + X, MainWindow.InitAimPos.Top + Y, 0, 0); E.UpdateLayout(); })); Dispatcher.CurrentDispatcher.InvokeShutdown(); } else { E.Fill = B; E.Width = W; E.Height = H; if (DontMove) { return; } if (X < -200) { X = -200; } if (X > 200) { X = 200; } if (Y < -200) { Y = -200; } if (Y > 200) { Y = 200; } E.Margin = new Thickness(MainWindow.InitAimPos.Left + X, MainWindow.InitAimPos.Top + Y, 0, 0); E.UpdateLayout(); } }
/// <summary> /// The on apply template. /// </summary> public override void OnApplyTemplate() { base.OnApplyTemplate(); this.rootElement = (FrameworkElement)this.GetTemplateChild("RootElement"); this.canvasHSV = (Canvas)this.GetTemplateChild("CanvasHSV"); this.rectangleRootHSV = (Rectangle)this.GetTemplateChild("RectangleRootHSV"); this.gradientStopHSVColor = (GradientStop)this.GetTemplateChild("GradientStopHSVColor"); this.rectangleHSV = (Rectangle)this.GetTemplateChild("RectangleHSV"); this.ellipseHSV = (Ellipse)this.GetTemplateChild("EllipseHSV"); this.sliderHSV = (Slider)this.GetTemplateChild("SliderHSV"); this.sliderA = (Slider)this.GetTemplateChild("SliderA"); this.gradientStopA0 = (GradientStop)this.GetTemplateChild("GradientStopA0"); this.gradientStopA1 = (GradientStop)this.GetTemplateChild("GradientStopA1"); this.sliderR = (Slider)this.GetTemplateChild("SliderR"); this.gradientStopR0 = (GradientStop)this.GetTemplateChild("GradientStopR0"); this.gradientStopR1 = (GradientStop)this.GetTemplateChild("GradientStopR1"); this.sliderG = (Slider)this.GetTemplateChild("SliderG"); this.gradientStopG0 = (GradientStop)this.GetTemplateChild("GradientStopG0"); this.gradientStopG1 = (GradientStop)this.GetTemplateChild("GradientStopG1"); this.sliderB = (Slider)this.GetTemplateChild("SliderB"); this.gradientStopB0 = (GradientStop)this.GetTemplateChild("GradientStopB0"); this.gradientStopB1 = (GradientStop)this.GetTemplateChild("GradientStopB1"); this.textBoxA = (TextBox)this.GetTemplateChild("TextBoxA"); this.textBoxR = (TextBox)this.GetTemplateChild("TextBoxR"); this.textBoxG = (TextBox)this.GetTemplateChild("TextBoxG"); this.textBoxB = (TextBox)this.GetTemplateChild("TextBoxB"); this.comboBoxColor = (ComboBox)this.GetTemplateChild("ComboBoxColor"); this.rectangleColor = (Rectangle)this.GetTemplateChild("RectangleColor"); this.brushColor = (SolidColorBrush)this.GetTemplateChild("BrushColor"); this.textBoxColor = (TextBox)this.GetTemplateChild("TextBoxColor"); this.buttonDone = (Button)this.GetTemplateChild("ButtonDone"); this.buttonCancel = (Button)this.GetTemplateChild("ButtonCancel"); this.themeColorsGrid = (ListBox)this.GetTemplateChild("ThemeColorsGrid"); this.recentColorsGrid = (ListBox)this.GetTemplateChild("RecentColorsGrid"); this.themeColorsGrid.SelectionChanged += this.themeColorsGrid_SelectionChanged; this.recentColorsGrid.SelectionChanged += this.recentColorsGrid_SelectionChanged; this.rectangleHSV.MouseLeftButtonDown += this.HSV_MouseLeftButtonDown; this.rectangleHSV.MouseMove += this.HSV_MouseMove; this.rectangleHSV.MouseLeftButtonUp += this.HSV_MouseLeftButtonUp; this.rectangleHSV.MouseLeave += this.HSV_MouseLeave; this.sliderHSV.ValueChanged += this.sliderHSV_ValueChanged; this.sliderA.ValueChanged += this.sliderA_ValueChanged; this.sliderR.ValueChanged += this.sliderR_ValueChanged; this.sliderG.ValueChanged += this.sliderG_ValueChanged; this.sliderB.ValueChanged += this.sliderB_ValueChanged; this.textBoxA.LostFocus += this.textBoxA_LostFocus; this.textBoxR.LostFocus += this.textBoxR_LostFocus; this.textBoxG.LostFocus += this.textBoxG_LostFocus; this.textBoxB.LostFocus += this.textBoxB_LostFocus; this.comboBoxColor.SelectionChanged += this.comboBoxColor_SelectionChanged; this.textBoxColor.GotFocus += this.textBoxColor_GotFocus; this.textBoxColor.LostFocus += this.textBoxColor_LostFocus; this.buttonDone.Click += this.buttonDone_Click; this.buttonCancel.Click += this.buttonCancel_Click; this.InitializePredefined(); this.InitializeThemeColors(); this.UpdateControls(this.Color, true, true, true); this.KeyDown += this.ColorBoard_KeyDown; }
private void GameLoop(object sender, EventArgs e) { // this is the game loop event, all of the instructions inside of this event will run each time the timer ticks // first we update the score and show the last score on the labels txtScore.Content = "Score: " + score; txtLastScore.Content = "Last Score: " + lastScore; // reduce 2 from the current rate as the time runs currentRate -= 2; // if the current rate is below 1 if (currentRate < 1) { // reset current rate back to spawn rate currentRate = spawnRate; // generate a random number for the X and Y value for the circles posX = rand.Next(15, 700); posY = rand.Next(50, 350); // generate a random colour for the circles and save it inside the brush brush = new SolidColorBrush(Color.FromRgb((byte)rand.Next(1, 255), (byte)rand.Next(1, 255), (byte)rand.Next(1, 255))); // create a new ellipse called circle // this circle will have a tag, default height and width, border colour and fill Ellipse circle = new Ellipse { Tag = "circle", Height = 10, Width = 10, Stroke = Brushes.Black, StrokeThickness = 1, Fill = brush }; // place the newly created circle to the canvas with the X and Y position generated earlier Canvas.SetLeft(circle, posX); Canvas.SetTop(circle, posY); // finally add the circle to the canvas MyCanvas.Children.Add(circle); } // the for each loop below will find each ellipse inside of the canvas and grow it foreach (var x in MyCanvas.Children.OfType <Ellipse>()) { // we search the canvas and find the ellipse that exists inside of it x.Height += growthRate; // grow the height of the circle x.Width += growthRate; // grow the width of the circle x.RenderTransformOrigin = new Point(0.5, 0.5); // grow from the centre of the circle by resetting the transform origin // if the width of the circle goes above 70 we want to pop the circle if (x.Width > 70) { // if the width if above 70 then add this circle to the remove this list removeThis.Add(x); health -= 15; // reduce health by 15 playerPopSound.Open(PoppedSound); // load the popped sound uri inside of the player pop sound media player playerPopSound.Play(); // now play the pop sound } } // end of for each loop // if health is above 1 if (health > 1) { // link the health bar rectangle to the health integer healthBar.Width = health; } else { // if health is below 1 then run the game over function GameOverFunction(); } // to remov ethe ellipse from the game we need another for each loop foreach (Ellipse i in removeThis) { // this for each loop will search for each ellipse that exist inside of the remove this list MyCanvas.Children.Remove(i); // when it finds one it will remove it from the canvas } // if the score if above 5 if (score > 5) { // speed up the spawn rate spawnRate = 25; } // if the score is above 20 if (score > 20) { // speed up the growth and and spawn rate spawnRate = 15; growthRate = 1.5; } }
public void DrawFigure(ShapeType type) { try { ClearCanvas(); Shape shape = null; switch (type) { case ShapeType.LINE: shape = new Line() { X1 = 0 + data.LineWidth / 2, Y1 = 0 + data.LineWidth / 2, X2 = this.Width - data.LineWidth / 2, Y2 = this.Height - data.LineWidth / 2 }; break; case ShapeType.ELLIPSE: shape = new Ellipse(); break; case ShapeType.RECTANGLE: shape = new Rectangle(); break; case ShapeType.CRECTANGLE: shape = new Rectangle() { RadiusX = 10, RadiusY = 10 }; break; case ShapeType.MULTILINE: shape = new Polyline { Points = new PointCollection(data.Path) }; break; default: throw new ArgumentException(); } shape.Stroke = new SolidColorBrush(data.LineColor); shape.StrokeThickness = data.LineWidth; shape.StrokeStartLineCap = PenLineCap.Round; shape.StrokeEndLineCap = PenLineCap.Round; shape.Width = this.Width; shape.Height = this.Height; shape.Margin = new Thickness( 0, 0, shape.Width - data.LineWidth * 2, shape.Height - data.LineWidth * 2 ); canvas.Children.Add(shape); } catch { } }
private void Button_Click(object sender, RoutedEventArgs e) { initControl(); int sum = 0; sum += GetNum(txtbNO1.Text); int no1_c = sum; sum += GetNum(txtbNO2.Text); int no2_c = sum; sum += GetNum(txtbNO3.Text); int no3_c = sum; sum += GetNum(txtbNO4.Text); int no4_c = sum; sum += GetNum(txtbNO5.Text); int no5_c = sum; int _index = 0; for (int i = 0; i < sum; i++) { if (i < no1_c) { _brushs.Add(no1); continue; } else if (i < no2_c) { _brushs.Add(no2); continue; } else if (i < no3_c) { _brushs.Add(no3); continue; } else if (i < no4_c) { _brushs.Add(no4); continue; } else { _brushs.Add(no5); continue; } } //List<SolidColorBrush> new_list = _brushs; Random rom = new Random(); for (int i = 0; i < sum; i++) { int old_index = rom.Next(0, sum - 1); SolidColorBrush temp = _brushs[old_index]; _brushs[old_index] = _brushs[i]; _brushs[i] = temp; } int no = 0; while (no++ < 100) { Ellipse bb = new Ellipse(); bb.Height = 10; bb.Width = 10; int index = rom.Next(0, sum - 1); if (_brushs[index] == no1) { count_no1++; } if (_brushs[index] == no2) { count_no2++; } if (_brushs[index] == no3) { count_no3++; } if (_brushs[index] == no4) { count_no4++; } if (_brushs[index] == no5) { count_no5++; } bb.Fill = _brushs[index]; wPanel.Children.Add(bb); //System.Threading.Thread.Sleep(10); } txtResult.Text = string.Format("NO.1: {0} ; NO.2: {1} ; NO.3: {2} ; NO.4: {3} ; NO.5: {4} ", count_no1, count_no2, count_no3, count_no4, count_no5); }
public DibujaCirculo(Canvas canvas) : base(canvas) { ellipse = null; }
private void RemoveDot(Ellipse dot) { Dots.Remove(dot); this.dotCanvas.Children.Remove(dot); DotsPool.Push(dot); }
private void ReportProgress(Ellipse ellipse, ProgressBar progressBar, TextBlock textResult, double value, Ellipse ellipse1 = null) { if (ellipse1 != null) { ellipse1.Fill = solidColorBrush; } if (progressBar != null && textResult != null && value > 0) { progressBar.Value = value; textResult.Text = string.Format("{0:0.00}", value) + "% done."; } if (value == 100) { ellipse.Fill = solidColorBrush; } }
private void SetDotForShape(Ellipse dot) { shapeQueue.Add(dot); dot.Fill = CurrentColor.Background; // update dot count for shape if (shapeQueue.Count <= 3) { color1.DataContext = shapeQueue.Count; } else if (shapeQueue.Count > 3 && shapeQueue.Count <= 6) { color2.DataContext = shapeQueue.Count - 3; } else if (shapeQueue.Count > 6 && shapeQueue.Count <= 9) { color3.DataContext = shapeQueue.Count - 6; } else if (shapeQueue.Count > 9 && shapeQueue.Count <= 13) { color4.DataContext = shapeQueue.Count - 9; } else if (shapeQueue.Count > 13 && shapeQueue.Count <= 16) { color5.DataContext = shapeQueue.Count - 13; } else if (shapeQueue.Count > 16 && shapeQueue.Count <= 19) { color6.DataContext = shapeQueue.Count - 16; } else if (shapeQueue.Count > 19 && shapeQueue.Count <= 23) { color7.DataContext = shapeQueue.Count - 19; } // highlight current color if (shapeQueue.Count < 3) { CurrentColor = color1; } else if (shapeQueue.Count >= 3 && shapeQueue.Count < 6) { CurrentColor = color2; } else if (shapeQueue.Count >= 6 && shapeQueue.Count < 9) { CurrentColor = color3; } else if (shapeQueue.Count >= 9 && shapeQueue.Count < 13) { CurrentColor = color4; } else if (shapeQueue.Count >= 13 && shapeQueue.Count < 16) { CurrentColor = color5; } else if (shapeQueue.Count >= 16 && shapeQueue.Count < 19) { CurrentColor = color6; } else if (shapeQueue.Count >= 19 && shapeQueue.Count < 23) { CurrentColor = color7; } else if (shapeQueue.Count == 23) { btnDotsForShapeComplete.IsEnabled = true; CurrentColor = null; } }
/***************************************************/ public static bool IsInPlane(this Ellipse ellipse, Plane plane, double tolerance = Tolerance.Distance, double angTolerance = Tolerance.Angle) { //TODO: Is this check enough? return(ellipse.Normal().IsParallel(plane.Normal, angTolerance) != 0 && Math.Abs(plane.Normal.DotProduct(ellipse.Centre - plane.Origin)) <= tolerance); }
public FruitDraw(Ellipse shape, double strain, double number) { fruit = shape; strainValue = strain; fruitNumber = number; }
private void UpdateTraverseBoundary() { if (this.ElevationLimits == null) { this.BoundaryCanvas.Children.Clear(); return; } double size; double radius; Point center; this.GetDimentions(out size, out radius, out center); if (size == 0) { return; } var oneThirdsRadius = radius / 3; var maxElevation = this.ElevationLimits.GetMaxValue(); var maxDepression = this.DepressionLimits.GetMaxValue(); var maxTraverse = -maxElevation + maxDepression; // elevation/outer figure _elevationRadiusConverter = r => (-r + maxDepression) / maxTraverse * oneThirdsRadius * 2 + oneThirdsRadius; _depressionRadiusConverter = r => (maxDepression - r) / maxTraverse * oneThirdsRadius * 2 + oneThirdsRadius; _inverseVerticalTraverseConverter = r => - ((r - oneThirdsRadius) / (oneThirdsRadius * 2) * maxTraverse - maxDepression); var elevationGeometry = GunTraverseHelper.CreateGeometry(this.ElevationLimits, this.TurretYawLimits, center, _elevationRadiusConverter); var depressionGeometry = GunTraverseHelper.CreateGeometry(this.DepressionLimits, this.TurretYawLimits, center, _depressionRadiusConverter); var combinedGeometry = new CombinedGeometry(GeometryCombineMode.Exclude, elevationGeometry, depressionGeometry); var figure = new Path { Data = combinedGeometry }; var borderStyle = this.FindResource("Border") as Style; var delimiterStyle = this.FindResource("Delimiter") as Style; figure.Style = borderStyle; var delimiterCircle = new Ellipse(); var delimiterCircleSize = _depressionRadiusConverter(0) * 2; delimiterCircle.Width = delimiterCircleSize; delimiterCircle.Height = delimiterCircleSize; delimiterCircle.Style = delimiterStyle; Canvas.SetLeft(delimiterCircle, (size - delimiterCircleSize) / 2); Canvas.SetTop(delimiterCircle, (size - delimiterCircleSize) / 2); this.BoundaryCanvas.Children.Clear(); this.BoundaryCanvas.Children.Add(delimiterCircle); this.BoundaryCanvas.Children.Add(figure); Canvas.SetLeft(this.YawDirectionLine, center.X); Canvas.SetTop(this.YawDirectionLine, center.Y); }
/// <summary> /// 鼠标移动画线 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ScreenUnlock_MouseMove(object sender, MouseEventArgs e) { if (isChecking)//如果图形正在检查中,不响应后续处理 { return; } if (e.LeftButton == System.Windows.Input.MouseButtonState.Pressed) { var point = e.GetPosition(this); HitTestResult result = VisualTreeHelper.HitTest(this, point); Ellipse ellipse = result.VisualHit as Ellipse; if (ellipse != null) { if (currentLine == null) { //从头开始绘制 currentLine = CreateLine(); canvasRoot.Children.Add(currentLine); var ellipseCenterPoint = GetCenterPoint(ellipse); currentLine.X1 = currentLine.X2 = ellipseCenterPoint.X; currentLine.Y1 = currentLine.Y2 = ellipseCenterPoint.Y; currentPointArray.Add(ellipse.Tag.ToString()); Console.WriteLine(string.Join(",", currentPointArray)); currentLineList.Add(currentLine); } else { //遇到下一个点,排除已经经过的点 if (currentPointArray.Contains(ellipse.Tag.ToString())) { return; } OnAfterByPoint(ellipse); } } else { if (ellipse == null) { ellipse = IsOnLineEx(point); } if (currentLine != null) { currentLine.X2 = point.X; currentLine.Y2 = point.Y; } } } else { if (currentPointArray.Count == 0) { return; } isChecking = true; if (currentLineList.Count + 1 != currentPointArray.Count) { //最后一条线的终点不在点上 //两点一线,点的个数-1等于线的条数 currentLineList.Remove(currentLine); //从已记录的线集合中删除最后一条多余的线 canvasRoot.Children.Remove(currentLine); //从界面上删除最后一条多余的线 currentLine = null; } if (Operation == ScreenUnLockOperationType.Check) { Console.WriteLine("playAnimation Check"); var result = CheckPoint(); //执行图形检查 //执行完成动画并触发检查事件 PlayAnimation(result, () => { if (OnCheckedPoint != null) { this.Dispatcher.BeginInvoke(OnCheckedPoint, this, new CheckPointArgs() { Result = result }); //触发检查完成事件 } }); } else if (Operation == ScreenUnLockOperationType.Remember) { Console.WriteLine("playAnimation Remember"); RememberPoint(); //记忆绘制的坐标 var args = new RememberPointArgs() { PointArray = this.PointArray }; //执行完成动画并触发记忆事件 PlayAnimation(true, () => { if (OnRememberPoint != null) { this.Dispatcher.BeginInvoke(OnRememberPoint, this, args); //触发图形记忆事件 } }); } } }
private void ShapeSave_Click(object sender, RoutedEventArgs e) { if (clicked == null) { } else if (clicked.GetType().ToString() == "System.Windows.Shapes.Line") { Line tmp = (Line)clicked; if (shapeName_tb.Text != null) { tmp.Name = shapeName_tb.Text; } if (shapeX1_tb.Text != null) { tmp.X1 = Double.Parse(shapeX1_tb.Text); } if (shapeX1_tb.Text != null) { tmp.Y1 = Double.Parse(shapeY1_tb.Text); } if (shapeX1_tb.Text != null) { tmp.X2 = Double.Parse(shapeX2_tb.Text); } if (shapeX1_tb.Text != null) { tmp.Y2 = Double.Parse(shapeY2_tb.Text); } if (newColor_cb.IsChecked == true) { tmp.Stroke = (Brush)converter.ConvertFromString(color_l.Content.ToString()); } } else if (clicked.GetType().ToString() == "System.Windows.Shapes.Ellipse") { Ellipse tmp = (Ellipse)clicked; if (shapeName_tb.Text != null) { tmp.Name = shapeName_tb.Text; } if (shapeX1_tb.Text != null && shapeX1_tb.Text != null) { tmp.Margin = new Thickness(Double.Parse(shapeX1_tb.Text), Double.Parse(shapeY1_tb.Text), 0, 0); } if (shapeX1_tb.Text != null) { tmp.Height = Double.Parse(shapeHeight_tb.Text); } if (shapeX1_tb.Text != null) { tmp.Width = Double.Parse(shapeWidth_tb.Text); } if (newColor_cb.IsChecked == true) { tmp.Stroke = (Brush)converter.ConvertFromString(color_l.Content.ToString()); tmp.Fill = (Brush)converter.ConvertFromString(color_l.Content.ToString()); } } else if (clicked.GetType().ToString() == "System.Windows.Shapes.Rectangle") { Rectangle tmp = (Rectangle)clicked; if (shapeName_tb.Text != null) { tmp.Name = shapeName_tb.Text; } if (shapeX1_tb.Text != null && shapeX1_tb.Text != null) { tmp.Margin = new Thickness(Double.Parse(shapeX1_tb.Text), Double.Parse(shapeY1_tb.Text), 0, 0); } if (shapeX1_tb.Text != null) { tmp.Height = Double.Parse(shapeHeight_tb.Text); } if (shapeX1_tb.Text != null) { tmp.Width = Double.Parse(shapeWidth_tb.Text); } if (newColor_cb.IsChecked == true) { tmp.Stroke = (Brush)converter.ConvertFromString(color_l.Content.ToString()); tmp.Fill = (Brush)converter.ConvertFromString(color_l.Content.ToString()); } } }
ShapeData ConstructAndAddShape(TypeId typeId) { UIElement element; if (typeId == TypeId.Line) { var line = new Line {StrokeEndLineCap = PenLineCap.Round}; element = line; } else if (typeId == TypeId.Text) { element = new TextBlock (); } else if (typeId == TypeId.Oval) { element = new Ellipse (); } else if (typeId == TypeId.Arc) { element = new Path(); } else if (typeId == TypeId.RoundedRect) { element = new Rectangle (); } else if (typeId == TypeId.Rect) { element = new Rectangle (); } else if (typeId == TypeId.Image) { element = new Image (); } else if (typeId == TypeId.Polygon) { element = new NativePolygon (); } else { throw new NotSupportedException ("Don't know how to construct: " + typeId); } var sd = new ShapeData { Element = element, TypeId = typeId, }; _shapes.Add (sd); // // Insert it in the right place so it gets drawn in the right order // if (_lastAddElementIndex >= 0) { _lastAddElementIndex++; _canvas.Children.Insert(_lastAddElementIndex, element); } else { if (_lastShape != null) { _lastAddElementIndex = _canvas.Children.IndexOf(_lastShape.Element) + 1; _canvas.Children.Insert(_lastAddElementIndex, element); } else { _lastAddElementIndex = _canvas.Children.Count; _canvas.Children.Add(element); } } return sd; }
private void DrawCircels() { gameGrid1.Children.Clear(); gameGrid2.Children.Clear(); blackDeadArea.Children.Clear(); whiteDeadArea.Children.Clear(); { int k = 0; for (int i = 0; i < _board.GameBoard.Count(); i++) { if (i > 11) { k++; } if (_board.GameBoard[i].Count > 0) { if (i <= 11) { int n = 0; foreach (var item in _board.GameBoard[i]) { Ellipse el = new Ellipse(); if (item.Color == "Black") { el.Fill = new SolidColorBrush(Colors.Black); } else { el.Fill = new SolidColorBrush(Colors.White); } if (item.IsSelected == true) { el.Stroke = new SolidColorBrush(Colors.Yellow); el.StrokeThickness = 3; } else { el.Stroke = null; } el.Height = 45; el.Width = 45; el.HorizontalAlignment = HorizontalAlignment.Center; el.Name = $"{i}_{n}"; el.AddHandler(TappedEvent, new TappedEventHandler(Ellipse_Tapped), true); _circels.Add(el); if (i == 6) { el.HorizontalAlignment = HorizontalAlignment.Left; } Grid.SetColumn(el, 11 - i); Grid.SetRow(el, n); gameGrid1.Children.Add(el); n++; } } if (i > 11) { if (_board.GameBoard[i].Count > 0) { int n = 6; foreach (var item in _board.GameBoard[i]) { Ellipse el = new Ellipse(); if (item.Color == "Black") { el.Fill = new SolidColorBrush(Colors.Black); } else { el.Fill = new SolidColorBrush(Colors.White); } if (item.IsSelected == true) { el.Stroke = new SolidColorBrush(Colors.Yellow); el.StrokeThickness = 3; } else { el.Stroke = null; } el.Height = 45; el.Width = 45; el.HorizontalAlignment = HorizontalAlignment.Center; el.Name = $"{i}_{n}"; el.AddHandler(TappedEvent, new TappedEventHandler(Ellipse_Tapped), true); _circels.Add(el); if (i == 17) { el.HorizontalAlignment = HorizontalAlignment.Left; } Grid.SetColumn(el, k - 1); Grid.SetRow(el, n); gameGrid2.Children.Add(el); n--; } } } } } int index = 0; foreach (var item in _currnetPlayer.NumOfDeadCircels) { Ellipse el = new Ellipse(); if (item.Color == "Black") { el.Fill = new SolidColorBrush(Colors.Black); } else { el.Fill = new SolidColorBrush(Colors.White); } if (item.IsSelected == true) { el.Stroke = new SolidColorBrush(Colors.Yellow); el.StrokeThickness = 3; } else { el.Stroke = null; } el.Height = 45; el.Width = 45; el.HorizontalAlignment = HorizontalAlignment.Center; el.Name = $"dead{index}"; _circels.Add(el); el.AddHandler(TappedEvent, new TappedEventHandler(Ellipse_Tapped), true); Grid.SetColumn(el, index); Grid.SetRow(el, index); if (_currnetPlayer.Color == "Black") { blackDeadArea.Children.Add(el); } else { whiteDeadArea.Children.Add(el); } index++; } foreach (var item in _secondPlayer.NumOfDeadCircels) { Ellipse el = new Ellipse(); if (item.Color == "Black") { el.Fill = new SolidColorBrush(Colors.Black); } else { el.Fill = new SolidColorBrush(Colors.White); } if (item.IsSelected == true) { el.Stroke = new SolidColorBrush(Colors.Yellow); el.StrokeThickness = 3; } else { el.Stroke = null; } el.Height = 45; el.Width = 45; el.HorizontalAlignment = HorizontalAlignment.Center; el.Name = $"dead{index}"; _circels.Add(el); el.AddHandler(TappedEvent, new TappedEventHandler(Ellipse_Tapped), true); Grid.SetColumn(el, index); Grid.SetRow(el, index); if (_secondPlayer.Color == "Black") { blackDeadArea.Children.Add(el); } else { whiteDeadArea.Children.Add(el); } index++; } } }
public void Setup() { DispatcherCache.Clear(); circle = new Circle(); rect = new Rectangle(); roundedRect = new RoundedRectangle(); morph = new Morph(); ellipse = new Ellipse(); }
private async void MakeCircleClick(string elName) { await Windows.ApplicationModel.Core.CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { Ellipse el = _circels.FirstOrDefault(a => a.Name == elName); if (_selectedCircle.Name == "noSelceted") { if (_currentTurn.NumOfDeadCircels.Count > 0) { if (el.Name.Substring(0, el.Name.Length - 1) == "dead") { _selectedCircle = el; var name = el.Name.Substring(el.Name.Count() - 1); var getInBoard = _board.GameBoard[int.Parse(name)]; ShowWhereCanGo(name); foreach (var item in _currentTurn.NumOfDeadCircels) { item.IsSelected = true; } } else { if (_currentTurn == _currnetPlayer) { await new MessageDialog("You can choose only dead circels!").ShowAsync(); return; } } } else { _selectedCircle = el; var nameSplited = el.Name.Split('_'); var name = nameSplited[0]; var getInBoard = _board.GameBoard[int.Parse(name)]; ShowWhereCanGo(name); foreach (var item in getInBoard) { item.IsSelected = true; } } DrawCircels(); return; } if (_selectedCircle.Name == el.Name) { if (el.Name.Substring(0, el.Name.Length - 1) == "dead") { foreach (var item in _currentTurn.NumOfDeadCircels) { item.IsSelected = false; } } else { var nameSplited = el.Name.Split('_'); var name = nameSplited[0]; var getInBoard = _board.GameBoard[int.Parse(name)]; foreach (var item in getInBoard) { item.IsSelected = false; } } _selectedCircle = new Ellipse() { Name = "noSelceted" }; ControlPolygonsEvents(false); ClearShowWhereCanGo(); DrawCircels(); return; } }); return; }