Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void mousePressed()
- {
- mouseOldCordX = mouseX/cellSize;
- mouseOldCordY = mouseY/cellSize;
- }
- void mouseReleased()
- {
- mouseNewCordX = mouseX/cellSize;
- mouseNewCordY = mouseY/cellSize;
- lineDrawing();
- }
- void lineDrawing()
- {
- int deltaX = mouseNewCordX - mouseOldCordX, deltaY = mouseNewCordY - mouseOldCordY;
- int gradient = deltaY + deltaY, error = gradient - deltaX;
- if (abs(deltaY) < abs(deltaX))
- {
- if (mouseOldCordX > mouseNewCordX)
- {
- plotLineLow(mouseOldCordX, mouseOldCordY, deltaX, deltaY, gradient, error);
- } else
- {
- plotLineLow(mouseNewCordX, mouseNewCordY, deltaX, deltaY, gradient, error);
- }
- } else
- {
- if (mouseOldCordY > mouseNewCordY)
- {
- plotLineHigh(mouseOldCordX, mouseOldCordY, deltaX, deltaY, gradient, error);
- } else
- {
- plotLineHigh(mouseNewCordX, mouseNewCordY, deltaX, deltaY, gradient, error);
- }
- }
- }
- void plotLineLow(int x0, int y0, int deltaX, int deltaY, int gradient, int error)
- {
- int yIncrease = 1;
- if (deltaY < 0)
- {
- yIncrease = -1;
- deltaY = -deltaY;
- }
- for (int x = mouseOldCordX; x <= mouseNewCordX; x += 1)
- {
- world[x][y0].state = selectedState;
- error += gradient;
- if (error >= 0)
- {
- y0 += yIncrease;
- error -= (deltaX + deltaX);
- }
- }
- }
- void plotLineHigh(int x0, int y0, int deltaX, int deltaY, int gradient, int error)
- {
- int xIncrease = 1;
- if (deltaX < 0)
- {
- xIncrease = -1;
- deltaX = -deltaX;
- }
- for (int y = mouseOldCordY; y <= mouseNewCordY; y += 1)
- {
- world[x0][y].state = selectedState;
- error += gradient;
- if (error >= 0)
- {
- x0 += xIncrease;
- error -= (deltaY + deltaY);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement