;*** Dreieck-Füllroutine
;*** 4/5.10.2004
;*** www.silizium-net.de
Graphics 800,600,32,2
SetBuffer BackBuffer()
SeedRnd MilliSecs()
x1=Rand(0,800)
y1=Rand(0,600)
x3=Rand(0,800)
y3=Rand(0,600)
HidePointer
time1 = MilliSecs()
While Not KeyDown(1)
filltri(x1,y1,MouseX(),MouseY(),x3,y3,0,0,255,255,255,255)
loops = loops+1
If MilliSecs() - time1 > 1000 Then
fps = loops:loops = 0
time1 = MilliSecs()
End If
If KeyHit(28) Then
x1=Rand(0,800)
y1=Rand(0,600)
x3=Rand(0,800)
y3=Rand(0,600)
End If
Color 255,255,255
Text 10,10, "Enter für neue Zufallspositionen"
Text 10,30, fps+" FPS"
Flip 0
Cls
Wend
End
;---
Function filltri(x1,y1,x2,y2,x3,y3,r,g,b,borderr,borderg,borderb)
For oft = 0 To 1
If x1 > x2 Then
p=x2
x2=x1
x1=p
q=y2
y2=y1
y1=q
End If
If x1 > x3 Then
p=x3
x3=x1
x1=p
q=y3
y3=y1
y1=q
End If
If x2 > x3 Then
p=x3
x3=x2
x2=p
q=y3
y3=y2
y2=q
End If
Next
Color r,g,b
For bx1# = x1 To x2
m13# = (Float(y3-y1)/(x3-x1))
n13# = -m13*x1+y1
by1# = m13*bx1+n13
m12# = (Float(y2-y1)/(x2-x1))
n12# = -m12*x1+y1
by2# = m12*bx1+n12
If by2-by1 > 0 Then Rect bx1,by1,1,by2-by1
If by2-by1 < 0 Then Rect bx1,by2,1,by1-by2
Next
For bx2 = x2 To x3
m13# = (Float(y3-y1)/(x3-x1))
n13# = -m13*x3+y3
by3# = m13*bx2+n13
m23# = (Float(y3-y2)/(x3-x2))
n23# = -m23*x2+y2
by4# = m23*bx2+n23
If by4-by3 > 0 Then Rect bx2,by3,1,by4-by3
If by4-by3 < 0 Then Rect bx2,by4,1,by3-by4
Next
Color borderr,borderg,borderb
Line x1,y1,x2,y2
Line x1,y1,x3,y3
Line x2,y2,x3,y3
Text x1,y1, "1"
Text x2,y2, "2"
Text x3,y3, "3"
End Function
|