Author Topic: Wierd Triangle Fill[BB2D]  (Read 3500 times)

0 Members and 1 Guest are viewing this topic.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17414
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Wierd Triangle Fill[BB2D]
« on: May 11, 2006 »
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

Code: [Select]
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

Code: [Select]
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!)
« Last Edit: July 21, 2007 by Shockwave »
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Wierd Triangle Fill
« Reply #1 on: May 13, 2006 »
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:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: Wierd Triangle Fill
« Reply #2 on: May 18, 2006 »
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.