int x, y, t, dx, dy, incx, incy, pdx, pdy, ddx, ddy, es, el, err; void gbham(ushort _tValue, ushort _tTime) /*-------------------------------------------------------------- * Bresenham-Algorithmus: Linien auf Rastergeräten zeichnen * * Eingabeparameter: * int xstart, ystart = Koordinaten des Startpunkts * int xend, yend = Koordinaten des Endpunkts * * Ausgabe: * void SetPixel(int x, int y) setze ein Pixel in der Grafik * (wird in dieser oder aehnlicher Form vorausgesetzt) *--------------------------------------------------------------- */ { /* Entfernung in beiden Dimensionen berechnen */ dx = _tTime ; dy = _tValue - H; /* Vorzeichen des Inkrements bestimmen */ incx = sgn(dx); incy = sgn(dy); if (dx < 0) dx = -dx; if (dy < 0) dy = -dy; /* feststellen, welche Entfernung größer ist */ if (dx > dy) { /* x ist schnelle Richtung */ pdx = incx; pdy = 0; /* pd. ist Parallelschritt */ ddx = incx; ddy = incy; /* dd. ist Diagonalschritt */ es = dy; el = dx; /* Fehlerschritte schnell, langsam */ } else { /* y ist schnelle Richtung */ pdx = 0; pdy = incy; /* pd. ist Parallelschritt */ ddx = incx; ddy = incy; /* dd. ist Diagonalschritt */ es = dx; el = dy; /* Fehlerschritte schnell, langsam */ } /* Initialisierungen vor Schleifenbeginn */ x = 0; y = H; err = el / 2; SetPixel(x, y); //Wert plotten, später: PWM-Helligkeit aktualisieren t = 0; timer1.Enabled = true; //Timer aktivieren /* Pixel berechnen */ } /* gbham() */ int sgn(int x) { return (x > 0) ? 1 : (x < 0) ? -1 : 0; } private void timer1_Tick(object sender, EventArgs e) //ISR { if (t < el) { /* Aktualisierung Fehlerterm */ err -= es; if (err < 0) { /* Fehlerterm wieder positiv (>=0) machen */ err += el; /* Schritt in langsame Richtung, Diagonalschritt */ x += ddx; y += ddy; } else { /* Schritt in schnelle Richtung, Parallelschritt */ x += pdx; y += pdy; } textBoxH.Text = y.ToString(); SetPixel(x, y); //Wert plotten, später: PWM-Helligkeit aktualisieren t++; } else { timer1.Enabled = false; MessageBox.Show("TIMER STOP"); } }