How to resolve the algorithm Bitmap/Bresenham's line algorithm step by step in the CoffeeScript programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Bitmap/Bresenham's line algorithm step by step in the CoffeeScript programming language
Table of Contents
Problem Statement
Using the data storage type defined on the Bitmap page for raster graphics images, draw a line given two points with Bresenham's line algorithm.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Bitmap/Bresenham's line algorithm step by step in the CoffeeScript programming language
Source code in the coffeescript programming language
drawBresenhamLine = (x0, y0, x1, y1) ->
dx = Math.abs(x1 - x0)
sx = if x0 < x1 then 1 else -1
dy = Math.abs(y1 - y0)
sy = if y0 < y1 then 1 else -1
err = (if dx>dy then dx else -dy) / 2
loop
setPixel(x0, y0)
break if x0 == x1 && y0 == y1
e2 = err
if e2 > -dx
err -= dy
x0 += sx
if e2 < dy
err += dx
y0 += sy
null
You may also check:How to resolve the algorithm Sequence of primes by trial division step by step in the Crystal programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the Phix programming language
You may also check:How to resolve the algorithm Shell one-liner step by step in the Huginn programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the Wren programming language
You may also check:How to resolve the algorithm Literals/Integer step by step in the Sidef programming language