January 15, 2021, 06:16:40 PM

### Author Topic: [bb] Snarty Line (ProPixel Code) by Snarty [ 1+ years ago ]  (Read 545 times)

#### BlitzBot

• Jr. Member
• Posts: 1
##### [bb] Snarty Line (ProPixel Code) by Snarty [ 1+ years ago ]
« on: June 29, 2017, 12:28:38 AM »
Title : Snarty Line (ProPixel Code)
Author : Snarty
Posted : 1+ years ago

Description : I took a look at the Bresham line algo and found it better to write a native Blitz algo for line Drawing. Includes a mode switch for XOR pixel drawing. Is aimed at drawing lines with Brushes/Sprites/Images etc, but is super fast with Pixels.

NOTE: Change the Draw image part to WritePixelFast to gain maximum speed on line creation.

Code :
Code: BlitzBasic
1. ; Snarty Line
2. ; Written By Paul Snart (Snarty)
3. ; Oct 2001
4.
5. ; Stx,Sty = Start pixel posistion
6. ; Enx,Eny = End point.
7. ; Mode    = False = Normal, True = XOR'ed
8. ; CurBrush= Image Memory Handle
9.
10. Function SLine(stx#,sty#,enx#,eny#,mode)
11.
12.         mvx#=Stx-enx:mvy#=sty-eny
13.         If mvx<0 mvx=-mvx
14.         If mvy<0 mvy=-mvy
15.         If mvy>mvx mv#=mvy Else mv#=mvx
16.         stpx#=(mvx/mv):If Stx>enx stpx=-stpx
17.         stpy#=(mvy/mv):If Sty>eny stpy=-stpy
18.         If Mode=1 LockBuffer BackBuffer()
19.         For nc=0 To Floor(mv)
20.                 If mode=0
21.                         If BrushMode<>1 Or Brush=0
22.                                 DrawImage CurBrush,stx,sty
23.                         Else
24.                                 If BrushMode=1
25.                                         DrawBlock CurBrush,stx,sty
26.                                 EndIf
27.                         EndIf
28.                 Else
30.                         ColD=\$FFFFFF Xor rgb
31.                         WritePixelFast stx,sty,ColD
32.                 EndIf
33.                 stx=stx+stpx:sty=sty+stpy
34.         Next
35.         If Mode=1 UnlockBuffer BackBuffer()
36.
37. End Function