RSS
 

Posts Tagged ‘bresenham algoritması’

C# grafik çizme algoritmaları (DDA-Bresenham)

09 Eki

Bütün programlama dillerinde genellikle kullanılan dda ve bresebham algoritmalarını kullanarak örnek uygulama yapcağız

Öncelikle DDA ve bresenham algoritmasının fonksiyonlarını oluşturalım;

sesese


DDA algoritması;

void DDACiz(int x1, int y1, int x2, int y2){

 int PikselSayisi;

 int dx, dy;
 float x, xFark;
 float y, yFark;

 dx = x2 - x1;
 dy = y2 - y1;

 PikselSayisi = Math.Abs(dx) > Math.Abs(dy) ? Math.Abs(dx) : Math.Abs(dy);

 xFark = (float)dx / (float)PikselSayisi;
 yFark = (float)dy / (float)PikselSayisi;

 x = (float)x1;
 y = (float)y1;

 while(PikselSayisi--){
 PikselBas((int)floor(x + 0.5F), (int) Math.Floor(y + 0.5f));
 x += xFark;
 y += yFark;
 }
}
Bresenham algoritması;
void dogruBresenham(int x1, int y1, int x2, int y2)
{ int hata = x1 - x2; int dx2 = (x2 - x1) * 2; int dy2 = (y2 - y1) * 2; int x, y = y1; System.Drawing.SolidBrush m_tualbrush = new System.Drawing.SolidBrush(m_brushcolor); System.Drawing.Graphics tualgraphics = panel1.CreateGraphics(); for (x = x1; x < x2; x++) { //pikselBas(x, y); foreach (Point p in m_nokta) { tualgraphics.FillEllipse(m_tualbrush, x, y,trackBar1.Value,trackBar1.Value); } hata += dy2; if (hata > 0) { y++; hata -= dx2; } } } void dogruBresenham(int x1, int y1, int x2, int y2) { int hata = x1 - x2; int dx2 = (x2 - x1) * 2; int dy2 = (y2 - y1) * 2; int x, y = y1; System.Drawing.SolidBrush m_tualbrush = new System.Drawing.SolidBrush(m_brushcolor); System.Drawing.Graphics tualgraphics = panel1.CreateGraphics(); for (x = x1; x < x2; x++) { //pikselBas(x, y); foreach (Point p in m_nokta) { PixelBas(m_tualbrush, x, y,trackBar1.Value,trackBar1.Value); } hata += dy2; if (hata > 0) { y++; hata -= dx2; } } }

Download !

 
10 Comments

Posted in C#