Advertisement
vovan333

C# Penis Drawer

May 17th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.68 KB | None | 0 0
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4.  
  5. namespace Canvas
  6. {
  7.     internal enum Tool
  8.     {
  9.         Brush = 0,
  10.         Line = 1,
  11.         Circles = 2,
  12.         Eraser = 3
  13.     }
  14.  
  15.     public partial class Form1 : Form
  16.     {
  17.         public Form1()
  18.         {
  19.             InitializeComponent();
  20.         }
  21.  
  22.         private Color BrushColor = Color.Black;
  23.         private Tool CurrentTool = Tool.Brush;
  24.         private Graphics Canvas;
  25.         private bool IsDrawing = false;
  26.         private Point Point1;
  27.         private Point Point2;
  28.  
  29.         private void InitializeCanvas()
  30.         {
  31.             Canvas = canvas.CreateGraphics();
  32.         }
  33.  
  34.         private void SetAppState(string state)
  35.         {
  36.             statusBar.Text = state;
  37.         }
  38.  
  39.         private void Form1_Load(object sender, EventArgs e)
  40.         {
  41.             SetAppState("Ready");
  42.             UpdateColor();
  43.             InitializeCanvas();
  44.             SetCursor(Cursors.Cross);
  45.         }
  46.  
  47.         private void UpdateColor()
  48.         {
  49.             colorIndicator.BackColor = BrushColor;
  50.         }
  51.  
  52.         private void SetColor(Color color)
  53.         {
  54.             this.BrushColor = color;
  55.             UpdateColor();
  56.         }
  57.  
  58.         private void colorPickerButton_Click(object sender, EventArgs e)
  59.         {
  60.             DialogResult result = colorDialog1.ShowDialog();
  61.             if (result == DialogResult.OK)
  62.             {
  63.                 SetColor(colorDialog1.Color);
  64.             }
  65.         }
  66.  
  67.         private void brushToolButton_CheckedChanged(object sender, EventArgs e)
  68.         {
  69.             CurrentTool = Tool.Brush;
  70.             SetCursor(Cursors.Cross);
  71.         }
  72.  
  73.         private void canvas_MouseDown(object sender, MouseEventArgs e)
  74.         {
  75.             Point1 = new Point(e.X, e.Y);
  76.             IsDrawing = true;
  77.             SetAppState("Drawing");
  78.         }
  79.  
  80.         private void DrawLine(Point pt1, Point pt2)
  81.         {
  82.             DrawLine(pt1, pt2, GetLineSz());
  83.         }
  84.  
  85.         private void DrawLine(Point pt1, Point pt2, int sz)
  86.         {
  87.             Pen pen = new Pen(new SolidBrush(CurrentTool != Tool.Eraser ? BrushColor : Color.White), sz);
  88.             Point[] points = { pt1, pt2 };
  89.             int tensity = GetInt(tensityTb.Text);
  90.             Canvas.DrawCurve(pen, points, tensity);
  91.         }
  92.  
  93.         private void canvas_MouseUp(object sender, MouseEventArgs e)
  94.         {
  95.             if (CurrentTool == Tool.Line)
  96.             {
  97.                 Point2 = new Point(e.X, e.Y);
  98.                 DrawLine(Point1, Point2);
  99.             };
  100.             IsDrawing = false;
  101.             SetAppState("Ready");
  102.         }
  103.  
  104.         private void DrawCircle(Point pt, int sz)
  105.         {
  106.             Pen pen = new Pen(BrushColor);
  107.             Canvas.DrawEllipse(pen, pt.X, pt.Y, sz, sz);
  108.         }
  109.  
  110.         private void canvas_MouseMove(object sender, MouseEventArgs e)
  111.         {
  112.             if(IsDrawing)
  113.             {
  114.                 if (CurrentTool == Tool.Brush || CurrentTool == Tool.Eraser)
  115.                 {
  116.                     Point2 = new Point(e.X, e.Y);
  117.                     DrawLine(Point1, Point2);
  118.                     Point1 = Point2;
  119.                 }
  120.                 else if (CurrentTool == Tool.Circles)
  121.                 {
  122.                    
  123.                     Point pt = new Point((new Random()).Next(10, 500), (new Random()).Next(10, 500));
  124.                     DrawCircle(pt, (new Random()).Next(10, 5000));
  125.                 }
  126.             }
  127.         }
  128.  
  129.         private int GetInt(string str)
  130.         {
  131.             try
  132.             {
  133.                 return Int32.Parse(str);
  134.             }
  135.             catch (FormatException)
  136.             {
  137.                 return 0;
  138.             }
  139.         }
  140.  
  141.         private int GetLineSz()
  142.         {
  143.             return GetInt(brushSz.Text);
  144.         }
  145.  
  146.         private void ClearCanvas()
  147.         {
  148.             canvas.Image = null;
  149.         }
  150.  
  151.         private void clearCanvasButton_Click(object sender, EventArgs e)
  152.         {
  153.             ClearCanvas();
  154.         }
  155.  
  156.         private void SetCursor(Cursor cursor)
  157.         {
  158.             canvas.Cursor = cursor;
  159.         }
  160.  
  161.         private void rubberToolButton_CheckedChanged(object sender, EventArgs e)
  162.         {
  163.             CurrentTool = Tool.Eraser;
  164.             SetCursor(Cursors.Hand);
  165.         }
  166.  
  167.         private void lineToolButton_CheckedChanged(object sender, EventArgs e)
  168.         {
  169.             CurrentTool = Tool.Line;
  170.         }
  171.  
  172.         private void circlesToolButton_CheckedChanged(object sender, EventArgs e)
  173.         {
  174.             CurrentTool = Tool.Circles;
  175.             SetCursor(Cursors.WaitCursor);
  176.         }
  177.     }
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement