Bitmap/Bresenham's line algorithm: Difference between revisions

Add J
m (→‎{{header|Ruby}}: update example)
(Add J)
Line 538:
deltay = abs $ y2 - y1
ystep = if y1 < y2 then 1 else -1</lang>
 
=={{header|J}}==
'''Solution'''
Using from definitions from [[Basic bitmap storage#J|Basic bitmap storage]]:
<lang j>
thru=: <./ + -~ i.@+ _1 ^ >
 
NB.*getBresenhamLine v Returns points for a line given start and end points
NB. y is: x0 y0 ,: x1 y1
getBresenhamLine=: monad define
steep=. ([: </ |@-~/) y
'startpt endpt'=. |."1^:steep y
slope=. %~/ -/ endpt ,: startpt
xpts=. thru/ {."1 startpt ,: endpt
ypts=. ({: + 0.5 <.@:+ slope * xpts - {.) startpt
|."1^:steep xpts,.ypts
)
 
NB.*drawLines v Draws lines (x) on image (y)
drawLines=: (1&{:: ;~ [: ; [: <@getBresenhamLine"2 (0&{::))@[ setPixels ]
</lang>
 
=={{header|Maple}}==
892

edits