Draw N- Side Gouruad Polygon outlines

Started by kevin, March 03, 2012, 01:19:42 AM

Previous topic - Next topic

kevin

   This is little routine/example that draws the outline of a N-sided circular polygon.  

PlayBASIC Code: [Select]
      For lp=1 to 100
ObjectColour=rndrgb()
objectX =rnd(800)
objectY =rnd(600)
EdgeWidth# =rndrange(10,30)
Size =rndrange(10,400)
Render_Gouraud_Shade(ObjectX,ObjectY, Size, Verts, EdgeWidth#, ObjectCOlour)
next


Sync
waitkey
end


Function Render_Gouraud_Shade(ObjectX,ObjectY, Size, Verts, EdgeWidth#, ObjectCOlour)


SizeOutter = Size+(EdgeWidth#/2)
SizeInner = Size-(EdgeWidth#/2)

Verts=10
For lp=0 to Verts-1

angle#=(360.0/verts)*lp

// calc the center cord
rgb1=ObjectCOlour
x1 = objectX+cosradius(Angle#, Size )
y1 = objectY+sinradius(Angle#, Size )

// calc the outter cord
rgb2=0
x2 = objectX+cosradius(Angle#, SizeOutter )
y2 = objectY+sinradius(Angle#, SizeOutter )

// calc the inner cord
rgb3=0
x3 = objectX+cosradius(Angle#, SizeInner )
y3 = objectY+sinradius(Angle#, SizeInner )

angle#=(360.0/verts)*(mod(lp+1,Verts))

// calc the center cord
rgb4=ObjectCOlour
x4 = objectX+cosradius(Angle#, Size )
y4 = objectY+sinradius(Angle#, Size )

// calc the outter cord
rgb5=0
x5 = objectX+cosradius(Angle#, SizeOutter )
y5 = objectY+sinradius(Angle#, SizeOutter )

// calc the inner cord
rgb6=0
x6 = objectX+cosradius(Angle#, SizeInner )
y6 = objectY+sinradius(Angle#, SizeInner )


; draw outter edges
gouraudquad x2,y2,rgb2, x5,y5,rgb5,x4,y4,rgb4,x1,y1,rgb1

; draw inner edges
gouraudquad x1,y1,rgb1,x4,y4,rgb4,x6,y6,rgb6,x3,y3,rgb3

; show the edges
; line x1,y1,x4,y4
; line x2,y2,x5,y5
; line x3,y3,x6,y6

next

EndFunction







kevin

#1
  Now here's a bit pretty visual effect created simply by using turning on Alpha Addition...  

 Source Code


PlayBASIC Code: [Select]
      Type Tobject
x#
y#
xspeed#
yspeed#
verts
EdgeWidth#
Colour
size
Angle#
RotSpeed#
EndType

DIm Obj as tObject LIst

For lp=1 to 100
obj = new tobject
Obj.Colour=rndrgb()
obj.X =rnd(800)
obj.Y =rnd(600)
obj.Xspeed =rndrange(1,5)
obj.YSpeed =rndrange(1,5)
obj.EdgeWidth# =rndrange(10,30)
obj.Size =rndrange(20,200)
obj.verts =rndrange(3,20)

obj.angle =rnd#(360)
obj.RotSpeed =rndrange#(1,5)
next


Screen=NewIMage(800,600,2)


do
rendertoimage screen
cls 0

inkmode 1+64
for each Obj()
x#=Obj.x#+Obj.xSpeed#
y#=Obj.y#+Obj.ySpeed#
Render_Gouraud_Shade(Obj.X,Obj.Y, Obj.Size, Obj.Verts, Obj.EdgeWidth#, Obj.COlour,Obj.Angle#)
Obj.Angle#=wrapangle(Obj.Angle#+Obj.RotSpeed#)

if x#<0 then x#=0 : Obj.xspeed*=-1
if y#<0 then y#=0 : Obj.yspeed*=-1
if x#>800 then x#=800 : Obj.xspeed*=-1
if y#>600 then y#=600 : Obj.yspeed*=-1

obj.x=x#
obj.y=y#
next
inkmode 1

rendertoscreen
drawimage Screen,0,0,false

Sync
loop




Function Render_Gouraud_Shade(ObjectX,ObjectY, Size, Verts, EdgeWidth#, ObjectCOlour,BaseAngle#)


SizeOutter = Size+(EdgeWidth#/2)
SizeInner = Size-(EdgeWidth#/2)

For lp=0 to Verts-1

angle#=BaseAngle#+((360.0/verts)*lp)

// calc the center cord
rgb1=ObjectCOlour
x1 = objectX+cosradius(Angle#, Size )
y1 = objectY+sinradius(Angle#, Size )

// calc the outter cord
rgb2=0
x2 = objectX+cosradius(Angle#, SizeOutter )
y2 = objectY+sinradius(Angle#, SizeOutter )

// calc the inner cord
rgb3=0
x3 = objectX+cosradius(Angle#, SizeInner )
y3 = objectY+sinradius(Angle#, SizeInner )

angle#=baseangle#+((360.0/verts)*(mod(lp+1,Verts)))


// calc the center cord
rgb4=ObjectCOlour
x4 = objectX+cosradius(Angle#, Size )
y4 = objectY+sinradius(Angle#, Size )

// calc the outter cord
rgb5=0
x5 = objectX+cosradius(Angle#, SizeOutter )
y5 = objectY+sinradius(Angle#, SizeOutter )

// calc the inner cord
rgb6=0
x6 = objectX+cosradius(Angle#, SizeInner )
y6 = objectY+sinradius(Angle#, SizeInner )


; draw outter edges
gouraudquad x2,y2,rgb2, x5,y5,rgb5,x4,y4,rgb4,x1,y1,rgb1

; draw inner edges
gouraudquad x1,y1,rgb1,x4,y4,rgb4,x6,y6,rgb6,x3,y3,rgb3

; show the edges
; line x1,y1,x4,y4
; line x2,y2,x5,y5
; line x3,y3,x6,y6

next
EndFunction





 Video




ATLUS