5. Изчертаване на триъгълник чрез линии
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace r
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent(); Draw();
}
public void Draw()
{
Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
Graphics graph = Graphics.FromImage(bmp);
Pen pen=new Pen(Color.Red,2);
int x = 10, y = 10;
graph.DrawRectangle(pen, x, y, 200, 100);
pictureBox1.Image = bmp;
}
}
}
1 задача: Изчертаване на триъгълник с координати на долния ляв ъгъл x1 = 200, y1 =300 и страна a = 200.
int a = 200, x1 = 200, y1 =300 , x2, y2, x3, y3;
x2 = x1 + a;
y2 = y1;
x3 = (x1 + x2) / 2;
int h = (int)(a * Math.Sqrt(3) / 2);
y3 = y1 - h;
Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
Graphics graph = Graphics.FromImage(bmp);
Pen pen = new Pen(Color.Red,2);
graph.DrawLine(pen, x1, y1, x2, y2);
graph.DrawLine(pen, x2, y2, x3, y3);
graph.DrawLine(pen, x3, y3, x1, y1);
pictureBox1.Image = bmp;
x2 = x1 + a;
y2 = y1;
x3 = (x1 + x2) / 2;
int h = (int)(a * Math.Sqrt(3) / 2);
y3 = y1 - h;
Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
Graphics graph = Graphics.FromImage(bmp);
Pen pen = new Pen(Color.Red,2);
graph.DrawLine(pen, x1, y1, x2, y2);
graph.DrawLine(pen, x2, y2, x3, y3);
graph.DrawLine(pen, x3, y3, x1, y1);
pictureBox1.Image = bmp;
