[bb] Any Zoom Level Line by skn3 [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:43

Previous topic - Next topic

BlitzBot

Title : Any Zoom Level Line
Author : skn3
Posted : 1+ years ago

Description : A function to draw a line at a variable Zoom. What this means is . Say you are making an art app. And you were at 4X zoomed in, with this you can quickly draw a line at 4X zoom.

[update]
I just fixed some flaot --> int  and int --> float rounding up/down errors. Not that its majorly complicated, but a line in any zoom, will be 99% accurate now.


Code :
Code (blitzbasic) Select
Graphics 640,480,32,2
Global angle#=0

While KeyDown(1)=False
SetBuffer BackBuffer()
Cls
Color 255,255,255
drawline(200,200,MouseX(),MouseY(),33)
Flip
Wend

Function DrawLine(StartX,StartY,EndX,EndY,Scale)
StartX=StartX/Scale*Scale
StartY=StartY/Scale*Scale
EndX=EndX/Scale*Scale
EndY=EndY/Scale*Scale
If StartX<EndX Then
Xmode=True
Else
Xmode=False
End If
If StartY<EndY Then
Ymode=True
Else
Ymode=False
End If
width#=Abs(startX-EndX)
height#=Abs(StartY-EndY)

If width#>height# Then
loops=width#
If XMode=False Then
xstep#=-1
Else
xstep#=1
End If
If Ymode=False Then
ystep#=-(height#/width#)
Else
ystep#=(height#/width#)
End If
Else
loops=height#
If XMode=False Then
xstep#=-(width#/height#)
Else
xstep#=(width#/height#)
End If
If Ymode=False Then
ystep#=-1
Else
ystep#=1
End If
End If

drawX#=startX
drawY#=startY

loops=Ceil(loops/scale)+1

For i=1 To loops
getX#=drawX#/scale
getY#=drawY#/scale
intX=Int(getX#)*scale
intY=Int(GetY#)*scale

Rect IntX,IntY,scale,scale
drawX#=drawX#+(xstep#*scale)
drawY#=drawY#+(ystep#*scale)
Next
End Function


Comments : none...