• Welcome to Dark Bit Factory & Gravity.
 

Wierd Triangle Fill[BB2D]

Started by Shockwave, May 11, 2006

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

Shockwave

Original Topic By Nawitus from the old board.

Quote
Well, this is not unlike normal triangle fill, but seeing I havent this anywhere else I thought it would be good idea to post it here. It basicly works like this, it draws a Line from point 2 to point 3, and on every pixel from that line, it draws line from point 1 to those pixels. It has some bugs (even with default Line drawing function, fixing those it could be ok speed I think? (if optimised properly). Im gonna start on 'normal' style triangle fill next (I never read tutos, just experiment as you see :P).

Heres the codeZ


Const ScreenWidth = 320
Const ScreenHeight = 240

Graphics ScreenWidth,ScreenHeight,0,2
SetBuffer BackBuffer()

Repeat



LockBuffer
Triangle MouseX(),MouseY(),50+50*Sin(phase),50+50*Cos(phase),190,90,(Rand(255) Shl 16) + (Rand(255) Shl 8) + Rand(255)
UnlockBuffer

phase = phase + 1

Flip
Cls

Until KeyHit(1)

Function Triangle(X1,Y1,X2,Y2,X3,Y3,col)


XEro = X2-X3
YEro = Y2-Y3

Angle# = ATan2(XEro,YEro)

StepX# = -Sin(Angle#)
StepY# = -Cos(Angle#)

DX# = X2
DY# = Y2

Matka# = Sqr(XEro*XEro+YEro*YEro)




Repeat
c = c + 1

Line X1,Y1,DX,DY,col

DX# = DX# + StepX#
DY# = DY# + StepY#


Until c >= Matka#

End Function

Function Line(X1,Y1,X2,Y2,col)
XEro = X1-X2
YEro = Y1-Y2

Angle# = ATan2(XEro,YEro)

StepX# = -Sin(Angle#)
StepY# = -Cos(Angle#)

DX# = X1
DY# = Y1

Matka# = Sqr(XEro*XEro+YEro*YEro)



Repeat
c = c + 1
If DX > 0 And DY > 0 And DX + StepX#
DY# = DY# + StepY#


Until c >= Matka#

End Function


Quote
5H0CKW4VE
*Administrator*

Posts: 7294
(27/3/05 15:50)
81.155.27.21
Reply | Edit | Del
ezSupporter

Re: Weird triangle fill
This wont work here.



Ã,¤Ã,´Ã,¨)
Ã,¸.Ã,·Ã,´Ã,¸.Ã,·*Ã,´Ã,¨) Ã,¸.Ã,·*Ã,¨)
(Ã,¸.Ã,·Ã,´ (Ã,¸.Ã,·`Ã,¤... SHOCKWAVE / DBF...Ã,¤

VISIT DARK BIT FACTORY INTERACTIVE! (please!)

Quote
Blitz Amateur
DBF: Coder

Posts: 54
(28/3/05 0:28)
67.172.138.160
Reply | Edit | Del
Re: Weird triangle fill
Here's a working version


Const ScreenWidth = 320
Const ScreenHeight = 240

Graphics ScreenWidth,ScreenHeight,0,2
SetBuffer BackBuffer()

Repeat



LockBuffer
Triangle MouseX(),MouseY(),50+50*Sin(phase),50+50*Cos(phase),190,90,(Rand(255) Shl 16) + (Rand(255) Shl 8) + Rand(255)
UnlockBuffer

phase = phase + 1

Flip
Cls

Until KeyHit(1)

Function Triangle(X1,Y1,X2,Y2,X3,Y3,col)


XEro = X2-X3
YEro = Y2-Y3

Angle# = ATan2(XEro,YEro)

StepX# = -Sin(Angle#)
StepY# = -Cos(Angle#)

DX# = X2
DY# = Y2

Matka# = Sqr(XEro*XEro+YEro*YEro)




Repeat
c = c + 1

Line X1,Y1,DX,DY,col

DX# = DX# + StepX#
DY# = DY# + StepY#


Until c >= Matka#

End Function

Function Line(X1,Y1,X2,Y2,col)
XEro = X1-X2
YEro = Y1-Y2

Angle# = ATan2(XEro,YEro)

StepX# = -Sin(Angle#)
StepY# = -Cos(Angle#)

DX# = X1
DY# = Y1

Matka# = Sqr(XEro*XEro+YEro*YEro)



Repeat
c = c + 1
If DX > 0 And DY > 0
DX# = DX# + StepX#
DY# = DY# + StepY#
WritePixelFast dx,dy,col
EndIf

Until c >= Matka#

End Function



Quote
5H0CKW4VE
*Administrator*

Posts: 7499
(28/8/05 14:26)
81.153.61.129
Reply | Edit | Del
ezSupporter

Re: Weird triangle fill
Interesting technique to fill the triangle there.



Ã,¤Ã,´Ã,¨)
Ã,¸.Ã,·Ã,´Ã,¸.Ã,·*Ã,´Ã,¨) Ã,¸.Ã,·*Ã,¨)
(Ã,¸.Ã,·Ã,´ (Ã,¸.Ã,·`Ã,¤... SHOCKWAVE / DBF...Ã,¤

VISIT DARK BIT FACTORY INTERACTIVE! (please!)
Shockwave ^ Codigos
Challenge Trophies Won:

Clyde

Weird indeed, but a clever thang. Nice.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

Stonemonkey

I think i tried something like this in my initial attempts but found it'll lead to some pixels having to be filled more than once.