private Hashtable rd = new Hashtable(); //哈希表存放对应xy数组的行数,随机数,对应剪裁正方形的(x、y坐标) private void menuShuffleBlock_Click(object sender, RoutedEventArgs e) { ///计算可以裁剪多少个方块 /// //初始化变量值,方块的边长为rs rs = 30; //计数变量初值=0 //坐标系:image的左上角为坐标原点,image上边为X轴,正方向向右。image左边为Y轴,正方向向下 count = 0; rd.Clear(); pg.Clear(); //取x方向剪裁的整数大者。image的宽、高不要设为自动 x = (int)Math.Ceiling(this.image.Width / rs); //取y方向剪裁的整数大者 y = (int)Math.Ceiling(this.image.Height / rs); total = x * y;//剪裁总数 //创建小方块数组,并为数组填充值 xy = new int[total, 2]; getxy(); //得到随机数列,存入哈希表rb中 random(); ///定时器的相关操作 //设置时间间隔为10ms timer.Interval = TimeSpan.FromMilliseconds(10); //定时访问事件为timerTick timer.Tick += new EventHandler(timerTick); //定时器使能 timer.IsEnabled = true; //启动定时器 timer.Start(); }
private void button2_Click(object sender, System.Windows.RoutedEventArgs e) { pg1.Clear(); this.canvas1.Children.Clear(); y1 = this.canvas1.Height; count1 = 0; baiyechuang(); //设置百叶窗 timer2.Interval = TimeSpan.FromMilliseconds(100); timer2.Tick += new EventHandler(timer2Tick); timer2.Start(); }
protected override void UpdateUIRepresentationCore() { var transform = Plotter.Viewport.Transform; PathGeometry geometry = PathGeometry; PointCollection points = Points; geometry.Clear(); if (points == null) { } else { PathFigure figure = new PathFigure(); if (points.Count > 0) { figure.StartPoint = points[0].DataToScreen(transform); if (points.Count > 1) { Point[] pointArray = new Point[points.Count - 1]; for (int i = 1; i < points.Count; i++) { pointArray[i - 1] = points[i].DataToScreen(transform); } figure.Segments.Add(new PolyLineSegment(pointArray, true)); } } geometry.Figures.Add(figure); geometry.FillRule = this.FillRule; } }
private Hashtable rd = new Hashtable(); //哈希表存放对应xy数组的行数,随机数,对应剪裁正方形的(x、y坐标) private void button2_Click(object sender, System.Windows.RoutedEventArgs e) { rs = 30; //初始化变量值 count = 0; //坐标系:image的左上角为坐标原点,image上边为X轴,正方向向右。image左边为Y轴,正方向向下 rd.Clear(); pg.Clear(); x = (int)Math.Ceiling(this.image.Width / rs); //取x方向剪裁的整数大者。image的宽、高不要设为自动 y = (int)Math.Ceiling(this.image.Height / rs); //取y方向剪裁的整数大者 total = x * y; //剪裁总数 xy = new int [total, 2]; getxy(); random(); timer.Interval = TimeSpan.FromMilliseconds(10); timer.Tick += new EventHandler(timerTick); timer.IsEnabled = true; timer.Start(); }
/// <summary> /// Handles when the plot size changes /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void clippedPlotCanvas_SizeChanged(object sender, SizeChangedEventArgs e) { chartClip.Clear(); chartClip.AddGeometry( new RectangleGeometry(new Rect(0, 0, clippedPlotCanvas.ActualWidth, clippedPlotCanvas.ActualHeight))); panZoomCalculator.Window = new Rect(0, 0, clippedPlotCanvas.ActualWidth, clippedPlotCanvas.ActualHeight); ResizePlot(); }
public ViewportShapeClone(ViewportShape source, double xOffset) { _xOffset = xOffset; _translateTransform = new TranslateTransform(); _geometry = new PathGeometry(); _geometry.Transform = _translateTransform; _source = source; _source.ShapeGeometry.Changed += (s, e) => { _geometry.Clear(); _geometry.AddGeometry(_source.ShapeGeometry); }; _geometry.Clear(); _geometry.AddGeometry(_source.ShapeGeometry); // The properties we are copying all need to be bindings Action <DependencyProperty, string> bind = (dp, path) => BindingOperations.SetBinding(this, dp, new Binding { Source = _source, Path = new PropertyPath(path), Mode = BindingMode.OneWay }); bind(StrokeProperty, "Stroke"); bind(StrokeThicknessProperty, "StrokeThickness"); bind(StrokeDashArrayProperty, "StrokeDashArray"); bind(FillProperty, "Fill"); bind(VisibilityProperty, "Visibility"); // Need to reflect all mouse events back to the original MouseDown += (s, e) => _source.RaiseEvent(e); MouseEnter += (s, e) => _source.RaiseEvent(e); MouseLeave += (s, e) => _source.RaiseEvent(e); MouseLeftButtonDown += (s, e) => _source.RaiseEvent(e); MouseLeftButtonUp += (s, e) => _source.RaiseEvent(e); MouseMove += (s, e) => _source.RaiseEvent(e); MouseRightButtonDown += (s, e) => _source.RaiseEvent(e); MouseRightButtonUp += (s, e) => _source.RaiseEvent(e); MouseUp += (s, e) => _source.RaiseEvent(e); MouseWheel += (s, e) => _source.RaiseEvent(e); UpdateUIRepresentationCore(); }
private void RefreshUpper(ref PathGeometry pg, Point p, Size size) { pg.Clear(); PathFigure fig = new PathFigure(); fig.StartPoint = StartPoint; Point cPoint = CalcPoint(p); fig.Segments.Add(new LineSegment(new Point(cPoint.X, StartPoint.Y), true)); fig.Segments.Add(new LineSegment(new Point(StartPoint.X, cPoint.Y), true)); pg.Figures.Add(fig); }
private void redraw_line(PathGeometry line, List <Point> points) { var figure = new PathFigure { StartPoint = points[0], IsClosed = false }; var segment = new PolyLineSegment(points, true); figure.Segments.Add(segment); line.Clear(); line.Figures.Add(figure); }
public static void SizeGeometry(PathGeometry pg, Size size) { if (size.Width > 0.0 && size.Height > 0.0) { PathFigure[] sizeFigures = { new PathFigure(new Point(size.Width, size.Height), Enumerable.Empty <PathSegment>(), true), new PathFigure(new Point(0.0, 0.0), Enumerable.Empty <PathSegment>(), true), }; var newGeo = new PathGeometry(sizeFigures.Concat(pg.Figures), pg.FillRule, null);//pg.Transform do not add transform here, it will recalculate all the Points pg.Clear(); pg.AddGeometry(newGeo); //return new PathGeometry(sizeFigures.Concat(pg.Figures), pg.FillRule, pg.Transform); } }
internal static void SizeGeometry(PathGeometry pg, Size size) { if (!(size.Height > 0) || !(size.Height > 0)) { return; } PathFigure[] sizeFigures = { new PathFigure(new Point(size.Width, size.Height), Enumerable.Empty <PathSegment>(), true), new PathFigure(new Point(0, 0), Enumerable.Empty <PathSegment>(), true) }; var newGeo = new PathGeometry(sizeFigures.Concat(pg.Figures), pg.FillRule, null); pg.Clear(); pg.AddGeometry(newGeo); }
private void RefreshMiddle(ref PathGeometry path, Point p, ref RotateTransform rot, ref TranslateTransform transl, Size size) { path.Clear(); Point cPoint = CalcPoint(p); PathFigure fig = new PathFigure(); fig.StartPoint = new Point(size.Width - cPoint.X, 0); fig.Segments.Add(new LineSegment(new Point(size.Width - StartPoint.X, 0), true)); fig.Segments.Add(new LineSegment(new Point(size.Width - StartPoint.X, cPoint.Y), true)); path.Figures.Add(fig); // rotation double a = 2 * Math.Atan(p.Y / (p.X - StartPoint.X)); rot.Angle = 180 * a / Math.PI; rot.CenterX = cPoint.X; rot.CenterY = StartPoint.Y; // translation transl.X = 2 * cPoint.X - size.Width; // reflection setting Point d = new Point(Math.Abs(p.X - StartPoint.X) / (RenderSize.Width), (p.Y) / (RenderSize.Height)); double o1 = (RenderSize.Width - StartPoint.X) / RenderSize.Width; // working right x_page_reflection.StartPoint = d;// new Point(1, 0);//d;// StartPoint; x_page_reflection.EndPoint = new Point(o1, 0); x_page_reflection.GradientStops[0].Color = Colors.White; x_page_reflection.GradientStops[1].Color = Colors.Transparent; if (o1 > 0.5) { x_page_reflection.StartPoint = new Point(o1, 0); x_page_reflection.GradientStops[0].Color = Colors.Transparent; x_page_reflection.GradientStops[1].Color = Colors.White; x_page_reflection.EndPoint = new Point(1 - d.X, d.Y); } }
public override void Draw(DrawingContext ctx, ViewPort vp) { _geometry.Clear(); var path = new PathFigure(); path.StartPoint = new Point( _places[0].Coordinate.X + vp.X1 / vp.Scale, _places[0].Coordinate.Y + vp.Y1 / vp.Scale); for (var i = 1; i < _places.Count; i++) { var pt = new Point( _places[i].Coordinate.X + vp.X1 / vp.Scale, _places[i].Coordinate.Y + vp.Y1 / vp.Scale); var edge = new LineSegment(pt, true); path.Segments.Add(edge); } _geometry.Figures.Add(path); ctx.DrawGeometry(Brushes.Transparent, new Pen(Brushes.Red, 3), _geometry); }
private DispatcherTimer timer3 = new DispatcherTimer(); //定时器 private void button1_Click(object sender, System.Windows.RoutedEventArgs e) { pg.Clear(); Pathfigure = new PathFigure(); //定义二维几何线段图形组合体; Pathfigure.StartPoint = new Point(this.image.Width / 2, 0); //直线开始点 Linesegment1 = new LineSegment(); //定义1条直线,起点是Pathfigure.StartPoint Linesegment1.Point = new Point(this.image.Width, 0); //下面每条线的终点坐标、起点同Linesegment1 Pathfigure.Segments.Add(Linesegment1); Linesegment2 = new LineSegment(); Linesegment2.Point = new Point(Linesegment1.Point.X, Linesegment1.Point.Y); Pathfigure.Segments.Add(Linesegment2); Linesegment3 = new LineSegment(); Linesegment3.Point = new Point(Linesegment1.Point.X, Linesegment1.Point.Y); Pathfigure.Segments.Add(Linesegment3); Linesegment0 = new LineSegment(); Linesegment0.Point = new Point(Linesegment1.Point.X, Linesegment1.Point.Y); Pathfigure.Segments.Add(Linesegment0); pg.Figures.Add(Pathfigure); this.image.Clip = pg; timer3.Interval = TimeSpan.FromMilliseconds(100); timer3.Tick += new EventHandler(timer3Tick); timer3.IsEnabled = true; timer3.Start(); }
protected override void UpdateUIRepresentationCore() { if (updating) { return; } updating = true; var transform = Plotter.Viewport.Transform; PathGeometry geometry = PathGeometry; PointCollection points = Points; geometry.Clear(); if (BezierPoints != null) { points = BezierPoints; var screenPoints = points.DataToScreen(transform).ToArray(); PathFigure figure = new PathFigure(); figure.StartPoint = screenPoints[0]; figure.Segments.Add(new PolyBezierSegment(screenPoints.Skip(1), true)); geometry.Figures.Add(figure); geometry.FillRule = this.FillRule; } else if (points == null) { } else { PathFigure figure = new PathFigure(); if (points.Count > 0) { Point[] bezierPoints = null; figure.StartPoint = points[0].DataToScreen(transform); if (points.Count > 1) { Point[] screenPoints = points.DataToScreen(transform).ToArray(); bezierPoints = BezierBuilder.GetBezierPoints(screenPoints).Skip(1).ToArray(); figure.Segments.Add(new PolyBezierSegment(bezierPoints, true)); } if (bezierPoints != null && buildBezierPoints) { Array.Resize(ref bezierPoints, bezierPoints.Length + 1); Array.Copy(bezierPoints, 0, bezierPoints, 1, bezierPoints.Length - 1); bezierPoints[0] = figure.StartPoint; BezierPoints = new PointCollection(bezierPoints.ScreenToData(transform)); } } geometry.Figures.Add(figure); geometry.FillRule = this.FillRule; } updating = false; }
private void Update() { if (_isValid) { return; } _sectorGeometry.Clear(); _leaderLineGeometry.Clear(); // Fetch dependency properties. (Accessing dependency properties is expensive.) double centerX = CenterX; double centerY = CenterY; double innerRadius = InnerRadius; double outerRadius = OuterRadius; double offset = Offset; double startAngle = StartAngle; double endAngle = EndAngle; // Correct invalid values. if (innerRadius < 0) { innerRadius = 0; } if (outerRadius < 0) { outerRadius = 0; } if (innerRadius > outerRadius) { innerRadius = outerRadius; } if (startAngle > endAngle) { ChartHelper.Swap(ref startAngle, ref endAngle); } // The sector angle. double angle = endAngle - startAngle; // The thickness of the ring. double width = outerRadius - innerRadius; // The direction vector pointing from the center to the start of the sector. double startX, startY; GetDirection(startAngle, out startX, out startY); // The direction vector pointing from the center to the end of the sector. double endX, endY; GetDirection(endAngle, out endX, out endY); // The direction vector pointing from the center to the middle of the sector. double midX, midY; GetDirection((startAngle + endAngle) / 2, out midX, out midY); // Exploded pie charts: Translate the center of the pie chart. centerX += offset * midX; centerY += offset * midY; if (angle < 2 * Math.PI) { // ---- Draw sector. Point p0 = new Point(centerX + innerRadius * startX, centerY + innerRadius * startY); Point p1 = new Point(centerX + outerRadius * startX, centerY + outerRadius * startY); Point p2 = new Point(centerX + outerRadius * endX, centerY + outerRadius * endY); Point p3 = new Point(centerX + innerRadius * endX, centerY + innerRadius * endY); var figure = new PathFigure { StartPoint = p0 }; figure.Segments.Add(new LineSegment { Point = p1 }); figure.Segments.Add(new ArcSegment { Point = p2, Size = new Size(outerRadius, outerRadius), IsLargeArc = angle > Math.PI, SweepDirection = SweepDirection.Clockwise }); figure.Segments.Add(new LineSegment { Point = p3 }); figure.Segments.Add(new ArcSegment { Point = p0, Size = new Size(innerRadius, innerRadius), IsLargeArc = angle > Math.PI, SweepDirection = SweepDirection.Counterclockwise }); _sectorGeometry.Figures.Add(figure); } else { if (innerRadius > 0) { // ----- Draw full ring. Point p0 = new Point(centerX, centerY - outerRadius); Point p1 = new Point(centerX, centerY + outerRadius); Point p2 = new Point(centerX, centerY - innerRadius); Point p3 = new Point(centerX, centerY + innerRadius); // Outer circle (= two half-circles). var figure = new PathFigure { StartPoint = p0 }; figure.Segments.Add(new ArcSegment { Point = p1, Size = new Size(outerRadius, outerRadius), SweepDirection = SweepDirection.Clockwise }); figure.Segments.Add(new ArcSegment { Point = p0, Size = new Size(outerRadius, outerRadius), SweepDirection = SweepDirection.Clockwise }); _sectorGeometry.Figures.Add(figure); // Inner circle (= two half-circles). figure = new PathFigure { StartPoint = p2 }; figure.Segments.Add(new ArcSegment { Point = p3, Size = new Size(innerRadius, innerRadius), SweepDirection = SweepDirection.Clockwise }); figure.Segments.Add(new ArcSegment { Point = p2, Size = new Size(innerRadius, innerRadius), SweepDirection = SweepDirection.Clockwise }); _sectorGeometry.Figures.Add(figure); } else { // ----- Draw full disc. Point p0 = new Point(centerX, centerY - outerRadius); Point p1 = new Point(centerX, centerY + outerRadius); // Outer circle (= two half-circles). var figure = new PathFigure { StartPoint = p0 }; figure.Segments.Add(new ArcSegment { Point = p1, Size = new Size(outerRadius, outerRadius), SweepDirection = SweepDirection.Clockwise }); figure.Segments.Add(new ArcSegment { Point = p0, Size = new Size(outerRadius, outerRadius), SweepDirection = SweepDirection.Clockwise }); _sectorGeometry.Figures.Add(figure); } } // ----- Draw inner label. if (InnerLabel != null && angle > InnerLabelClipAngle) { _innerLabel.Visibility = Visibility.Visible; _innerLabel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); Size size = _innerLabel.DesiredSize; if (size.Width > 0 && size.Height > 0) { double x = centerX + innerRadius * midX + 0.6 * width * midX; double y = centerY + innerRadius * midY + 0.6 * width * midY; x -= size.Width / 2; y -= size.Height / 2; Canvas.SetLeft(_innerLabel, x); Canvas.SetTop(_innerLabel, y); } } else { _innerLabel.Visibility = Visibility.Collapsed; } // ----- Draw outer label. if (OuterLabel != null && angle > OuterLabelClipAngle) { _outerLabel.Visibility = Visibility.Visible; _outerLabel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); Size size = _outerLabel.DesiredSize; if (size.Width > 0 && size.Height > 0) { // Draw leader line. double outerLabelDistance = LeaderLineLength; double l1 = 0.667 * outerLabelDistance; // Segment normal to circle. double l2 = 0.333 * outerLabelDistance; // Horizontal segment. double d = 0.5 * l2; // Distance between line and label. Point p0 = new Point(centerX + outerRadius * midX, centerY + outerRadius * midY); Point p1 = new Point(centerX + (outerRadius + l1) * midX, centerY + (outerRadius + l1) * midY); Point p2 = new Point(p1.X + l2 * Math.Sign(midX), p1.Y); var line = new PathFigure { StartPoint = p0 }; line.Segments.Add(new LineSegment { Point = p1 }); line.Segments.Add(new LineSegment { Point = p2 }); _leaderLineGeometry.Figures.Add(line); if (midX >= 0) { // Label on the right. Canvas.SetLeft(_outerLabel, p2.X + d); Canvas.SetTop(_outerLabel, p2.Y - size.Height / 2); } else { // Label on the left. Canvas.SetLeft(_outerLabel, p2.X - d - size.Width); Canvas.SetTop(_outerLabel, p2.Y - size.Height / 2); } } } else { _outerLabel.Visibility = Visibility.Collapsed; } _isValid = true; }
private void ClearOverlayRelative() { pathFigure.Segments.Clear(); pathGeometry.Clear(); TopAnnotationLayer.Children.Clear(); }
private void DoAnimation() { if (start == finish) { return; } PathGeometry pathGeometry = new PathGeometry(); PathFigure pathFigure = new PathFigure(); Point startingFrom = start.coord; startingFrom.X -= 20; startingFrom.Y -= 20; pathFigure.StartPoint = startingFrom; pathFigure.Segments.Add(bezie); pathGeometry.Figures.Add(pathFigure); NameScope.SetNameScope(this, new NameScope()); DoubleAnimationUsingPath transX = new DoubleAnimationUsingPath(); DoubleAnimationUsingPath transY = new DoubleAnimationUsingPath(); Rectangle aRectangle = new Rectangle(); aRectangle.Width = 40; aRectangle.Height = 40; aRectangle.Fill = ballBrush; TranslateTransform transform = new TranslateTransform(); this.RegisterName("Transform", transform); aRectangle.RenderTransform = transform; mainPanel.Children.Add(aRectangle); this.Content = mainPanel; transX.PathGeometry = pathGeometry; transX.Duration = TimeSpan.FromSeconds(5); transX.Source = PathAnimationSource.X; Storyboard.SetTargetName(transX, "Transform"); Storyboard.SetTargetProperty(transX, new PropertyPath(TranslateTransform.XProperty)); transY.PathGeometry = pathGeometry; transY.Duration = TimeSpan.FromSeconds(5); transY.Source = PathAnimationSource.Y; Storyboard.SetTargetName(transY, "Transform"); Storyboard.SetTargetProperty(transY, new PropertyPath(TranslateTransform.YProperty)); Storyboard storyboard = new Storyboard(); storyboard.Children.Add(transX); storyboard.Children.Add(transY); storyboard.Duration = TimeSpan.FromSeconds(7); aRectangle.Loaded += delegate(object sender, RoutedEventArgs e) { storyboard.Begin(this); }; storyboard.Completed += delegate(object sender, EventArgs e) { pathGeometry.Clear(); mainPanel.Children.Remove(aRectangle); }; }