Author Topic: Blue stuff  (Read 538 times)

Marcus

  • Administrator
  • Hero Member
  • *****
  • Posts: 542
    • View Profile
Blue stuff
« on: November 07, 2016 »
Code: [Select]
import "Random.lib"
import "Speed.lib"

set window 32, 32, 700, 700, false
set redraw off

' Create brush.
brushImage = 1
create image 1, 31, 31
set image 1
set color 0, 0, 0
cls
for y = 0 to 30;
dy# = float(y - 15)
dysqr# = dy*dy
for x = 0 to 30
dx# = float(x - 15)
d# = sqr(dx*dx + dysqr)
if d < 15.0
c = int(32.0*(1.0 - d/15.0))
set color c, c, c
set pixel x, y
endif
next
next
set image primary

curveCount = 32
curves#[curveCount][3][4]
for i = 0 to curveCount - 1
curves[i][0][0] = 0.5*float(width(primary)) - 15.0
curves[i][0][1] = 0.5*float(height(primary)) - 15.0
curves[i][1][0] = RandomFloat(float(width(primary))) - 15.0
curves[i][1][1] = RandomFloat(float(height(primary))) - 15.0
curves[i][1][2] = curves[i][1][0] - 15.0
curves[i][1][3] = curves[i][1][1] - 15.0
curves[i][2][0] = RandomFloat(float(width(primary))) - 15.0
curves[i][2][1] = RandomFloat(float(height(primary))) - 15.0
curves[i][2][2] = curves[i][2][0] - 15.0
curves[i][2][3] = curves[i][2][1] - 15.0
next

particleCount = 400
particles?[particleCount]
for i = 0 to particleCount - 1
particles[i].c = RandomInt(curveCount)
particles[i].p# = RandomFloat(1.0)
particles[i].s# = 0.005 + RandomFloat(0.005)
next

curveChangeTimer = 0
set color 0, 32, 64
cls

shouldDraw = true
do
curveChangeTimer = curveChangeTimer - 1
if curveChangeTimer <= 0
curveChangeTimer = 60
for i = 0 to curveCount - 1
if RandomInt(2) = 0
curves[i][1][2] = RandomFloat(float(width(primary))) - 15.0
curves[i][1][3] = RandomFloat(float(height(primary))) - 15.0
endif
if RandomInt(4) = 0
curves[i][2][2] = RandomFloat(float(width(primary))) - 15.0
curves[i][2][3] = RandomFloat(float(height(primary))) - 15.0
endif
next
endif

for i = 0 to curveCount - 1
curves[i][1][0] = curves[i][1][0]*0.99 + curves[i][1][2]*0.01
curves[i][1][1] = curves[i][1][1]*0.99 + curves[i][1][3]*0.01
curves[i][2][0] = curves[i][2][0]*0.99 + curves[i][2][2]*0.01
curves[i][2][1] = curves[i][2][1]*0.99 + curves[i][2][3]*0.01
next

if shouldDraw
for i = 0 to particleCount - 1
particles[i].p# = particles[i].p# + particles[i].s#
if particles[i].p# >= 1.0
particles[i].p# = particles[i].p# - 1.0
particles[i].c = RandomInt(curveCount)
particles[i].s# = 0.005 + RandomFloat(0.005)
endif
c = particles[i].c
p# = particles[i].p#
b1# = (1.0 - p)*(1.0 - p)
b2# = 2.0*(1.0 - p)*p
b3# = p*p
particles[i].x# = b1*curves[c][0][0] + b2*curves[c][1][0] + b3*curves[c][2][0]
particles[i].y# = b1*curves[c][0][1] + b2*curves[c][1][1] + b3*curves[c][2][1]
particles[i].i = int(255.0*(1.0 - p))
next

set color 0, 32, 64, 24
cls
set additive true
for i = 0 to particleCount - 1
set color 64, 128, 255, particles[i].i
draw image brushImage, int(particles[i].x#), int(particles[i].y#)
next
set additive false
redraw
endif

shouldDraw = SPD_HoldFrameDraw(60)

until keydown(27, true)
« Last Edit: November 07, 2016 by Marcus »
.\\\opz

B+

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Blue stuff
« Reply #1 on: November 07, 2016 »
Nice effect! I've been looking for working example using alpha, thanks!  :)

B+

Rick3137

  • Sr. Member
  • ****
  • Posts: 341
  • May the Force be with You
    • View Profile
    • Rick's Programs
Re: Blue stuff
« Reply #2 on: November 07, 2016 »
 Cool... That ought to be useful for something. Just not sure yet what to use it for.

Marcus

  • Administrator
  • Hero Member
  • *****
  • Posts: 542
    • View Profile
Re: Blue stuff
« Reply #3 on: November 07, 2016 »
Cool... That ought to be useful for something. Just not sure yet what to use it for.

 ;D
.\\\opz

Marcus

  • Administrator
  • Hero Member
  • *****
  • Posts: 542
    • View Profile
Re: Blue stuff
« Reply #4 on: November 08, 2016 »
Actually, with some tweaking I could make it look like one of those "plasma globes". But that wouldn't make it much more useful :)
.\\\opz