News:

Function Finder  Find all the functions within source code files

Main Menu

Lightning Balls

Started by kevin, October 26, 2010, 05:29:49 PM

Previous topic - Next topic

kevin

  Lightning Balls (or something)

   This is couple of little effects tacked together.  


  Version For  PlayBasic V1.64M

PlayBASIC Code: [Select]
   #include "BlitImage"

Size=256

; Create a image using the Ball and size variables
Texture=NewFxImage(Size,Size)

; Render a phone map styled shading to the image
RenderPhongImage Texture,GetImageWidth(Texture)/2,GetImageHeight(TExture)/2,$ffffff,200,2.0


spr=NewSprite(0,0,Texture)
spritedrawmode Spr,2+16
SpriteTint spr,rndrgb()
Centerspritehandle spr
scalesprite spr,0.23

playerx=50
playery=50

Screen=newfximage(GetScreenWidth(),GetScreenHeight())

do

rendertoimage Screen

mx=mousex()
my=mousey()
Radius=200
AngleOffset#=wrapangle(AngleOffset#+1)
For A#=0 to 359 step 10
Angle#=wrapangle(A#+AngleOffset#)
x#=mx+cos(angle#)*(Radius+Sin(Angle#+Y#)*150)
y#=my+sin(angle#)*(Radius+Cos(Angle#+X#)*50)

Draw_Electic_current(mx,my,x#,y#)

positionsprite spr,x#,y#
drawsprite spr
next

rendertoscreen
BlitImageAlphaPostMultColour(Screen,0,0,$fff0d0)

sync
loop




Psub Draw_Electic_current(x1,y1,x2,y2)


dx=x2-x1
dy=y2-y1
angle=atanfull(dy,dx)
h#=sqrt((dx*dx)+(dy*dy))

`print h#

Points=h#/10

oldx#=x1
oldy#=y1

Radius#=10

angle2=wrapangle(angle+90)

OffsetRadius#=4

inkmode 1+32

For lp =1 to POints-1

Offset#=(OffsetRadius#+rnd#(3))*(sin((stepv*8)+Stepv*rnd(20)))

X#=x1+(cos(angle)*radius#)
Y#=y1+(sin(angle)*radius#)

X#=x#+(cos(angle2)*offset#)
Y#=y#+(sin(angle2)*offset#)

OffsetRadius#=OffsetRadius#-0.02

radius#=Radius#+10

linec oldx#,oldy#,x#,y#,$a06040
;rgb(55,0,0)

oldx#=x#
oldy#=y#


next lp


line oldx#,oldy#,x2,y2

inkmode 1
inc stepv,8


EndPsub






   Version for PlayBasic V1.64L  (Learning Edition)

PlayBASIC Code: [Select]
   #include "BlitImage"

Size=256

; Create a image using the Ball and size variables
Texture=NewFxImage(Size,Size)

; Render a phone map styled shading to the image
RenderPhongImage Texture,GetImageWidth(Texture)/2,GetImageHeight(TExture)/2,$ffffff,200,2.0


spr=NewSprite(0,0,Texture)
spritedrawmode Spr,2+16
SpriteTint spr,rndrgb()
Centerspritehandle spr
scalesprite spr,0.23

playerx=50
playery=50

Screen=newfximage(GetScreenWidth(),GetScreenHeight())

do

rendertoimage Screen

mx=mousex()
my=mousey()


inkmode 1


Radius=300
AngleOffset#=wrapangle(AngleOffset#,1)
For A#=0 to 359 step 10
Angle#=wrapangle(A#,AngleOffset#)
x#=mx+cos(angle#)*(Radius+Sin(Angle#+Y#)*150)
y#=my+sin(angle#)*(Radius+Cos(Angle#+X#)*50)

Draw_Electic_current(mx,my,x#,y#)

positionsprite spr,x#,y#
drawsprite spr
next

inkmode 1+32


rendertoscreen
BlitImageAlphaPostMultColour(Screen,0,0,$fff0d0)

sync
loop




Psub Draw_Electic_current(x1,y1,x2,y2)


dx=x2-x1
dy=y2-y1
angle=atanfull(dy,dx)
h#=sqrt((dx*dx)+(dy*dy))

`print h#

Points=h#/10

oldx#=x1
oldy#=y1

Radius#=10

angle2=wrapangle(angle,90)

OffsetRadius#=4

inkmode 1+32

For lp =1 to POints-1

Offset#=(OffsetRadius#+rnd#(3))*(sin((stepv*8)+Stepv*rnd(20)))

X#=x1+cosradius(angle,radius#)
Y#=y1+sinradius(angle,radius#)

X#+=cosradius(angle2,offset#)
Y#+=sinradius(angle2,offset#)

OffsetRadius#=OffsetRadius#-0.02

radius#=Radius#+10

linec oldx#,oldy#,x#,y#,$a06040
;rgb(55,0,0)

oldx#=x#
oldy#=y#


next lp


; line oldx#,oldy#,x2,y2

inkmode 1
inc stepv,8


EndPsub







YouTube





monkeybot

wooo thats groovy,i like it.

kevin

  Lightning Balls #2

   Here's a slight variation of the previous example, the main visual difference is that the balls are connected with gouraud shaded quads this time, although the code is fairly different.  





Size=256

; Create a image using the Ball and size variables
 Texture=NewFxImage(Size,Size)
 
; Render a phone map styled shading to the image
 RenderPhongImage Texture,GetImageWidth(Texture)/2,GetImageHeight(TExture)/2,$ffffff,200,2.0
scaleimage Texture,0.23,0.23,0+2
 

Type tElecticCurrentSprite
Sprite
ThisRGb
EndType

Dim Me as tElecticCurrentSprite list

Me()=CReate_Ellectic_Current_Sprites(30,texture)


Screen=newfximage(GetScreenWidth(),GetScreenHeight())

do

rendertoimage Screen
cls 0
mx=mousex()
my=mousey()

AngleOffset#=wrapangle(AngleOffset#,0.25)
DRaw_Ellectic_Current(me(), mX,my,200,AngleOffset#)
drawallsprites

inkmode 1

rendertoscreen
drawimage Screen,0,0,false

sync
loop


psub CReate_Ellectic_Current_Sprites(NumbOfSprites,texture)
Dim Sprite as tElecticCurrentSprite list
ThisRgB=rndrgb()

For lp=1 to NumbOfSprites
spr=NewSprite(0,0,Texture)
spritedrawmode Spr,2+16
SpriteTint spr,ThisRGB
Centerspritehandle spr

Sprite= new tElecticCurrentSprite
Sprite.sprite=Spr
Sprite.ThisRGB=ThisRGB
next

EndPsub Sprite as tElecticCurrentSprite list



psub DRaw_Ellectic_Current(me as tElecticCurrentSprite list, mX,my,Radius,AngleOffset#)

Count=GetListSize(Me())
inkmode 1+32
for each me()
Angle#=wrapangle(A#,AngleOffset#)
x#=mx+cos(angle#)*(Radius+Sin(Angle#+Y#)*150)
y#=my+sin(angle#)*(Radius+Cos(Angle#+X#)*50)
Gline(mx,my,20,$112233,x#,y#,1,$808080)
positionsprite me.sprite,x#,y#
a#+=(360.0/count)
next
inkmode 1

endpsub





psub Gline(lx1,ly1,width1,colour1,lx2,ly2,width2,colour2)

angle#=getangle2d(lx1,ly1,lx2,ly2)

angle1#=wrapangle(angle#-90)
angle2#=wrapangle(angle#+90)

x1#=lx1+cosradius(angle1#,width1)
y1#=ly1+sinradius(angle1#,width1)

x2#=lx2+cosradius(angle1#,width2)
y2#=ly2+sinradius(angle1#,width2)

x3#=lx2+cosradius(angle2#,width2)
y3#=ly2+sinradius(angle2#,width2)

x4#=lx1+cosradius(angle2#,width1)
y4#=ly1+sinradius(angle2#,width1)

gouraudquad x1#,y1#,Colour1,x2#,y2#,colour2,x3#,y3#,colour2,x4#,y4#,colour1
endpsub



kevin

#3
 Glow / Lightning Balls Thing

     This is slight variation of the demo above, but this time we have a little video.  The clip was created by saving the raw frames to disc as sequential file names, then using virtual dub to make the AVI / compress them.   Which is handy approach to making little clips such as this.


Video

 




Download

   Attached bellow