Advertisement
Guest User

Untitled

a guest
May 26th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. let drawLine = (x0, y0, x1, y1, color) => {
  2. // Calculate "deltas" of the line (difference between two ending points)
  3. let dx = x1 - x0;
  4. let dy = y1 - y0;
  5. console.log("dy = "+dy);
  6. // Calculate the line equation based on deltas
  7. let D = (2 * dy) - dx;
  8. let y = y0;
  9. // Draw the line based on arguments provided
  10. for (let x = x0; x < x1; x++)
  11. {
  12. // Place pixel on the raster display
  13. putPixel(x,y,color);
  14. if (D >= 0)
  15. {
  16. y = y + 1;
  17. D = D - 2 * dx;
  18. }
  19. D = D + 2 * dy;
  20. }
  21. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement