private void lineTo(BMyPoint target, BMyCanvas canvas) { int x, y, t, deltaX, deltaY, incrementX, incrementY, pdx, pdy, ddx, ddy, es, el, err; BMyPoint origin = canvas.Position; deltaX = target.X - origin.X; deltaY = target.Y - origin.Y; incrementX = Math.Sign(deltaX); incrementY = Math.Sign(deltaY); if (deltaX < 0) { deltaX = -deltaX; } if (deltaY < 0) { deltaY = -deltaY; } if (deltaX > deltaY) { pdx = incrementX; pdy = 0; ddx = incrementX; ddy = incrementY; es = deltaY; el = deltaX; } else { pdx = 0; pdy = incrementY; ddx = incrementX; ddy = incrementY; es = deltaX; el = deltaY; } x = origin.X; y = origin.Y; err = el / 2; canvas.TrySetPixel(x, y); for (t = 0; t < el; ++t) { err -= es; if (err < 0) { err += el; x += ddx; y += ddy; } else { x += pdx; y += pdy; } canvas.TrySetPixel(x, y); } }
private void setSymetric(int x, int y, BMyCanvas canvas) { BMyPoint o = canvas.Position; canvas.TrySetPixel(o.X + x, o.Y + y, false); canvas.TrySetPixel(o.X + y, o.Y + x, false); canvas.TrySetPixel(o.X + y, o.Y + -x, false); canvas.TrySetPixel(o.X + x, o.Y + -y, false); canvas.TrySetPixel(o.X + -x, o.Y + -y, false); canvas.TrySetPixel(o.X + -y, o.Y + -x, false); canvas.TrySetPixel(o.X + -y, o.Y + x, false); canvas.TrySetPixel(o.X + -x, o.Y + y, false); }
public bool TrySetPixel(int x, int y, bool moveto = true) { if (isInBounds(x, y)) { _raster[x][y] = color.ToChar(); if (moveto) { Position = new BMyPoint(x, y); } return(true); } else { return(false); } }
public override bool TryRun(BMyDrawingCommand command, BMyCanvas canvas, BMyEnvironment Env) { string[] argv = command.Args.Split(new char[] { ',' }); int x; int y; if ( argv.Length == 2 && int.TryParse(argv[0], out x) && int.TryParse(argv[1], out y) ) { BMyPoint target = new BMyPoint(x, y); lineTo(target, canvas); return(true); } else { return(false); } }
public override bool TryRun(BMyDrawingCommand command, BMyCanvas canvas, BMyEnvironment Env) { string[] argv = command.Args.Split(new char[] { ',' }); int x; int y; if ( argv.Length == 2 && int.TryParse(argv[0], out x) && int.TryParse(argv[1], out y) ) { bool success = false; BMyPoint origin = canvas.Position; BMyDrawingCommand linetoCommand = new BMyDrawingCommand(string.Format(@"lineto {0},{1}", x, origin.Y)); if (Env.TryRunDraw(linetoCommand, canvas)) { linetoCommand = new BMyDrawingCommand(string.Format(@"lineto {0},{1}", x, y)); if (Env.TryRunDraw(linetoCommand, canvas)) { linetoCommand = new BMyDrawingCommand(string.Format(@"lineto {0},{1}", origin.X, y)); if (Env.TryRunDraw(linetoCommand, canvas)) { linetoCommand = new BMyDrawingCommand(string.Format(@"lineto {0},{1}", origin.X, origin.Y)); if (Env.TryRunDraw(linetoCommand, canvas)) { success = true; } } } } canvas.Position = new BMyPoint(x, y); return(success); } else { return(false); } }