March 04, 2021, 12:32:05 AM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Home
Forum
Help
Search
Gallery
Login
Register
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Graphics
»
[bb] Fast Line by Rob Farley [ 1+ years ago ]
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: [bb] Fast Line by Rob Farley [ 1+ years ago ] (Read 1374 times)
BlitzBot
Jr. Member
Posts: 1
[bb] Fast Line by Rob Farley [ 1+ years ago ]
«
on:
June 29, 2017, 12:28:43 AM »
Title :
Fast Line
Author :
Rob Farley
Posted :
1+ years ago
Description :
I know this doesnt sound that exciting, however, if you want to draw only vertical and horizonal lines it's a darn sight faster than the standard line function.
I could have locked and unlocked the backbuffer() in the function however, it's much faster to lockbuffer, draw a bunch of lines, then unlockbuffer.
Usage:
fline(x1,y1,x2,y2,r,g,b)
Simple as that... If you try to draw a line that isn't horizontal or vertical it won't do anything.
Example code at the top, all you actually need is the function.
Code :
Code: BlitzBasic
; Fast line, 2004 Rob Farley
; rob@mentalillusion.co.uk
;==========================================================
; example code
;==========================================================
Graphics
640
,
480
SetBuffer
BackBuffer
(
)
LockBuffer
BackBuffer
(
)
For
x=
0
To
200
Step
20
For
y=
0
To
200
Step
20
fline
(
0
,y,
200
,y,
255
,
128
,
0
)
fline
(
x,
0
,x,
200
,
255
,
0
,
0
)
Next
Next
UnlockBuffer
BackBuffer
(
)
Flip
WaitKey
;==========================================================
; end of example code
;==========================================================
Function
fLine
(
x,y,x1,y1,r=
255
,g=
255
,b=
255
)
; fLine will only draw horizonal or vertical lines, no diagonals
; Defaults to a white line.
argb=
(
b
Or
(
g
Shl
8
)
Or
(
r
Shl
16
)
Or
(
$ff000000
)
)
If
x=x1
If
y>y1
Then
t=y1:y1=y:y=t
For
n=y
To
y1
WritePixelFast
x,n,argb,
BackBuffer
(
)
Next
EndIf
If
y=y1
If
x>x1
Then
t=x1:x1=x:x=t
For
n=x
To
x1
WritePixelFast
n,y,argb,
BackBuffer
(
)
Next
EndIf
End Function
Comments :
big10p(Posted 1+ years ago)
Is this even faster than Rect for drawing horz/vert lines, then?
Rob Farley(Posted 1+ years ago)
Yes.
Logged
Print
Pages: [
1
]
Go Up
« previous
next »
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Graphics
»
[bb] Fast Line by Rob Farley [ 1+ years ago ]
SimplePortal 2.3.6 © 2008-2014, SimplePortal