private void UI_List_Butt_Click(object sender, EventArgs e) { pointList.Clear(); while (pointList.Count != ((canvas.ScaledWidth / (int)UI_NumUpDown.Value) * (canvas.ScaledHeight / (int)UI_NumUpDown.Value))) { Point newPoint = new Point(rng.Next(0, (canvas.ScaledWidth / (int)UI_NumUpDown.Value)) * (int)UI_NumUpDown.Value, rng.Next(0, (canvas.ScaledHeight / (int)UI_NumUpDown.Value)) * (int)UI_NumUpDown.Value); if (pointList.Count == 0) { pointList.Add(newPoint); } else { if (!pointList.Contains(newPoint)) { pointList.Add(newPoint); } } } canvas.Clear(); for (int i = 0; i < pointList.Count - 1; i++) { canvas.AddLine(pointList[i].X, pointList[i].Y, pointList[i + 1].X, pointList[i + 1].Y, Color.Magenta); } canvas.Render(); Text = "Made N Points"; UI_List_Butt.Text = "List contains: " + pointList.Count + " points"; }
//[Make List] //extract the divisor as an integer.Using that divisor and the ScaledWidth and ScaledHeight of the CDrawer //use nested for() loops to generate all possible Points within the CDrawer window (based on the divisor increments) private void MakeList_Click(object sender, EventArgs e) { int divisor = (int)divisorUpDown.Value; //nested loops to generate all points in cdrawer for (int y = 0; y < drawer.ScaledHeight; y += divisor) //y vals { for (int x = 0; x < drawer.ScaledWidth; x += divisor) //x vals { ptr.Add(new Point(x, y)); } } //once list has been populated , clear the drawer drawer.Clear(); //itterate through list points while drawing fuchsia lines between all adjcent points for (int i = 1; i < ptr.Count; i++) { if (i != 1) { drawer.AddLine(ptr[i - 1].X, ptr[i - 1].Y, ptr[i].X, ptr[i].Y, Color.Fuchsia); } } //render drawn lines drawer.Render(); //display number of points in list ListButton.Text = $"List contains: {ptr.Count} points"; }
// Button Constructor/Controller; User selects button and returns a char static char SelectLetter(ref CDrawer HangingPost) { char selection = ' '; Point click; bool valid_click = false; int counter = 0; // Generate buttons var button = new Button[26]; //create array of class Button for (int i = 0; i < 26; i++) { button[i] = new Button(); //construct new Button for each element in array button[i].alpha = (char)(i + 65); if (i < 13) { button[i].xMin_coord = 250 + counter * 40; button[i].xMax_coord = button[i].xMin_coord + 30; button[i].yMin_coord = 10; button[i].yMax_coord = 40; } else { button[i].xMin_coord = 250 + counter * 40; button[i].xMax_coord = button[i].xMin_coord + 30; button[i].yMin_coord = 50; button[i].yMax_coord = 80; } counter++; if (counter >= 13) { counter = 0; } } while (!valid_click) { if (HangingPost.GetLastMouseLeftClick(out click)) { for (int i = 0; i < 26; i++) { int xmin = button[i].xMin_coord; int xmax = button[i].xMax_coord; int ymin = button[i].yMin_coord; int ymax = button[i].yMax_coord; if (click.X > xmin && click.X < xmax && click.Y > ymin && click.Y < ymax) { HangingPost.AddLine(xmin, ymin, xmax, ymax, Color.Red, 2); HangingPost.AddLine(xmax, ymin, xmin, ymax, Color.Red, 2); HangingPost.Render(); selection = button[i].alpha; valid_click = true; } } } } return(selection); }
public void Render(CDrawer canvas, Point lPoint) { if (_flag == false) { canvas.AddLine(lPoint, _length, Math.PI, Color.Red, _width); } else { canvas.AddLine(lPoint, _length, Math.PI, Color.Yellow, _width); } }
// Main Menu Screen public static void MainMenu(ref CDrawer HangingPost) { bool play_game = false; Point click; HangingPost.Clear(); ////Draw hanged man, can use this for reference later //HangingPost.AddCenteredEllipse(270, 215, 50, 50, Color.Black); //head //HangingPost.AddLine(250, 215, 245, 285, Color.Black, 5); //torso //HangingPost.AddLine(250, 215, 230, 305, Color.Black, 5); //right arm //HangingPost.AddLine(250, 215, 270, 305, Color.Black, 5); //left arm //HangingPost.AddLine(245, 285, 230, 365, Color.Black, 5); //right leg //HangingPost.AddLine(245, 285, 265, 365, Color.Black, 5); //left leg ////Add peanut gallery //AddStickMan(60, 380, "Black", ref HangingPost, true); //AddStickMan(160, 420, "Black", ref HangingPost, true); //AddStickMan(300, 400, "Black", ref HangingPost, true); //AddStickMan(420, 420, "Black", ref HangingPost, true); //HangingPost.AddText("Let's Hang Someone!", 36, 0, 0, 800, 100, Color.DarkRed); //PG VERSION of Hangman HangingPost.AddCenteredEllipse(250, 245, 60, 60, Color.Empty, 5, Color.Black); //head HangingPost.AddLine(250, 275, 250, 350, Color.Black, 5); //torso HangingPost.AddLine(250, 275, 220, 360, Color.Black, 5); //left arm HangingPost.AddLine(250, 275, 280, 360, Color.Black, 5); //right arm HangingPost.AddLine(250, 350, 230, 460, Color.Black, 5); //left leg HangingPost.AddLine(250, 350, 270, 460, Color.Black, 5); //right leg HangingPost.AddText("Let's Play Hangman!", 36, 0, 0, 800, 100, Color.DarkRed); HangingPost.AddText("Click anywhere to begin...", 12, 200, 500, 800, 100); HangingPost.Render(); while (!play_game) { if (HangingPost.GetLastMouseLeftClick(out click)) { play_game = true; } } HangingPost.Clear(); //// Idle peanut gallery //AddStickMan(60, 380, "Black", ref HangingPost, false); //AddStickMan(160, 420, "Black", ref HangingPost, false); //AddStickMan(300, 400, "Black", ref HangingPost, false); //AddStickMan(420, 420, "Black", ref HangingPost, false); HangingPost.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); } }
/// <summary> /// check if missile is friendly or an enemy /// then render it /// </summary> public void DrawMissiles() { //foe missile if (whoIsIt == false) { _drawer.AddCenteredEllipse(Where(), radius * 2, radius * 2, Color.Red); _drawer.AddLine(missleStart.X, missleStart.Y, Where().X, Where().Y, Color.Red); } //friendly missile else { _drawer.AddCenteredEllipse(Where(), radius * 2, radius * 2, Color.FromArgb(alpha, Color.Green)); _drawer.AddLine(missleStart.X, missleStart.Y, Where().X, Where().Y, Color.Green); } }
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); } }
//****************************************************** //Render Method: Draw a line between the instance amd its parent(if EXISTS) //****************************************************** public virtual void Render(CDrawer drawer) { if (!object.ReferenceEquals(_parent, null)) { drawer?.AddLine((int)_position.X, (int)_position.Y, (int)_parent._position.X, (int)_parent._position.Y, Color.White, 1); } }
public void Render(CDrawer dr) { if (parent != null) { dr.AddLine(position.X, position.Y, parent.position.X, parent.position.Y, Color.White); } vRender(dr); }
static void SLines() { CDrawer can = new CDrawer(800, 600, false); can.AddLine(10, 10, 790, 590, Color.Red, 2); for (double d = 0; d < Math.PI * 2; d += Math.PI / 32) { can.AddLine(new Point(400, 300), 50 * d, d); } for (int x = 0; x < 600; x += 5) { can.AddLine(0, 600 - x, x, 0, RandColor.GetColor(), 1); } can.Render(); Console.ReadKey(); }
static private void DrawCartisan(int minX, int maxX, int minY, int maxY, CDrawer cDrawer, out int scaleX, out int scaleY) { scaleX = cDrawer.DrawerWindowSize.Width / (maxX - minX); int centerX = (-minX * scaleX); scaleY = (cDrawer.DrawerWindowSize.Height - 43) / (maxY - minY);//not the minus 43 is because cdraw does not return hiegt of draw space crrectly int centerY = (-minY * scaleY); cDrawer.AddLine(0, centerY, 900, centerY, Color.GreenYellow, 1); //adds horizontal line for (int tick = centerX - scaleX * -minX; tick <= scaleX * centerX * 2; tick += scaleX) //add hrizontal scale { cDrawer.AddLine(tick, centerY - 5, tick, centerY + 5, Color.AliceBlue, 1); } cDrawer.AddLine(centerX, 0, centerX, 600, Color.GreenYellow, 1); //add vertical line for (int tick = centerY - scaleY * -minY; tick <= scaleY * centerY * 2; tick += scaleY) //add vertical scale { cDrawer.AddLine(centerX - 5, tick, centerX + 5, tick, Color.AliceBlue, 1); } }
// Add a stick figure to drawing window with head at (x, y) in cheering pose or idle pose public static void AddStickMan(int x, int y, string color, ref CDrawer HangingPost, bool cheer) { HangingPost.AddCenteredEllipse(x, y, 50, 50, Color.FromName(color)); //head HangingPost.AddLine(x, y + 25, x, y + 95, Color.FromName(color), 5); //torso HangingPost.AddLine(x, y + 95, x - 15, y + 180, Color.FromName(color), 5); //left leg HangingPost.AddLine(x, y + 95, x + 15, y + 180, Color.FromName(color), 5); //right leg if (cheer) { HangingPost.AddLine(x, y + 40, x - 40, y - 5, Color.FromName(color), 5); //left upper arm HangingPost.AddLine(x - 40, y - 5, x - 60, y - 40, Color.FromName(color), 5); //left lower arm HangingPost.AddLine(x, y + 40, x + 40, y - 5, Color.FromName(color), 5); //right upper arm HangingPost.AddLine(x + 40, y - 5, x + 60, y - 40, Color.FromName(color), 5); //right lower arm } else { HangingPost.AddLine(x, y + 30, x - 25, y + 105, Color.FromName(color), 5); //left arm HangingPost.AddLine(x, y + 30, x + 25, y + 105, Color.FromName(color), 5); //right arm } }
static private void Graph(double a, double b, double c, int minX, int maxX, CDrawer cDrawer) { DrawCartisan(minX, maxX, -5, 5, cDrawer, out int scaleX, out int scaleY); for (double x = minX * scaleX; x < maxX * scaleX; x += 1.0 / scaleX)//at 50 scale { double x1 = x - (1.0 / scaleX); double yc = a * x * x + b * x + c; double yc1 = a * x1 * x1 + b * x1 + c; int y = Convert.ToInt32(-yc * scaleY + (scaleY * 5));//we must scale to our size int yl = Convert.ToInt32(-yc1 * scaleY + (scaleY * 5)); int xp = Convert.ToInt32(x * scaleX + (-minX * scaleX)); int xpl = Convert.ToInt32((x - (1.0 / scaleX)) * scaleX + (-minX * scaleX)); cDrawer.AddLine(xp, y, xpl, yl, Color.White, 3); } }
static void Lines() { CDrawer can = new CDrawer(800, 600, false); can.Scale = 10; for (int i = -10; i < can.ScaledWidth + 1; i += 5) { for (int j = -10; j < can.ScaledHeight + 1; j += 5) { can.AddLine(i, j, can.ScaledWidth + 1 - i, can.ScaledHeight + 1 - j, RandColor.GetKnownColor(), 1); } } can.AddText("check...check.. ", 48); can.AddText("one two three", 12, -10, -10, 100, 50, Color.White); can.Render(); Console.ReadKey(); }
static void Main(string[] args) { //int x = 0; //ConsoleKeyInfo keyPressed; //while(x < 10) //{ // Console.WriteLine(x); //++x; //} //keyPressed = Console.ReadKey(); //Console.WriteLine(keyPressed.Key); //Console.ReadKey(); /// end of that part //start of new part CDrawer canvas = new CDrawer(800, 600); Console.WriteLine("Draw Something"); canvas.AddCenteredEllipse(200, 100, 100, 100, Color.Red, 2, Color.White); canvas.AddLine(50, 50, 400, 500, Color.Green, 5); canvas.AddRectangle(400, 300, 100, 50, Color.Purple, 2, Color.White); canvas.AddText("meat", 24, Color.Magenta); canvas.AddText("Bacon", 36, 300, 150, 250, 50, Color.Lime); Console.ReadKey(); //to have random color:- "RandColor.GetColor()" }
private void Render() { Queue <Point> queueCopy; Point nextPos; _sw.Start(); while (true) { while (_sw.ElapsedMilliseconds < delay) { ; } lock (_qPoints) { queueCopy = _qPoints; } Invoke(new Action(() => LB_DrawData.Text = queueCopy.Count.ToString() + " segs in queue, estimated time to draw : " + (queueCopy.Count * delay / 1000).ToString("F1") + " seconds.")); if (queueCopy.Count > 0) { lock (_qPoints) { nextPos = _qPoints.Dequeue(); } _canvas.AddLine(_lastKnownPoint.X, _lastKnownPoint.Y, nextPos.X, nextPos.Y, Color.Red); _lastKnownPoint = nextPos; } _sw.Restart(); //Thread.Sleep(50); } }
static private void Draw() { int X = 0; int Y = 0; int A = 0; int B = 0; int avelocit = 2; int bvelocit = 2; int xvelocity = 3; int yvelocity = 3; bool operation = true; int bole = 7; bool ioperation = true; CDrawer canvas = new CDrawer(); canvas.Scale = 5; canvas.ContinuousUpdate = false; while (operation) { canvas.AddCenteredEllipse(X, Y, 10, 10, Color.Aqua, 6); canvas.AddLine(X, Y, 88, 4, Color.Red, 4); canvas.Render(); System.Threading.Thread.Sleep(10); canvas.Clear(); X += xvelocity; Y += yvelocity; if ((Y >= canvas.ScaledHeight) || (Y <= 0)) { yvelocity *= -1; } //check for left or right side of the screen if ((X >= canvas.ScaledWidth) || (X <= 0)) { xvelocity *= -1; } if (ioperation) { canvas.AddCenteredEllipse(A, B, 10, 10, Color.Red, 5); canvas.AddLine(A, B, 85, 4, Color.Blue, 6); canvas.Render(); System.Threading.Thread.Sleep(bole); canvas.Clear(); A += avelocit; _ = A != X; B += bvelocit; _ = B != Y; if ((A >= canvas.ScaledWidth) || (A <= 0)) { avelocit *= -1; } if ((B >= canvas.ScaledHeight) || (B <= 0)) { bvelocit *= -1; } } } Console.Read(); }
//*********************************************************************************** //Method: static private void DrawScreen(CDrawer canvas, ref int wrongCounter, ref int WinCond, ref string[] secretWord, ref string[] guessResult, ref bool gameOn) //Purpose: Controls all elements that will appear in GDI drawer and controls game running loop //parameters: (described in main) //*********************************************************************************** static private void DrawScreen(CDrawer canvas, ref int wrongCounter, ref int WinCond, ref string[] secretWord, ref string[] guessResult, ref string[] usedLetters, ref bool gameOn, ref int xPosition) { xPosition = 195; //incremental x position to draw the letters that have already been used //*********************************************************************************** //Draw the gallows //*********************************************************************************** //draws the rope canvas.AddLine(400, 200, 400, 250, Color.Red, 2); //main vertical scaffold beam canvas.AddLine(300, 175, 300, 450, Color.DarkOrange, 3); //scaffold arm and supporting strut //arm canvas.AddLine(300, 200, 425, 200, Color.DarkOrange, 3); //support canvas.AddLine(300, 225, 325, 200, Color.DarkOrange, 3); //scaffold floor canvas.AddLine(300, 400, 450, 400, Color.DarkOrange, 3); //front support leg canvas.AddLine(425, 400, 425, 450, Color.DarkOrange, 3); //floor supporting struts canvas.AddLine(300, 440, 425, 410, Color.DarkOrange, 3); canvas.AddLine(300, 410, 425, 440, Color.DarkOrange, 3); //*********************************************************************************** //Draws the hangman if answers are wrong //*********************************************************************************** if (wrongCounter >= 1) { //draws the head canvas.AddCenteredEllipse(400, 250, 50, 50, Color.White); } if (wrongCounter >= 2) { //draws torso canvas.AddCenteredEllipse(400, 300, 50, 100, Color.Blue); } if (wrongCounter >= 3) { //draws arm canvas.AddLine(380, 290, 350, 320, Color.Blue, 5); } if (wrongCounter >= 4) { //draws arm 2 canvas.AddLine(420, 290, 450, 320, Color.Blue, 5); } if (wrongCounter >= 5) { //draws leg 1 canvas.AddLine(410, 330, 420, 390, Color.Green, 5); } if (wrongCounter >= 6) { //draws leg 2 canvas.AddLine(390, 330, 380, 390, Color.Green, 5); } //*********************************************************************************** //Draws currently used letters and win / loss results //*********************************************************************************** //text to show the currently used letters canvas.AddText($"Letters used: ", 20, 100, 50, 400, 75, Color.White); for (int i = 0; i <= usedLetters.Length - 1; i++) { canvas.AddText($"{usedLetters[i]}", 20, xPosition, 50, 400, 75, Color.White); xPosition += 20; } //Displays result if user wins if (WinCond == 0) { //win text canvas.AddText("You Win!", 50, Color.Yellow); gameOn = false; } //Displays result if user loses else if ((WinCond > 0) && (wrongCounter == 6)) { //displays the full secret word for (int index = 0; index <= secretWord.Length - 1; index++) { guessResult[index] = secretWord[index]; } //loss text canvas.AddText("You Lose!", 50, Color.Gray); gameOn = false; } }
public void Render(CDrawer canvas) { canvas.AddLine(GetStart.X, GetStart.Y, GetEnd.X, GetEnd.Y, GetColor, GetThickness); }
// Draw Hanged Man 1 bodypart at a time public static void DisplayHangedMan(ref CDrawer HangingPost, int body_count, bool PGversion) { if (PGversion) { switch (body_count) { case 1: HangingPost.AddCenteredEllipse(250, 245, 60, 60, Color.Empty, 5, Color.Black); break; case 2: HangingPost.AddLine(250, 275, 250, 350, Color.Black, 5); break; case 3: HangingPost.AddLine(250, 275, 220, 360, Color.Black, 5); break; case 4: HangingPost.AddLine(250, 275, 280, 360, Color.Black, 5); break; case 5: HangingPost.AddLine(250, 350, 230, 460, Color.Black, 5); break; case 6: HangingPost.AddLine(250, 350, 270, 460, Color.Black, 5); break; } } else { switch (body_count) { case 1: HangingPost.AddCenteredEllipse(270, 215, 50, 50, Color.Black); break; case 2: HangingPost.AddLine(250, 215, 245, 285, Color.Black, 5); break; case 3: HangingPost.AddLine(250, 215, 230, 305, Color.Black, 5); break; case 4: HangingPost.AddLine(250, 215, 270, 305, Color.Black, 5); break; case 5: HangingPost.AddLine(245, 285, 230, 365, Color.Black, 5); break; case 6: HangingPost.AddLine(245, 285, 265, 365, Color.Black, 5); break; } } HangingPost.Render(); }
static void Main(string[] args) { Random rng = new Random(); int xVelocity = 1; //the rate at which the ball moves on the X plane int yVelocity = 1; //the rate at which the ball moves on the Y plane int xBall = 80; int yBall = 60; int wallTop = 0; //top boundry of screen/game int wallRight = 0; //right boundry of screen/game int wallBottom = 0; //bottom boundry of screen/game bool playAgain = true; Point playerPosition; //location of mouse so paddle can be appropriately set on the Y plane const int playerPositionX = 0; //the constant postion of the paddle against the left side of screen CDrawer gdi = new CDrawer(); gdi.Scale = 5; gdi.ContinuousUpdate = false; do { while (true) { //sets the boundry for the ball with as a visual for (wallTop = 0; wallTop < 160; wallTop = ++wallTop) { gdi.SetBBScaledPixel(wallTop, 0, Color.SkyBlue); } for (wallRight = 0; wallRight < 120; wallRight = ++wallRight) { gdi.SetBBScaledPixel(wallTop - 1, wallRight, Color.SkyBlue); } for (wallBottom = 0; wallBottom < 160; wallBottom = ++wallBottom) { gdi.SetBBScaledPixel(wallBottom, wallRight - 1, Color.SkyBlue); } //the ball while (xBall < wallRight && yBall < wallTop && yBall > wallBottom) { gdi.AddRectangle(xBall, yBall, 2, 2, Color.Gainsboro); //the paddle gdi.GetLastMousePosition(out playerPosition); //playerPositionYStart = playerPositionYStart + playerPosition; gdi.AddLine(playerPositionX, (playerPosition.Y + 25) / 5, playerPositionX, (playerPosition.Y - 25) / 5, Color.DarkRed, 10); //the delay, new images then removal of old images to create "animation" gdi.Render(); System.Threading.Thread.Sleep(20); gdi.Clear(); xBall += xVelocity; yBall += yVelocity; } } playAgain = false; } while (playAgain); }