0

Help me with Bresenham's line algorithm

https://code.sololearn.com/WXEUnTz1GmmY/?ref=app I'm making a game and I bumped into a strange problem. So, I've found a JS code for drawing a line via Bresenham's algorithm, without plot() function (maybe I write it wrong) and all this stuff works weird: 1) Start x,y and end x,y for line drawing is reversed for some reason 2) Line not drawing in some cases, like in the code below, where I called the function castRay(8,0,4,4) 3) Line not drawing except only one dot in God know where position What am I doing wrong?

15th Jul 2020, 9:21 AM
Š’Š°Š“ŠøŠ¼ Š›ŃƒŠŗŠ°ŃˆŠµŠ½ŠŗŠ¾
Š’Š°Š“ŠøŠ¼ Š›ŃƒŠŗŠ°ŃˆŠµŠ½ŠŗŠ¾ - avatar
2 Answers
+ 1
try to put console.log(`${x}x${y}`) into plot() function and u will see that it isn't drawing correct line from 4x4 tile into 0x0 tile
15th Jul 2020, 11:08 AM
Š’Š°Š“ŠøŠ¼ Š›ŃƒŠŗŠ°ŃˆŠµŠ½ŠŗŠ¾
Š’Š°Š“ŠøŠ¼ Š›ŃƒŠŗŠ°ŃˆŠµŠ½ŠŗŠ¾ - avatar
0
you are very smart, dude. Now it can draw a correct line
15th Jul 2020, 11:32 AM
Š’Š°Š“ŠøŠ¼ Š›ŃƒŠŗŠ°ŃˆŠµŠ½ŠŗŠ¾
Š’Š°Š“ŠøŠ¼ Š›ŃƒŠŗŠ°ŃˆŠµŠ½ŠŗŠ¾ - avatar