Wednesday, May 21, 2014
Zau_Smiley Face Lab
namespace Zau_Smiley_Face
{
public partial class Form1 : Form
{
//declare a bitmap
Bitmap bmap;
//declare a Graphic object
Graphics g;
Random rand = new Random();
public Form1()
{
InitializeComponent();
bmap = new Bitmap(pictureBox1.Width, pictureBox1.Height);
g = Graphics.FromImage(bmap);
}
private Color GetRandomColor()
{
int red = rand.Next(256); //0 - 255)
int green = rand.Next(256);
int blue = rand.Next(256);
Color c = Color.FromArgb(red, green, blue);
return c;
}
private void btnSmileyFace_Click(object sender, EventArgs e)
{
FaceOutline();
Eyes();
Nose();
mouth();
}
int x;
int y;
int diameter;
private void FaceOutline()
{
Point p = new Point(200, 200);
x = p.X;
y = p.Y;
//define width and height
diameter = 160;
//generate a random color
Color color = Color.AliceBlue;
//create a Pen
int lineThickness = 3;
Pen pen = new Pen(color, lineThickness);
g.DrawEllipse(pen, x, y, diameter, diameter);
pictureBox1.Image = bmap;
}
private void Nose()
{
Point N1 = new Point(280, 250);
Point N2 = new Point(270, 280);
Point N3 = new Point(290, 270);
Pen pen = new Pen(Color.BlanchedAlmond, 3);
g.DrawLine(pen, N1.X, N1.Y, N2.X, N2.Y);
g.DrawLine(pen, N2.X, N2.Y, N3.X, N3.Y);
pictureBox1.Image = bmap;
}
private void Eyes()
{
//Point E1 = new Point (x + (int) 0.5 * diameter, y + (int) 0.4 * diameter);
//Point E2 = new Point (x + (int) 0.8 * diameter, y + (int) 0.2 * diameter);
Point E1 = new Point(240, 240);
Point E2 = new Point(305, 240);
int diameter1 = 15;
Color color = Color.Black;
SolidBrush brush = new SolidBrush(color);
g.FillEllipse(brush, E1.X, E1.Y, diameter1, diameter1);
g.FillEllipse(brush, E2.X, E2.Y, diameter1, diameter1);
pictureBox1.Image = bmap;
}
private void mouth()
{
Point[] pArr = new Point[6];
pArr[0] = new Point(230, 300);
pArr[1] = new Point(270, 320);
pArr[2] = new Point(280, 330);
pArr[3] = new Point(290, 320);
pArr[4] = new Point(330, 300);
pArr[5] = new Point(280, 310);
Color color = Color.Red;
SolidBrush brush = new SolidBrush(color);
g.FillClosedCurve(brush, pArr, System.Drawing.Drawing2D.FillMode.Alternate);
pictureBox1.Image = bmap;
}
}
}
Labels:
C#
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment