//NB: if button pushed again, we'll just add 10 more Shapes. private void btnGo_Click(object sender, EventArgs e) { //If timer is running, it could goof with my list. tmrAddShapes.Enabled = false; //Make sure I got a canvas if (canvas is null || canvas.DrawerWindowSize.IsEmpty) { canvas = new CDrawer(canvWidth, canvHeight); } //Set my Shapes to bounce on that size canvas Shape.SetCanvasProperties(canvas); //Create my list of 10 Shapes, obeying the rules for //resolving conflicts newShapes = new List <Shape>(10); while (newShapes.Count < 10) { Shape shape = random.Next(2) == 0 ? new Circle() : new Ellipse(); if (!newShapes.Contains(shape)) { newShapes.Add(shape); } } //Sort them newShapes.Sort(); //Start adding them to the animation by letting my timer go. tmrAddShapes.Enabled = true; }
public void Render(CDrawer canvas, Color bColor) { const int ballSize = 10; canvas.AddCenteredEllipse(_pos.X, _pos.Y, ballSize, ballSize, bColor); canvas.Render(); }
virtual public void Render(CDrawer canvas) { if (obj != null) { canvas.AddLine((int)point.X, (int)point.Y, (int)obj.point.X, (int)obj.point.Y, Color.White); } }
public static void DrawWorldMap(Location CurrentLocation) { CDrawer Canvas = new CDrawer(1000, 1000); Canvas.Clear(); Canvas.Scale = 50; int[] cordarray = new int[2] { 0, 0 }; for (int row = 0; row < MapArray.GetLength(0); row++) { for (int columb = 0; columb < MapArray.GetLength(1); columb++) { foreach (Location locals in Locations) { if (locals.Coordinates.SequenceEqual(cordarray)) { Canvas.SetBBScaledPixel(row, columb, Color.Red); Canvas.AddText(locals.Name, 10, row, columb, 1, 1, Color.White); } if (CurrentLocation.Coordinates.SequenceEqual(cordarray)) { Canvas.SetBBScaledPixel(row, columb, Color.Green); } } cordarray[1]++; } cordarray[1] = 0; cordarray[0]++; } }
public virtual void Render(CDrawer dr) { if (_parentShape != null) { dr.AddLine((int)_pos.X, (int)_pos.Y, (int)_parentShape._pos.X, (int)_parentShape._pos.Y, Color.White); } }
/// <summary> /// display blocks on certian key stroke /// set boundaris for gdi window /// </summary> /// <param name="drawer"></param> public virtual void ShowBlock(CDrawer drawer) { // Create a Size structure. SizeF inflateSize = new SizeF(3, 3); //Use one of the RectangleF helper methods to determine if the block center point has exceeded the CDrawer boundaries //make rect obj based on cdrwar dimensions//thecn check if out //btm of gdi if (localSize.IntersectsWith(new RectangleF(0, drawer.ScaledHeight + (localSize.Height / 2), drawer.ScaledWidth, 10))) { outside = true; return; } //left border if (localSize.IntersectsWith(new RectangleF(0 - (localSize.Width / 2) - 10, 0, 10, drawer.ScaledHeight))) { outside = true; return; } //right border if (localSize.IntersectsWith(new RectangleF(drawer.ScaledWidth + (localSize.Width / 2), 0, 10, drawer.ScaledHeight))) { outside = true; return; } else { //draw black rect(copy) //then draw real rect on top of it RectangleF temp = localSize; temp.Inflate(inflateSize); drawer.AddRectangle((int)temp.X, (int)temp.Y, (int)temp.Width, (int)temp.Height, Color.Black);//background square } }
public Form1() { InitializeComponent(); canvas = new CDrawer(); canvas.MouseLeftClick += Canvas_MouseLeftClick; canvas.MouseRightClick += Canvas_MouseRightClick; }
/// <summary> /// returns a rect and has CDrawer arg /// sets up rectangles to be drwan at random points /// </summary> /// <param name="drawer"></param> /// <returns></returns> public Rectangle NextDrawerRect(CDrawer drawer) { //If the CDrawer is not valid, throw an ArgumentException if (drawer == null) { throw new ArgumentException("drawer noit valid"); } //if the Maximum size exceeds the CDrawer bounds use cdrawer coundaries if (maxSize < 10) { maxSize = 10; } if (maxSize > drawer.ScaledHeight) { maxSize = drawer.ScaledHeight; } if (maxSize > drawer.ScaledWidth) { maxSize = drawer.ScaledWidth; } //rect sized between 10 and the Maximum size( new member field ) of the CDrawer and with[X, Y] coordinates //rect randomized somewhere so the Rectangle is always fully visible Size size = new Size(Next(10, maxSize), Next(10, maxSize)); Point point = new Point(); point.Y = Next(drawer.ScaledHeight - size.Height); point.X = Next(drawer.ScaledWidth - size.Width); //create a new Rectangle object Rectangle rect = new Rectangle(point, size); return(rect); }
public Fungus(Point s, CDrawer c, EColor e) { this.canvas = c; this.start = s; this.e = e; this.color_strength = 64; }
public Form1() { InitializeComponent(); _draw = new CDrawer(WIDTH, HEIGHT); // make gdi window timer1.Start(); // allow cliking in gdi window }
/// <summary> /// alternate method of set position method that uses a cdrawer instead of form app /// </summary> /// <param name="position"></param> /// <param name="drawer"></param> void SetPosition(EPosition position, CDrawer drawer) { Point local = drawer.Position;//pos of form switch (position) { case EPosition.eRight: local.X += drawer.ScaledWidth; break; case EPosition.eBelow: local.Y += drawer.ScaledHeight; break; case EPosition.eBelowRight: local.X += drawer.ScaledWidth; local.Y += drawer.ScaledHeight; break; case EPosition.eNone: local.X += drawer.ScaledWidth; break; default: break; } Position = local; }
public void MoveBall(CDrawer canvas) { if ((pLocation.X + velX + Ballrad) >= canvas.ScaledWidth || (pLocation.X + velX - Ballrad) <= 0) { if ((pLocation.X + velX + Ballrad) >= canvas.ScaledWidth) { pLocation.X = canvas.ScaledWidth - Ballrad; } else if ((pLocation.X += velX - Ballrad) <= 0) { pLocation.X = 0 + Ballrad; } velX = -velX; } if ((pLocation.Y + velY + Ballrad) >= canvas.ScaledHeight || (pLocation.Y + velY - Ballrad) <= 0) { if ((pLocation.Y + velY + Ballrad) >= canvas.ScaledHeight) { pLocation.Y = canvas.ScaledHeight - Ballrad; } else if ((pLocation.Y += velY - Ballrad) <= 0) { pLocation.Y = 0 + Ballrad; } velY = -velY; } pLocation.Y += velY; pLocation.X += velX; }
//****************************************************** //Render Method: Draw the shape as a Polygon //****************************************************** public override void Render(CDrawer drawer) { //Draw line to parent base.Render(drawer); drawer.AddPolygon((int)_position.X, (int)_position.Y, _size, _sides, _sequence, _color); }
static void RandomBlocks() { Random rnd = new Random(); CDrawer can = new CDrawer(); System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); watch.Reset(); watch.Start(); can.AddText("Random Known Colors SetBBPixel : 2s", 28, 0, 0, can.ScaledWidth, can.ScaledHeight, Color.White); can.AddText("Random Known Colors SetBBPixel : 2s", 28, 2, 2, can.ScaledWidth + 2, can.ScaledHeight + 2, Color.Black); while (watch.ElapsedMilliseconds < 2000) { can.SetBBPixel(rnd.Next(can.ScaledWidth), rnd.Next(can.ScaledHeight), RandColor.GetKnownColor()); } can.Close(); can = new CDrawer(800, 800); can.Scale = 10; Console.WriteLine("Random Known Colors SetBBScaledPixel : 2s"); watch.Reset(); watch.Start(); can.AddText("Random Known Colors SetBBScaledPixel : 2s", 24); while (watch.ElapsedMilliseconds < 2000) { can.SetBBScaledPixel(rnd.Next(can.ScaledWidth), rnd.Next(can.ScaledHeight), RandColor.GetKnownColor()); } can.Close(); }
//NB: if button pushed again, we'll just add 10 more balls. private void btnGo_Click(object sender, EventArgs e) { //If timer is running, it could goof with my list. tmrAddBalls.Enabled = false; //Make sure I got a canvas if (canvas is null || canvas.DrawerWindowSize.IsEmpty) { canvas = new CDrawer(canvWidth, canvHeight); } //Set my balls to bounce on that size canvas Ball.SetCanvasProperties(canvas); //Create my list of 10 balls, obeying the rules for //resolving conflicts newBalls = new List <Ball>(10); while (newBalls.Count < 10) { Ball ball = new Ball(true); if (!newBalls.Contains(ball)) { newBalls.Add(ball); } } //Sort them newBalls.Sort(); //Start adding them to the animation by letting my timer go. tmrAddBalls.Enabled = true; }
private void UI_BTN_Play_Click(object sender, EventArgs e) { if (_canvas == null) { _canvas = new CDrawer(800, 600 + OFFSET); } _canvas.Clear(); _score = 0; if (UI_RB_Easy.Checked) { Randomize(Difficulty.Easy); } else if (UI_RB_Medium.Checked) { Randomize(Difficulty.Medium); } else { Randomize(Difficulty.Hard); } Display(); UI_Timer.Enabled = true; UI_BTN_Play.Enabled = false; }
public static void SetCanvasProperties(CDrawer canvas) { //Reset static canvas size based on the sample I just got CanvasWidth = canvas.ScaledWidth; CanvasHeight = canvas.ScaledHeight; MaxSize = CanvasWidth / 5; }
static Block() { Height = 20; Canvas = new CDrawer(); Canvas.BBColour = Color.White; Canvas.ContinuousUpdate = false; }
const int unitValue4 = 10; // 30pixels for unit x and y value static void Main(string[] args) { //make a canvas for graph CDrawer canvas = new CDrawer(); // y = Amplitude.sin(AngularFrequency.x + PhaseAngle) + VerticalOffset // a = Amplitude || f = AngularFrequency || p = Phase angle || v = VerticalOffset bool success = false; bool success2 = false; double a = 0.00; double f = 0.00; double p = 0.00; double v = 0.00; ConsoleKeyInfo userChoice; Grid(canvas); do { do { userChoice = GetUserChoice("Action: "); Console.WriteLine(userChoice); } while (!success); Console.Clear(); } while (!success2); Console.ReadKey(); }
// Thread to traverse 2D grid in random fashion private void TraverseGridRandomly() { int steps = 0; CDrawer canvas = new CDrawer(WIDTH, HEIGHT); int[,] grid = new int[X_MAX, Y_MAX]; // 2D backing array for the grid Point current = new Point(0, 0); Point previous = new Point(0, 0); List <Point> nextPossiblePoint = new List <Point>(); // List of valid moves canvas.Scale = BLOCKSIZE; // Initialize each grid location with nominal value; for (int x = 0; x < X_MAX; ++x) { for (int y = 0; y < Y_MAX; ++y) { grid[x, y] = BASE_RGB_VALUE; } } while (!HasTravelledAll(grid)) { ++steps; // Increment intensity of current color to max of 255 grid[current.X, current.Y] = grid[current.X, current.Y] + 3 > 255 ? 255 : grid[current.X, current.Y] + 3; // Draw previous point in yellow - ignore initial start if (steps != 1) { canvas.SetBBScaledPixel(previous.X, previous.Y, Color.FromArgb(grid[previous.X, previous.Y], grid[previous.X, previous.Y], 0)); } // Draw current point location in red canvas.SetBBScaledPixel(current.X, current.Y, Color.Red); previous = current; // Clear previous list of valid movement and update list and move to new Point nextPossiblePoint.Clear(); nextPossiblePoint = validLocation(current); current = nextPossiblePoint[_rnd.Next(0, nextPossiblePoint.Count)]; } // Display number of steps on screen canvas.AddText(steps.ToString() + " Steps Taken", 25, Color.Blue); try { Invoke(new delVoidInt(UpdateUI), steps); } catch { System.Diagnostics.Trace.WriteLine("Target thread is dead"); } }
/// <summary> /// get balls to move and bounce around in gdi windows /// </summary> /// <param name="cDrawer"></param> public void Move(CDrawer cDrawer) { ballCenter.X += xVel; ballCenter.Y += yVel; //bounce off left wall if (ballCenter.X - radius < 0) { xVel = -xVel; ballCenter.X = radius; } //bounce off right wall if (ballCenter.X + radius > cDrawer.ScaledWidth) { xVel = -xVel; ballCenter.X = cDrawer.ScaledWidth - radius; } //bounce off top wall if (ballCenter.Y - radius < 0) { yVel = -yVel; ballCenter.Y = radius; } //bounce off bottom wall if (ballCenter.Y + radius > cDrawer.ScaledHeight) { yVel = -yVel; ballCenter.Y = cDrawer.ScaledHeight - radius; } }
//****************************************************** //Render Method: Draw shape as a ball. //****************************************************** public override void Render(CDrawer drawer) { //Draw line to parent base.Render(drawer); drawer?.AddCenteredEllipse((int)_position.X, (int)_position.Y, _size, _size, _color); }
static Bar() { Height = 20; drawer = new CDrawer(); drawer.BBColour = Color.White; drawer.ContinuousUpdate = false; }
//Take in a canvas and scale, draw all of the blocks public void Render(CDrawer canvas, int Size) { canvas.Clear(); for (int x = 0; x < XLength; x++) { for (int y = 0; y < YLength; y++) { //Ignore nulls and retainer blocks, don't need to render them if (grid[x, y] != null && !(grid[x, y] is RetainerBlock)) { //Centered point Point point = new Point(x * Size + (Size / 2), y * Size + (Size / 2)); //If free block, offset the point by Animation state if (grid[x, y] is FreeBlock && grid[x, y].life != Life.Dying) { point.Y += (Size / 10) * grid[x, y].AnimationState; //Move down 1/10 of the size, per AnimationState } //Get our side length, shrunk by death int sideLength = Size; if (grid[x, y].life == Life.Dying) { // (-10%) * State + Size sideLength = (-(Size / 10)) * grid[x, y].AnimationState + Size; //Shrink by 10% of size for every AnimationState } //Add every block using the point and size we just made canvas.AddCenteredRectangle(point.X, point.Y, sideLength, sideLength, grid[x, y].Colour, 1, Color.Black); } } } canvas.Render(); }
public DrawerWnd(CDrawer dr) { InitializeComponent(); // use the log as built from parent _log = dr._log; // save window size m_ciWidth = dr.m_ciWidth; m_ciHeight = dr.m_ciHeight; // cap delegates, this will be set by owner m_delRender = null; m_delMouseMove = null; m_delMouseLeftClick = null; m_delMouseRightClick = null; // cap/set references m_bgc = new BufferedGraphicsContext(); m_bg = null; // create the bitmap for the underlay and clear it to whatever colour m_bmUnderlay = new Bitmap(dr.m_ciWidth, dr.m_ciHeight); // docs say will use Format32bppArgb // fill the bitmap with the default drawer bb colour FillBB(Color.Black); // show that drawer is up and running _log.WriteLine("Drawer Started..."); }
//****************************************************** //Render Method: Draw beizer around the parent shape. //****************************************************** public override void Render(CDrawer drawer) { //Draw line to parent base.Render(drawer); drawer?.AddBezier(_startPoint.X, _startPoint.Y, _ControlPoint1.X, _ControlPoint1.Y, _ControlPoint2.X, _ControlPoint2.Y, _endPoint.X, _endPoint.Y, Color.White, 1); }
public void Move(CDrawer cDrawer) { ballCenter.X += xVel; ballCenter.Y += yVel; if (ballCenter.X - radius < 0) { xVel = -xVel; ballCenter.X = 0 + radius; } if (ballCenter.X + radius > cDrawer.ScaledWidth) { xVel = -xVel; ballCenter.X = cDrawer.ScaledWidth - radius; } if (ballCenter.Y - radius < 0) { yVel = -yVel; ballCenter.Y = 0 + radius; } if (ballCenter.Y + radius > cDrawer.ScaledHeight) { yVel = -yVel; ballCenter.Y = cDrawer.ScaledHeight - radius; } }
/// <summary> /// keep track of current key state(s) /// </summary> /// <param name="bIsDown"></param> /// <param name="keyCode"></param> /// <param name="dr"></param> private void Pic_KeyboardEvent(bool bIsDown, Keys keyCode, CDrawer dr) { if (keyCode == Keys.F) { state = keyCode; } if (keyCode == Keys.D) { state = keyCode; } if (keyCode == Keys.C) { state = keyCode; } if (keyCode == Keys.Escape) { state = keyCode; } if (keyCode == Keys.F1) { state = keyCode; } }
public Form1() { InitializeComponent(); this.StartPosition = FormStartPosition.Manual; this.Location = new Point(10, 10); _greenBlueGDI = new CDrawer(800, 400);//main Point GDIpos = new Point(this.Width, this.Height); GDIpos.X += _greenBlueGDI.ScaledWidth; GDIpos.Y += _greenBlueGDI.ScaledHeight; _greenBlueGDI.Position = new Point(this.Width, this.Height - 250); //drawer position above colided gdi window _greenBlueGDI.ContinuousUpdate = false; //secondary window(red balls/green blue ball colision) _collidedGDI = new CDrawer(800, 400); _collidedGDI.Position = new Point(this.Width, _greenBlueGDI.ScaledHeight + 50); _collidedGDI.ContinuousUpdate = false; _greenBlueGDI.MouseLeftClick += _greenBlueGDI_MouseLeftClick; _greenBlueGDI.MouseRightClick += _greenBlueGDI_MouseRightClick; _timer.Tick += _timer_Tick; _timer.Interval = 20; _timer.Enabled = true; }
private void SetGuard(CDrawer dr, int ix, int iy, Color col) { if (ix >= 0 && ix < dr.m_ciWidth && iy >= 0 && iy < dr.m_ciHeight) { dr.SetBBPixel(ix, iy, col); } }