News:

Function Finder  Find all the functions within source code files

Main Menu

Swarming particles

Started by monkeybot, February 27, 2015, 01:44:24 PM

Previous topic - Next topic

monkeybot

PlayBASIC Code: [Select]
; PROJECT : The Swarm v1
; AUTHOR : Monkeybot
; CREATED : 26/02/2015
; EDITED : 26/02/2015
; ---------------------------------------------------------------------
PositionScreen (GetDesktopWidth()/2)-400,0
Explicit on
setfps(50)
type tPart
x#,y#,xv#,yv#,DesiredXV#,DesiredYV#,ang#,speed#
timetoTrav
EndType
global tx#,ty#
global sx=GetScreenWidth()
global sy=GetScreenHeight()

dim Part as tpart List
makePart()

repeat
cls
print fps()

circlec tx#,ty#,5,0,$00ff00

tx#=MouseX()
ty#=MouseY()
lockbuffer
for each part()
part.x#+=part.xv#*5
part.y#+=part.yv#*5
local rn#=rndrange#(0.02,0.07);0.05;
if part.desiredXV#>part.xv# then part.xv#+=rn#
if part.desiredXV#<part.xv# then part.xv#-=rn#
if part.desiredYV#>part.yv# then part.yv#+=rn#
if part.desiredYV#<part.yv# then part.yv#-=rn#
local dd#=GetDistance2D(part.x#,part.y#,tx#,ty#)
if timer()>part.timetoTrav
local dd#=GetDistance2D(part.x#,part.y#,tx#,ty#)
local offset#=rnd(50)
part.desiredxv#=(tx#+rndrange#(-offset#,offset#)-part.x#)/dd#;*0.2
part.desiredyv#=(ty#+rndrange#(-offset#,offset#)-part.y#)/dd#;*0.2
part.timetoTrav=timer()+rnd(100)
endif
circlec part.x#,part.y#,2,0,$ff0000
next
UnLockBuffer
sync
until false

end

function makePart()
local q
for q=0 to 300
part =new tPart
; part.x#=rnd(sx)
; part.y#=rnd(sy)
; part.xv#=0
; part.yv#=0
; part.ang#=0
part.speed#=1
; local dd#=GetDistance2D(part.x#,part.y#,tx#,ty#)
; part.xv#=(tx#-part.x#)/dd#
; part.yv#=(ty#-part.y#)/dd#
next
EndFunction









use PBCODE for code blocks with highlighting

BlinkOk

very cool monkey dude. it really look like a flock of birds

monkeybot


Sigtrygg

or a swarm of bees, hunting winnie pooh  ;)

monkeybot

I was aiming more at the bee aspect,if truth be told.