Post by johnno56 on Jun 20, 2019 17:04:52 GMT -6
Here is a Basic256 (author unknown) program that I converted to sdlbasic and now to RCBasic... It is totally useless except for demonstrating 'parts' of the particles.
arial.ttf (358.5 KB)
The listing also has filled and unfilled circles and boxes....
If you can find some use for it, fine. Otherwise you can probably use it to cure insomnia... lol
arial.ttf (358.5 KB)
xmax = 700
ymax = 400
WindowOpen(0,"Particle Polygons?",0,0,xmax,ymax,0)
Window(0)
CanvasOpen(0,xmax,ymax,0,0,xmax,ymax,0)
Canvas(0)
' ***************
' Particle System
' ***************
' maximum number of particles slots
' lower this to get more fluent effect
maximum =100
' Each particle has 6 parameters
' 0 : location on the x-axis
' 1 : location on the y-axis
' 2 : movement on the x-axis
' 3 : movement on the y-axis
' 4 : how old the particle can get
' 5 : period where particle keeps the same color
dim particle[maximum,6]
' ******************************
' Boiler plate for a nice canvas
' ******************************
hidemouse
randomize(timer)
darkred = rgb(128,0,0)
red = rgb(255,0,0)
orange = rgb(255,128,0)
yellow = rgb(255,255,0)
white = rgb(255,255,255)
' *************************************************
' pre-cache sin/cos calculations (small speed gain)
' *************************************************
dim degree[361,2]
pi = 3.141592654
k=0
for i = 0 to 2*pi step (2*pi/359)
k=k+1
degree[k,0]=sin(i)
degree[k,1]=cos(i)
next
'initialize text
text_count = 0
t1$="Particles Example"
t2$="( Cool, isn't it? )"
t3$="( colourful too )"
t4$=t2$
sw_text=0
font24 = 1
loadFont(1,"arial.ttf",24)
font32 = 2
loadFont(2,"arial.ttf",32)
lings = 0
dim x[10]
dim y[10]
' *************************************************
' initial particle definition: all particles 'dead'
' *************************************************
for i = 0 to maximum - 1
particle[i,4] = 0
next
'**************************************************
' main loop
'**************************************************
do
clearcanvas
' create new particles
' ********************
' select 7 random particles at each cycle
' play with this value to get the best result on your computer
for k = 1 to 7
spawni=rand(maximum)
' if age of the random particle = 0, create one
if particle[spawni,4] = 0 then
' horizontal location
if rand(100)/100 > 0.5 then
particle[spawni,0] = 20
lings = 1
else
particle[spawni,0] = 660
lings = 0
end if
' vertical location
particle[spawni,1] = 350
direction = rand(35) + 157
' horizontal speed vector
if lings = 1 then
particle[spawni,2] = rand(6)
else
particle[spawni,2] = 0 - (rand(6))
end if
' falling speed vector
particle[spawni,3] = (0 - rand(6)) - 5
' particle age
' particle[spawni,4] = 30+rnd(50)
particle[spawni,4] = 50 + rand(50)
' color aging
particle [spawni,5] = particle[spawni,4] / 5
end if
next
' update position on ALL live particles
' *************************************
for i = 0 to maximum - 1
' for all live particles
if particle[i,4] > 0 then
' calculate the new location
particle[i,0] = particle[i,0] + particle[i,2]
particle[i,1] = particle[i,1] + particle[i,3]
' increase the speed of falling
particle[i,3] = particle[i,3] + (rand(100) / 100) / 3
' make the particle older
particle[i,4] = particle[i,4] - 1
' if it hits the bottom, make it bounce up
' 0=no bounce, 1= full bounce,no damping
if particle[i,1] > 370 then
particle[i,3] = 0 - particle[i,3] * ((rand(100) / 100) / 2)
end if
end if
next
' Color determination of the particle
'************************************
for i = 0 to maximum - 1
' for all live particles
if particle[i,4] > 0 then
' color it darkred if less than 20% life left
if particle[i,4] < particle[i,5] then
setColor(darkred)
end if
' color it red if more than 20% life left
if particle[i,4] > (particle[i,5]) then
setColor(red)
end if
' color it orange if more than 40% life left
if particle[i,4] > (particle[i,5] * 2) then
setColor(orange)
end if
' color it yellow if more than 60% life left
if particle[i,4] > (particle[i,5] * 3) then
setColor(yellow)
end if
' color it white if more than 80% life left
if particle[i,4] > (particle[i,5] * 4) then
setColor(white)
end if
'----------------------------
' PLOT ALL THE LIVE PARTICLES
'----------------------------
'--- circles ---
'circle(particle[i,0], particle[i,1], 2+rand(4))
'--- filled circles ---
'circleFill(particle[i,0], particle[i,1], 2 + rand(4))
x[1] = 11 + particle[i,0]
y[1] = 0 + particle[i,1]
x[2] = 8 + particle[i,0]
y[2] = 8 + particle[i,1]
x[3] = 0 + particle[i,0]
y[3] = 8 + particle[i,1]
x[4] = 6 + particle[i,0]
y[4] = 14 + particle[i,1]
x[5] = 0 + particle[i,0]
y[5] = 23 + particle[i,1]
x[6] = 11 + particle[i,0]
y[6] = 18 + particle[i,1]
x[7] = 23 + particle[i,0]
y[7] = 23 + particle[i,1]
x[8] = 17 + particle[i,0]
y[8] = 14 + particle[i,1]
x[9] = 23 + particle[i,0]
y[9] = 8 + particle[i,1]
x[0] = 15 + particle[i,0]
y[0] = 8 + particle[i,1]
' poly(10,x,y)
polyfill(10,x,y)
'box(particle[i,0], particle[i,1], particle[i,0] + 2 + rand(4), particle[i,1] + 2 + rand(4))
'boxFill(particle[i,0], particle[i,1], particle[i,0] + 2 + rand(4), particle[i,1] + 2 + rand(4))
end if
next
setColor(rgb(0,0,255))
font(font32)
DrawText(t1$, 200, 140)
setColor(rgb(0,0,128))
font(font32)
DrawText(t1$, 202, 142)
if text_count < 300 then
font(font24)
setColor(rgb(0,0,192))
DrawText(t4$, 235, 180)
text_count = text_count + 1
else
if sw_text = 1 then
t4$ = t3$
sw_text = 0
else
t4$ = t2$
sw_text = 1
end if
text_count = 0
end if
update()
wait(10)
loop until key(k_escape) = 1
The listing also has filled and unfilled circles and boxes....
If you can find some use for it, fine. Otherwise you can probably use it to cure insomnia... lol