Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Besenham(int x1, int y1, int x2, int y2) {
- boolean zapamataj = false;
- boolean bolaVymena1 = false;
- boolean bolaVymena2 = false;
- if (Math.abs(x2 - x1) < Math.abs(y2 - y1)) {
- int pom;
- pom = x1; x1 = y1; y1 = pom;
- pom = x2; x2 = y2; y2 = pom;
- zapamataj = true;
- glColor3d(255, 0, 0);
- bolaVymena1 = true;
- }
- if (x2 < x1) {
- int pom;
- pom = x1; x1 = x2; x2 = pom;
- pom = y1; y1 = y2; y2 = pom;
- glColor3d(0, 0, 255);
- bolaVymena2 = true;
- }
- if (bolaVymena1 && bolaVymena2) {
- glColor3d(0, 255, 0);
- }
- if (!bolaVymena1 && !bolaVymena2) {
- glColor3d(255, 255, 255);
- }
- int krok = y2 < y1 ? -1 : 1;
- int dx = x2 - x1;
- int dy = Math.abs(y2 - y1);
- int y = y1;
- int k1 = 2 * dy;
- int k2 = 2 * dy - 2 * dx;
- int d = 2 * dy - dx;
- for (int x = x1; x <= x2; x++) {
- if (zapamataj) {
- Bod(y, x);
- } else {
- Bod(x, y);
- }
- if (d < 0) {
- d = d + k1;
- } else {
- d = d + k2;
- y = y + krok;
- }
- }
- }
Add Comment
Please, Sign In to add comment