Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Created January 8, 2021 17:05
Show Gist options
  • Select an option

  • Save unitycoder/90f0f1896e38a13d98e3d0c84ea45789 to your computer and use it in GitHub Desktop.

Select an option

Save unitycoder/90f0f1896e38a13d98e3d0c84ea45789 to your computer and use it in GitHub Desktop.

Revisions

  1. unitycoder created this gist Jan 8, 2021.
    28 changes: 28 additions & 0 deletions Bresenham.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    // old unityscript
    function drawLine(x0:int, y0:int, x1:int, y1:int)
    {
    dx= Mathf.Abs(x1-x0);
    dy= Mathf.Abs(y1-y0);
    if (x0 < x1) {sx=1;}else{sx=-1;}
    if (y0 < y1) {sy=1;}else{sy=-1;}
    err=dx-dy;

    loop=true;
    while (loop)
    {
    texture.SetPixel (x0,y0,Color(1,1,1,1));
    if ((x0 == x1) && (y0 == y1)) loop=false;
    e2 = 2*err;
    if (e2 > -dy)
    {
    err = err - dy;
    x0 = x0 + sx;
    }
    if (e2 < dx)
    {
    err = err + dx;
    y0 = y0 + sy;
    }
    }
    texture.Apply();
    }