Páginas

domingo, 27 de noviembre de 2011

PROYECTO FINAL DE LA UNIDAD I




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.IO;
using System.Drawing.Drawing2D;

namespace Proyecto_Creador
{
public partial class Form1 : Form
{
const int LENGHT = 70;
int width, height,N1,N2,tam;
Graphics g;

public Form1()
{
InitializeComponent();
g = pictureBox1.CreateGraphics();
}
SolidBrush verde = new SolidBrush(Color.Green);


double[] frctl = new double[1000];
int maxlevel = 6;
private void fractal(int y1, int y2, int maxlevel, double h, double scale)
{
int first, last;
double radio, std;

first = 0;

last = Convert.ToInt32(Math.Pow(maxlevel, 2.0));
frctl[first] = y1;
frctl[last] = y2;
radio = 1.0 / Math.Pow(h, 2.0);
std = scale * radio;
subdivide(first, last, std, radio);
}
private void subdivide(int p1, int p2, double std, double radio)
{
int midpnt;
double stdmid;
midpnt = (p1 + p2) / 2;
Random r = new Random();
if (midpnt != p1 && midpnt != 2)
{
frctl[midpnt] = (frctl[p1] + frctl[p2] / 2) + Convert.ToDouble(r.Next(16) - 8) / 8.0 * std;
stdmid = std * radio;
subdivide(p1, midpnt, stdmid, radio);
subdivide(midpnt, p2, stdmid, radio);
}
}
private void draw_fractal(Color color)
{
int i, x, xinc, l;
double maxlevel = 6;
l = Convert.ToInt32(Math.Pow((double)maxlevel, 2.0));
xinc = ClientSize.Width / l * 3 / 2;
Graphics g = panel8.CreateGraphics();
Pen pl = new Pen(color);
for (i = 0, x = 0; i < l; i++, x += xinc)
g.DrawLine(pl, 0, 100, x, (int)frctl[i]);

}


private void Form1_Load(object sender, EventArgs e)
{
/*groupBox4.Enabled = false;
groupBox3.Enabled = false;
groupBox2.Enabled = false;*/

}



private void button2_Click(object sender, EventArgs e)
{

//((Bitmap)pictureBox1.Image).Save("C:\\Documents and Settings\\Administrador\\Escritorio\\Proyecto_Creador\\imagen.bmp");
Bitmap ftr = new Bitmap(pictureBox1.Width, pictureBox1.Height,g);
ftr.Save("C:\\Documents and Settings\\Administrador\\Escritorio\\Proyecto_Creador\\imagen.bmp");

/*Bitmap bit = new Bitmap(pictureBox1.Width, pictureBox1.Height);
string nombre = textBox1.Text;

pictureBox1.Image.Save("hola.bmp");//, System.Drawing.Imaging.ImageFormat.Jpeg);*/
}

private void pictureBox1_Click(object sender, EventArgs e)
{


}

private void button1_Click(object sender, EventArgs e)
{

Graficos OG = new Graficos(pictureBox1);

if (radioButton1.Checked)
{

OG.Linea_DDA(201, 81, 232, 105);
OG.Linea_DDA(203, 81, 236, 99);
OG.Linea_DDA(199, 82, 205, 103);
OG.Linea_DDA(201, 81, 180, 102);
OG.Linea_DDA(200, 81, 159, 101);
pictureBox1.Refresh();
SolidBrush piel = new SolidBrush(Color.BlanchedAlmond);
SolidBrush ojos = new SolidBrush(Color.Brown);
SolidBrush playera = new SolidBrush(Color.Red);
SolidBrush pantalon = new SolidBrush(Color.Blue);
Pen boca = new Pen(Color.Red);
Point[] Boca = {new Point(180, 150),
new Point(200,160),
new Point(220, 150)};
Point[] Playera ={new Point(162,201),
new Point(165,194),
new Point(173,190),
new Point(223,190),
new Point(223,193),
new Point(236,201),
new Point(236,299),
new Point(163,301),
new Point(163,202)};
Point[] BrazoD ={new Point(165,192),
new Point(101,271),
new Point(101,278),
new Point(118,283),
new Point(163,215),
new Point(165,192)
};

Point[] BrazoI ={new Point(231,192),
new Point(294,271),
new Point(299,278),
new Point(282,283),
new Point(236,215),
new Point(231,192)
};
g.FillEllipse(piel, 150, 80, 100, 100);
g.FillEllipse(ojos, 175, 115, 15, 15);
g.FillEllipse(ojos, 210, 115, 15, 15);
g.DrawCurve(boca, Boca);
g.FillRectangle(piel, 189, 180, 23, 10);
//g.FillRectangle(playera, 162, 190, 75, 60);
g.FillClosedCurve(playera, Playera);
g.FillRectangle(pantalon, 160, 290, 80, 100);
g.FillClosedCurve(piel, BrazoD);
g.FillClosedCurve(piel, BrazoI);
// pictureBox1.Image = (new Image())g());

}
else if (radioButton2.Checked)
{
pictureBox1.Refresh();


SolidBrush piel = new SolidBrush(Color.BlanchedAlmond);
SolidBrush ojos = new SolidBrush(Color.Brown);
SolidBrush playera = new SolidBrush(Color.Violet);
SolidBrush pantalon = new SolidBrush(Color.Plum);
Pen boca = new Pen(Color.Red);
Point[] Boca = {new Point(180, 150),
new Point(200,160),
new Point(220, 150)};
Point[] Playera ={new Point(162,201),
new Point(165,194),
new Point(173,190),
new Point(223,190),
new Point(223,193),
new Point(236,201),
new Point(236,299),
new Point(163,301),
new Point(163,202)};
Point[] BrazoD ={new Point(165,192),
new Point(101,271),
new Point(101,278),
new Point(118,283),
new Point(163,215),
new Point(165,192)
};

Point[] BrazoI ={new Point(231,192),
new Point(294,271),
new Point(299,278),
new Point(282,283),
new Point(236,215),
new Point(231,192)
};



g.FillEllipse(piel, 150, 80, 100, 100);
g.FillEllipse(ojos, 175, 115, 15, 15);
g.FillEllipse(ojos, 210, 115, 15, 15);
g.DrawCurve(boca, Boca);
g.FillRectangle(piel, 189, 180, 23, 10);
//g.FillRectangle(playera, 162, 190, 75, 60);
g.FillClosedCurve(playera, Playera);
g.FillRectangle(pantalon, 160, 290, 80, 100);
g.FillClosedCurve(piel, BrazoD);
g.FillClosedCurve(piel, BrazoI);
// pictureBox1.Image = (new Image())g());

/* OG.Linea_DDA(197, 97, 160, 107);
OG.Linea_DDA(198, 85, 174, 107);
OG.Linea_DDA(202, 82, 197, 105);
OG.Linea_DDA(202, 81, 232, 108);
OG.Linea_DDA(193, 81, 123, 200);
OG.Linea_DDA(161, 161, 156, 198);
OG.Linea_DDA(203, 81, 278, 190);
OG.Linea_DDA(232, 172, 245, 205);*/


}
else
MessageBox.Show("Elija el sexo de su personaje");

}

private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{

}

private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{

}

private void button3_Click(object sender, EventArgs e)
{


}

private void panel1_Paint(object sender, PaintEventArgs e)
{

}

private void panel1_Click(object sender, EventArgs e)
{

Graphics g = pictureBox1.CreateGraphics();
SolidBrush azul = new SolidBrush(Color.Blue);
g.FillEllipse(azul, 175, 115, 15, 15);
g.FillEllipse(azul, 210, 115, 15, 15);
}

private void panel2_Click(object sender, EventArgs e)
{
Graphics g = pictureBox1.CreateGraphics();
SolidBrush verde = new SolidBrush(Color.Green);
g.FillEllipse(verde, 175, 115, 15, 15);
g.FillEllipse(verde, 210, 115, 15, 15);
}

private void panel3_Click(object sender, EventArgs e)
{
Graphics g = pictureBox1.CreateGraphics();
SolidBrush rojo = new SolidBrush(Color.Red);
g.FillEllipse(rojo, 175, 115, 15, 15);
g.FillEllipse(rojo, 210, 115, 15, 15);
}

private void panel4_Click(object sender, EventArgs e)
{
Graphics g = pictureBox1.CreateGraphics();
SolidBrush cafe = new SolidBrush(Color.Brown);
g.FillEllipse(cafe, 175, 115, 15, 15);
g.FillEllipse(cafe, 210, 115, 15, 15);
}

private void panel5_Paint(object sender, PaintEventArgs e)
{


}

private void panel5_Click(object sender, EventArgs e)
{
Graphics g1 = pictureBox1.CreateGraphics();

SolidBrush piel1 = new SolidBrush(Color.MistyRose);


Point[] BrazoD ={new Point(165,192),
new Point(101,271),
new Point(101,278),
new Point(118,283),
new Point(163,215),
new Point(165,192)
};

Point[] BrazoI ={new Point(231,192),
new Point(294,271),
new Point(299,278),
new Point(282,283),
new Point(236,215),
new Point(231,192)
};

//cabeza
g1.FillEllipse(piel1, 150, 80, 100, 100);
//brazos
g1.FillClosedCurve(piel1, BrazoD);
g1.FillClosedCurve(piel1, BrazoI);

g1.FillRectangle(piel1, 189, 180, 23, 10);


SolidBrush ojos = new SolidBrush(Color.Brown);

Pen boca = new Pen(Color.Red);
Point[] Boca = {new Point(180, 150),
new Point(200,160),
new Point(220, 150)};

g1.FillEllipse(ojos, 175, 115, 15, 15);
g1.FillEllipse(ojos, 210, 115, 15, 15);
g1.DrawCurve(boca, Boca);





}

private void panel6_Click(object sender, EventArgs e)
{
Graphics g = pictureBox1.CreateGraphics();
SolidBrush piel2 = new SolidBrush(Color.RosyBrown);
Point[] BrazoD ={new Point(165,192),
new Point(101,271),
new Point(101,278),
new Point(118,283),
new Point(163,215),
new Point(165,192)
};

Point[] BrazoI ={new Point(231,192),
new Point(294,271),
new Point(299,278),
new Point(282,283),
new Point(236,215),
new Point(231,192)
};

//cabeza
g.FillEllipse(piel2, 150, 80, 100, 100);
//brazos
g.FillClosedCurve(piel2, BrazoD);
g.FillClosedCurve(piel2, BrazoI);
g.FillRectangle(piel2, 189, 180, 23, 10);



SolidBrush ojos = new SolidBrush(Color.Brown);

Pen boca = new Pen(Color.Red);
Point[] Boca = {new Point(180, 150),
new Point(200,160),
new Point(220, 150)};

g.FillEllipse(ojos, 175, 115, 15, 15);
g.FillEllipse(ojos, 210, 115, 15, 15);
g.DrawCurve(boca, Boca);


}

private void panel7_Click(object sender, EventArgs e)
{
Graphics g = pictureBox1.CreateGraphics();

SolidBrush piel3 = new SolidBrush(Color.BlanchedAlmond);

Point[] BrazoD ={new Point(165,192),
new Point(101,271),
new Point(101,278),
new Point(118,283),
new Point(163,215),
new Point(165,192)
};

Point[] BrazoI ={new Point(231,192),
new Point(294,271),
new Point(299,278),
new Point(282,283),
new Point(236,215),
new Point(231,192)
};

//cabeza
g.FillEllipse(piel3, 150, 80, 100, 100);
//brazos
g.FillClosedCurve(piel3, BrazoD);
g.FillClosedCurve(piel3, BrazoI);
g.FillRectangle(piel3, 189, 180, 23, 10);



SolidBrush ojos = new SolidBrush(Color.Brown);

Pen boca = new Pen(Color.Red);
Point[] Boca = {new Point(180, 150),
new Point(200,160),
new Point(220, 150)};

g.FillEllipse(ojos, 175, 115, 15, 15);
g.FillEllipse(ojos, 210, 115, 15, 15);
g.DrawCurve(boca, Boca);


}

private void button4_Click(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex==0)
{

int CENTRO_X = 10;//pictureBox1.Width / 2;
int CENTRO_Y = 50;
Graphics g = panel8.CreateGraphics();
float posx, posy;
int angle;
Random val = new Random();
Pen pluma;

for (angle = 0; angle < 360; angle++)
{
posx = (float)(CENTRO_X + LENGHT * Math.Sin(angle / 180.0 * Math.PI));
posy = (float)(CENTRO_Y + LENGHT * Math.Cos(angle / 180.0 * Math.PI));
pluma = new Pen(Color.FromArgb(val.Next(256), val.Next(256), val.Next(256)));
g.DrawLine(pluma, CENTRO_X, CENTRO_Y, posx + 100, posy + 200);
//g.DrawLine(Pens.Brown,CENTRO_X,CENTRO_Y,posx+100,posy+200);


}
}
if (comboBox1.SelectedIndex == 1)
{
Rectangle rect = new Rectangle(0, 0, this.ClientSize.Width, this.ClientSize.Height);
SolidBrush brush = new SolidBrush(Color.SkyBlue);
fractal(100, 100, maxlevel, 0.5, 50.0);
draw_fractal(Color.Blue);
//Bitmap bm = new Bitmap(ClientSize.Width,ClientSize.Height);
Graphics G = panel8.CreateGraphics();
G.FillRectangle(brush, 1, 1, ClientSize.Width, ClientSize.Height);
//G.FillRegion(Brush,brush,);
//PaintBox1->Canvas->FloodFill(1,1,clBlack,fsBorder);
SolidBrush brus = new SolidBrush(Color.SkyBlue);
fractal(170, 170, maxlevel, 0.9, 30.0);
//draw_fractal(Color.BlueViolet);
SolidBrush br = new SolidBrush(Color.Blue);
fractal(170, 170, maxlevel, 0.0, 30.0);
G.FillRectangle(br, 1, 240, ClientSize.Width, ClientSize.Height);
SolidBrush br1 = new SolidBrush(Color.Yellow);
G.FillEllipse(br1, 50, 15, ClientSize.Width - 700, ClientSize.Height - 550);
//SolidBrush br2 = new SolidBrush(Color.Green);
//G.FillRectangle(br2, 300, 150, ClientSize.Width, ClientSize.Height);



}
}

private void panel8_Paint(object sender, PaintEventArgs e)
{

}

private void button5_Click(object sender, EventArgs e)
{
OpenFileDialog abrir = new OpenFileDialog();
abrir.Filter = "Archivos JPEG(*.jpg) | *.jpg";
abrir.InitialDirectory = "C:/Documents and Settings";

if (abrir.ShowDialog() == DialogResult.OK)
{
}
string Dir = abrir.FileName;
Bitmap picture = new Bitmap(Dir);

panel8.BackgroundImage = (Image)picture;

}

private void textBox6_TextChanged(object sender, EventArgs e)
{

}

private void textBox6_Enter(object sender, EventArgs e)
{





}

private void timer1_Tick(object sender, EventArgs e)
{
pictureBox2.Refresh();
N1 = Convert.ToInt32(numericUpDown2.Value);
N2 = Convert.ToInt32(numericUpDown1.Value);
tam = Convert.ToInt32(trackBar1.Value);
Graphics g = pictureBox2.CreateGraphics();
string cad = textBox6.Text;
g.DrawString(cad, new Font("Times", tam), Brushes.Black, N1, N2);

/*if (rojo)

g.DrawString(cad, new Font("Times", tam), Brushes.Red, N1, N2);

if (azul)
g.DrawString(cad, new Font("Times", tam), Brushes.Blue, N1, N2);
if (verde)
g.DrawString(cad, new Font("Times", tam), Brushes.Green, N1, N2);*/
}

private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
timer1.Enabled = true;
groupBox7.Visible = true;
}

private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
{

}
}
}

No hay comentarios:

Publicar un comentario