Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

bresenham algorithm

function line(x0, y0, x1, y1) {
   var dx = Math.abs(x1 - x0);
   var dy = Math.abs(y1 - y0);
   var sx = (x0 < x1) ? 1 : -1;
   var sy = (y0 < y1) ? 1 : -1;
   var err = dx - dy;

   while(true) {
      setPixel(x0, y0); // Do what you need to for this

      if ((x0 === x1) && (y0 === y1)) break;
      var e2 = 2*err;
      if (e2 > -dy) { err -= dy; x0  += sx; }
      if (e2 < dx) { err += dx; y0  += sy; }
   }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript on focus 
Javascript :: is odd javascript 
Javascript :: react native pure component vs component 
Javascript :: return object from map javascript 
Javascript :: check file name in url 
Javascript :: javascript find unique values in array of objects 
Javascript :: checked unchecked through js 
Javascript :: call a function 
Javascript :: how to seperate header body and footer in node 
Javascript :: js get children last 
Javascript :: ready function jq 
Javascript :: round down html 
Javascript :: vue 3 
Javascript :: find second smallest number in array 
Javascript :: react link onclick refresh page 
Javascript :: how to click on alret dialog with pupeteer 
Javascript :: jquery append text for 5 seconds 
Javascript :: let a = {y;10}; 
Javascript :: interpolation in js 
Javascript :: electron iframe require is not defined 
Javascript :: what is symbol in javascript 
Javascript :: how to add background to kaboom js 
Javascript :: mongoose search multiple fields 
Javascript :: How to use `setState` callback on react hooks 
Javascript :: HH:mm with am pm jquery 
Javascript :: ease between 2 points 
Javascript :: json with postgresql 
Javascript :: stop jboss from cli 
Javascript :: node js download image from url as buffer 
Javascript :: private methods js 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =