SimplGraphics Wiki
provides simple geometry oriented graphics based on gdi+
Brought to you by:
skyracer1
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using SimpleGraphics; using SimpleGeometry; using SimpleGeometry.factories; namespace TestLab { public partial class Form1 : Form { private ISimpleGraphics _gh; public Form1() { InitializeComponent(); //create new theadsafe GraphicsHelper object //with a new GCanvas object that holds the reference to the Form object _gh = new GraphicsHelperThreadSafe( new GCanvas(this)); //set offset for y inversion (typically 30) _gh.setCanvasYOffset( new GNumericValue(30)); //_gh.setAxisSwapMode(AxisSwapMode.INVERTYAXIS); } private void Form1_Click(object sender, EventArgs e) { //clear _gh.paintClearingRectangle(_gh.BackgroundColor); //create a line with 2 points IWinPoint p1 = new WinPoint(100, 100); IWinPoint p2 = new WinPoint(200, 600); ILine line = new GLine(p1, p2); //create a numerical value INumericValue distance = new GNumericValue(65); //paint a circle _gh.paintEllipse(Color.Blue, 2, p1, new GNumericValue(80)); //create an anchor point and a rectangle IWinPoint pRect = new WinPoint(line.getPointOnLine(distance)); IRectangle rect = new GRectangle(pRect, new GNumericValue(60), .7); //a block is a quare IWinPoint pBlock = new WinPoint(line.getPointOnLine(pRect, distance)); IBlock block = new GBlock(pBlock, new GNumericValue(50)); //a box is an extended rectangle that is optimized for painting IWinPoint pBox = new WinPoint(line.getPointOnLine(pBlock, distance)); IBox box = new GBox(pBox, new GNumericValue(70), .4); //a figure is a very rudimentary direction indicator IWinPoint pFigure = new WinPoint(line.getPointOnLine(pBox, distance)); IFigure f = new GFigure("a", pFigure, new GNumericValue(90), new GNumericValue(20)); //now paint all that //notice how the figures are located along the line that was first created //their anchor point has the same distance _gh.paintLine(Color.Yellow, 1, line); _gh.paintPolygon(Color.Black, 1, rect.Polygon); _gh.paintBlock(Color.Red, 2, block); _gh.paintBox(Color.YellowGreen, 4, box); _gh.paintFigure(f, Color.Green, 2, Color.Tomato, 2, 100); //clear _gh.paintClearingRectangle(_gh.BackgroundColor); //the block factory has additional methods to do this. execute and see :-) BlockFactory bf = new BlockFactory(); for (int i = 1; i < 400; i++) { line = new GLine( new WinPoint(300, 300), new GNumericValue(i), new GNumericValue(140)); block = bf.createNew(line.P2, new GNumericValue(35), false); _gh.paintBlock(Color.Blue, 2, block); } _gh.paintEllipse(Color.Black, 1, line.P1, new GNumericValue(140)); } } }