pixiVerse - artificial life
pixiVerse - artificial life
Hello
I havent coded a single line in 20 years, but I have an idea for a new kind of particle life which I want to implement in pixilang.
Any help will be appreciated.
My idea is instead of having a limited number of particle classes for particle types, you use thearbitrary RGB values of random colored pixels for attraction/repulsion parameters,
Another idea is to introduce a lifespan for the particles, and each time a particle dies a new random particle is born.
More on particle life in this video
More on my ideas in another post soon
I havent coded a single line in 20 years, but I have an idea for a new kind of particle life which I want to implement in pixilang.
Any help will be appreciated.
My idea is instead of having a limited number of particle classes for particle types, you use thearbitrary RGB values of random colored pixels for attraction/repulsion parameters,
Another idea is to introduce a lifespan for the particles, and each time a particle dies a new random particle is born.
More on particle life in this video
More on my ideas in another post soon
Re: pixiVerse - artificial life
I also want the particles to move in a 3D space
Last edited by ainegil on Sat Sep 24, 2022 3:20 pm, edited 1 time in total.
Re: pixiVerse - artificial life
I only have Android devices, and I am still looking for an editor for pixilang.
The code us about 1/3 of what is needed to turn this into a pixi script.
Will post questions later, if someone wants to give it a try in the meantime or has other suggestions, just go ahead ir let me know.
I hope some people are interested in this.
The code us about 1/3 of what is needed to turn this into a pixi script.
Will post questions later, if someone wants to give it a try in the meantime or has other suggestions, just go ahead ir let me know.
I hope some people are interested in this.
Re: pixiVerse - artificial life
( obsolete - deleted)
Last edited by ainegil on Sat Sep 24, 2022 3:19 pm, edited 1 time in total.
Re: pixiVerse - artificial life
...
Last edited by ainegil on Sat Sep 24, 2022 3:19 pm, edited 1 time in total.
Re: pixiVerse - artificial life
Deleted
Last edited by ainegil on Sat Sep 24, 2022 3:18 pm, edited 1 time in total.
Re: pixiVerse - artificial life
(DELETED)
Last edited by ainegil on Sat Sep 24, 2022 3:18 pm, edited 1 time in total.
Re: pixiVerse - artificial life
Ok, here is a first working version
Its rather slow though, too slow, maybe someone has an idea how to optimize?
EDIT: SEE NEXT POST
Its rather slow though, too slow, maybe someone has an idea how to optimize?
EDIT: SEE NEXT POST
Last edited by ainegil on Sat Sep 24, 2022 6:02 pm, edited 1 time in total.
Re: pixiVerse - artificial life
... ...
Last edited by ainegil on Sun Sep 25, 2022 2:28 pm, edited 1 time in total.
Re: pixiVerse - artificial life
lots of changes, cubic forces etc
...
...
Last edited by ainegil on Mon Sep 26, 2022 3:09 pm, edited 1 time in total.
Re: pixiVerse - artificial life
Finally, a proper version.
Shows some nice emergent flocking swarm behaviour, but is different from the 2D version
Check it out, forget the sh1t around us for a moment.
The longer it runs the more ciherent it becomes
Shows some nice emergent flocking swarm behaviour, but is different from the 2D version
Check it out, forget the sh1t around us for a moment.
The longer it runs the more ciherent it becomes
Code: Select all
Numparticles = 300
Distscale = 0.717
Distmax = sqrt(1280*1280 + 720*720)*2
Distmin = 2
Distmin1_2 = Distmin / 2
Distrange = Distmax - Distmin
Frictioncoeff = 0.89
Speedstep = .6
Maxlife = 8000
Minbright = 16 //255 * 0.382
Lifetime = new( Numparticles )
Particlecolor = new( Numparticles )
ParticleX = new( Numparticles,1 ,FLOAT32 )
ParticleY = new( Numparticles,1 ,FLOAT32 )
ParticleZ = new( Numparticles,1 ,FLOAT32 )
ParticleVx = new( Numparticles,1 ,FLOAT32 )
ParticleVy = new( Numparticles,1 ,FLOAT32 )
ParticleVz = new( Numparticles,1 ,FLOAT32 )
StageW = 640
StageH = 360
StageD = 360
//202
StageW_2 = StageW / 2
StageH_2 = StageH / 2
StageD_2 = StageD / 2
norm = 1 / 255
norm32 = 1 / 32767
rand_seed(0)
// ----------SET UP CANVAS
//set_pixel_size( WINDOW_XSIZE / StageW )
//resize( get_screen(), WINDOW_XSIZE, WINDOW_YSIZE )
Maincanvas = new( StageW , StageH )
set_screen( Maincanvas )
// -----------------------
//mainroutine:
while (1)
{
// loop per each particle1 with x1, y1, z1, R1, G1, B1
// loop per each particle2 with x2, y2, z2, R2, G2, B2
for( i = 0; i < Numparticles; i + 1)
{
// ‐---------init particle
if Lifetime[ i ] < 1
{
rando = rand()
Lifetime[ i ] = Maxlife * rando * norm32 * 0.618 + Maxlife * 0.382
R = rand() & 255
G = rand() & 255
B = rand() & 255
R = ( rand() & 7 ) * 32
G = ( rand() & 7 ) * 32
B = ( rand() & 7 ) * 32
R = ( R * ( 255 - Minbright ) * norm + Minbright ) & 255
G = ( G * ( 255 - Minbright ) * norm + Minbright ) & 255
B = ( B * ( 255 - Minbright ) * norm + Minbright ) & 255
Particlecolor[ i ] = get_color(R,G,B)
ParticleStagecolor[ i ] = get_color(R/4 + 191,G/4 + 191,B/4 + 191)
ParticleX[ i ] = StageW_2 //rand() * norm32 * StageW
ParticleY[ i ] = StageH_2 //rand() * norm32 * StageH
ParticleZ[ i ] = StageD_2 //rand() * norm32 * StageD
}
Lifetime[ i ] = Lifetime[ i ] - 1
//------------‐---------------‐--‐------- calculate‐-------------------
color1 = Particlecolor[ i ]
R1 = get_red(color1) * norm
G1 = get_red(color2) * norm
B1 = get_blue(color1) * norm
for( j = 0; j < Numparticles; j + 1 )
{
color2 = Particlecolor[ j ]
R2 = get_blue(color2) * norm
G2 = get_green(color1) * norm
B2 = get_green(color2) * norm
// attraction-repulsion weight by color
Cweight = (R1*R2 + G1*G2 + B1*B2)/6
Cweight = Cweight - ( R1 * ( G2 + B2 ) + G1 * ( R2 + B2 ) + B1 * ( R2 + G2 ) )/12
if Cweight > 0 { SgnC = 1 }
else {
Cweight = Cweight * 0.1
SgnC = -1
}
AbsCW = abs( Cweight )
// attraction-repulsion weight by distance
DistX = ParticleX[ j ] - ParticleX[ i ]
if abs( DistX ) >= StageW_2
{ DistX = - ( StageW - DistX ) }
if DistX < 0 { SgnX = -1 } else { SgnX = 1 }
DistY = ParticleY[ j ] - ParticleY[ i ]
if abs( DistY ) >= StageH_2
{ DistY = - ( StageH - DistY ) }
if DistY < 0 { SgnY = -1 } else { SgnY = 1 }
DistZ = ParticleZ[ j ] - ParticleZ[ i ]
if abs( DistZ ) >= StageD_2
{ DistZ = - ( StageD - DistZ ) }
if DistZ < 0 { SgnZ = -1 } else { SgnZ = 1 }
DistrangeScaled = Distrange * ( 1 - Distscale ) + Distrange * Distscale * AbsCW
Distrange_2 = DistrangeScaled / 2
if SgnC > 0 {
Tx = abs( DistX ) - Distmin1_2
if Tx < Distmin
{ DXweight = - SgnX * Tx / Distmin1_2 }
else { if Tx < DistrangeScaled
{ DXweight = SgnX * (1- ( Tx - Distmin1_2 )/ DistrangeScaled )}
else
{ DXweight = 0 }
}
Ty = abs( DistY ) - Distmin1_2
if Ty < Distmin
{ DYweight = - SgnY * Ty / Distmin1_2 }
else { if Ty < DistrangeScaled
{ DYweight = SgnY * (1- ( Ty - Distmin1_2 )/ DistrangeScaled )}
else
{ DYweight = 0 }
}
Tz = abs( DistZ ) - Distmin1_2
if Tz < Distmin
{ DZweight = - SgnZ * Tz / Distmin1_2 }
else { if Tz < DistrangeScaled
{ DZweight = SgnZ * (1- ( Tz - Distmin1_2 )/ DistrangeScaled )}
else
{ DZweight = 0 }
}
} else {
Tx = abs( DistX )
if Tx < DistrangeScaled
{ DXweight = - SgnX * ( 1- Tx / DistrangeScaled )
}
else
{ DXweight = 0 }
Ty = abs( DistY )
if Ty < DistrangeScaled
{ DYweight = - SgnY * ( 1- Ty / DistrangeScaled )
}
else
{ DYweight = 0 }
Tx = abs( DistZ )
if Tz < DistrangeScaled
{ DZweight = - SgnZ * ( 1- Tz / DistrangeScaled )
}
else
{ DZweight = 0 }
}
// ----------- update velocity
//ForceX = DXweight * abs( DXweight ) * Cweight * Speedstep
ForceX = DXweight * DXweight * DXweight * Speedstep * AbsCW
ParticleVx[ i ] = (( ParticleVx[ i ] + ForceX ) + ParticleVx[ i ]*0.0000)
ParticleVx[ j ] = (( ParticleVx[ j ] + ForceX ) + ParticleVx[ j ]*0.0000)
ForceY = DYweight * DYweight * DYweight * Speedstep * AbsCW
ParticleVy[ i ] = (( ParticleVy[ i ] + ForceY ) + ParticleVy[ i ]*0.0000)
ParticleVy[ j ] = (( ParticleVy[ j ] + ForceY ) + ParticleVy[ j ]*0.0000)
ForceZ = DZweight * DZweight * DZweight * Speedstep * AbsCW
ParticleVz[ i ] = (( ParticleVz[ i ] + ForceZ ) + ParticleVz[ i ]*0.0000)
ParticleVz[ j ] = (( ParticleVz[ j ] + ForceZ ) + ParticleVz[ j ]*0.0000)
}
}
// end inner loop
// end outer loop
// -----------Draw particles
transp(97)
effector( EFF_HBLUR, 2, WHITE, - StageW_2 , - StageH_2, StageW, StageH )
effector( EFF_VBLUR, 2, WHITE, - StageW_2 , - StageH_2, StageW, StageH )
//clear()
transp(255)
for( i = 0; i < Numparticles; i + 1 )
{
// ---------- friction
ParticleVx[ i ] = ParticleVx[ i ] * Frictioncoeff
ParticleVy[ i ] = ParticleVy[ i ] * Frictioncoeff
ParticleVz[ i ] = ParticleVz[ i ] * Frictioncoeff
// ----------- move
ParticleX[ i ] = ParticleX[ i ] + ParticleVx[ i ]
ParticleY[ i ] = ParticleY[ i ] + ParticleVy[ i ]
ParticleZ[ i ] = ParticleZ[ i ] + ParticleVz[ i ]
// ----------WRAP INTO FIELD
ParticleX[ i ] = mod( ParticleX[ i ], StageW )
if ParticleX[ i ] < 0 { ParticleX[ i ] = ParticleX[ i ] + StageW }
ParticleY[ i ] = mod( ParticleY[ i ], StageH )
if ParticleY[ i ] < 0 { ParticleY[ i ] = ParticleY[ i ] + StageH }
ParticleZ[ i ] = mod( ParticleZ[ i ], StageD )
if ParticleZ[ i ] < 0 { ParticleZ[ i ] = ParticleZ[ i ] + StageD }
//dot3D( ParticleX[ i ], ParticleY[ i ], ParticleZ[ i ], Particlecolor[ i ] )
dot( ParticleX[ i ] - StageW_2, ParticleY[ i ] - StageH_2, ParticleStagecolor[ i ] )
dot( ParticleX[ i ] - StageW_2, ParticleY[ i ] - StageH_2, ParticleStagecolor[ i ] )
//dot( ParticleX[ i ] - StageW_2, ParticleY[ i ] - StageH_2, WHITE )
}
frame()
}
//goto mainroutine
Re: pixiVerse - artificial life
Nicer paramters, and slightly optimized
Code: Select all
Numparticles = 320
Distscale = 1 - 0.159 //0.717
Distmax = sqrt(1280*1280 + 720*720 + 720*720)
//sqrt(640*640 + 360*360 + 360*360)
//sqrt(1280*1280 + 720*720 + 720*720)
Distmin = 1.382
Distmin1_2 = Distmin / 2
Distrange = Distmax - Distmin
Repulsrange = 6 / Distrange
Frictioncoeff = 0.81 //0.87
Speedstep = 0.03 //.23
Maxlife = 8000
Minbright = 0 //255 * 0.382
Lifetime = new( Numparticles )
Particlecolor = new( Numparticles )
ParticleX = new( Numparticles,1 ,FLOAT32 )
ParticleY = new( Numparticles,1 ,FLOAT32 )
ParticleZ = new( Numparticles,1 ,FLOAT32 )
ParticleVx = new( Numparticles,1 ,FLOAT32 )
ParticleVy = new( Numparticles,1 ,FLOAT32 )
ParticleVz = new( Numparticles,1 ,FLOAT32 )
StageW = 360
StageH = 222
StageD = 137
//202
StageW_2 = StageW / 2
StageH_2 = StageH / 2
StageD_2 = StageD / 2
norm = 1 / 255
norm32 = 1 / 32767
normA = 1 / ( 255*255*3*2)
normB = 1 / ( 255*510*3*2)
norm6 = 1/6
norm12 = 1/12
rand_seed(12345)
// ----------SET UP CANVAS
//set_pixel_size( WINDOW_XSIZE / StageW )
//resize( get_screen(), WINDOW_XSIZE, WINDOW_YSIZE )
Maincanvas = new( StageW , StageH )
set_screen( Maincanvas )
// -----------------------
//mainroutine:
while (1)
{
// loop per each particle1 with x1, y1, z1, R1, G1, B1
// loop per each particle2 with x2, y2, z2, R2, G2, B2
for( i = 0; i < Numparticles; i + 1)
{
// ‐---------init particle
if Lifetime[ i ] < 1
{
rando = rand()
Lifetime[ i ] = Maxlife * rando * norm32 * 0.618 + Maxlife * 0.382
R = rand() & 255
G = rand() & 255
B = rand() & 255
//R = ( rand() & 3 ) * 64 + 63
//G = ( rand() & 3 ) * 64 + 63
//B = ( rand() & 3 ) * 64 + 63
//R = ( rand() & 1 ) * 128 + 127
//G = ( rand() & 1 ) * 128 + 127
//B = ( rand() & 1 ) * 128 + 127
R = ( R * ( 255 - Minbright ) * norm + Minbright ) & 255
G = ( G * ( 255 - Minbright ) * norm + Minbright ) & 255
B = ( B * ( 255 - Minbright ) * norm + Minbright ) & 255
Particlecolor[ i ] = get_color(R,G,B)
ParticleStagecolor[ i ] = get_color(R/4 + 191,G/4 + 191,B/4 + 191)
ParticleX[ i ] = StageW_2 + rand() * norm32 //* StageW
ParticleY[ i ] = StageH_2 + rand() * norm32 //* StageH
ParticleZ[ i ] = StageD_2 + rand() * norm32 //* StageD
}
Lifetime[ i ] = Lifetime[ i ] - 1
//------------‐---------------‐--‐------- calculate‐-------------------
R1 = get_red( Particlecolor[ i ] )
G1 = get_red( Particlecolor[ i ] )
B1 = get_blue( Particlecolor[ i ] )
for( j = 0; j < Numparticles; j + 1 )
{
R2 = get_blue( Particlecolor[ j ] )
G2 = get_green( Particlecolor[ j ] )
B2 = get_green( Particlecolor[ j ] )
// attraction-repulsion weight by color
Cweight = (R1*R2 + G1*G2 + B1*B2)*normA
Cweight = - Cweight + ( R1 * ( G2 + B2 ) + G1 * ( R2 + B2 ) + B1 * ( R2 + G2 ) )*normB
//Cweight = Cweight * abs(Cweight)
//Cweight = Cweight * Cweight * Cweight
Cweight = floor(pow(Cweight,3) * 2 + 1) / 3
if Cweight > 0 { SgnC = 1 }
else {
Cweight = Cweight * Repulsrange
SgnC = -1
}
AbsCW = abs( Cweight )
// attraction-repulsion weight by distance
DistX = ParticleX[ j ] - ParticleX[ i ]
if abs( DistX ) >= StageW_2
{ DistX = - ( StageW - DistX ) }
if DistX < 0 { SgnX = -1 } else { SgnX = 1 }
DistY = ParticleY[ j ] - ParticleY[ i ]
if abs( DistY ) >= StageH_2
{ DistY = - ( StageH - DistY ) }
if DistY < 0 { SgnY = -1 } else { SgnY = 1 }
DistZ = ParticleZ[ j ] - ParticleZ[ i ]
if abs( DistZ ) >= StageD_2
{ DistZ = - ( StageD - DistZ ) }
if DistZ < 0 { SgnZ = -1 } else { SgnZ = 1 }
//DistrangeScaled = Distrange * ( 1 - Distscale ) + Distrange * Distscale * AbsCW
DistrangeScaled = Distrange * Distscale
DistrangeScaled = Distrange - DistrangeScaled + DistrangeScaled * AbsCW
Distrange_2 = DistrangeScaled / 2
if SgnC > 0 {
Tx = abs( DistX ) - Distmin1_2
if Tx < Distmin
{ DXweight = - SgnX * Tx / Distmin1_2 }
else { if Tx < DistrangeScaled
{ DXweight = SgnX * (1- ( Tx - Distmin1_2 )/ DistrangeScaled )}
else
{ DXweight = 0 }
}
Ty = abs( DistY ) - Distmin1_2
if Ty < Distmin
{ DYweight = - SgnY * Ty / Distmin1_2 }
else { if Ty < DistrangeScaled
{ DYweight = SgnY * (1- ( Ty - Distmin1_2 )/ DistrangeScaled )}
else
{ DYweight = 0 }
}
Tz = abs( DistZ ) - Distmin1_2
if Tz < Distmin
{ DZweight = - SgnZ * Tz / Distmin1_2 }
else { if Tz < DistrangeScaled
{ DZweight = SgnZ * (1- ( Tz - Distmin1_2 )/ DistrangeScaled )}
else
{ DZweight = 0 }
}
} else {
Tx = abs( DistX )
if Tx < DistrangeScaled
{ DXweight = - SgnX * ( 1- Tx / DistrangeScaled )
}
else
{ DXweight = 0 }
Ty = abs( DistY )
if Ty < DistrangeScaled
{ DYweight = - SgnY * ( 1- Ty / DistrangeScaled )
}
else
{ DYweight = 0 }
Tx = abs( DistZ )
if Tz < DistrangeScaled
{ DZweight = - SgnZ * ( 1- Tz / DistrangeScaled )
}
else
{ DZweight = 0 }
}
// ----------- update velocity
Accel = Speedstep * AbsCW
ForceX = DXweight * DXweight * DXweight * Accel
ParticleVx[ i ] = ParticleVx[ i ] + ForceX
ParticleVx[ j ] = ParticleVx[ j ] + ForceX
ForceY = DYweight * DYweight * DYweight * Accel
ParticleVy[ i ] = ParticleVy[ i ] + ForceY
ParticleVy[ j ] = ParticleVy[ j ] + ForceY
ForceZ = DZweight * DZweight * DZweight * Accel
ParticleVz[ i ] = ParticleVz[ i ] + ForceZ
ParticleVz[ j ] = ParticleVz[ j ] + ForceZ
}
}
// end inner loop
// end outer loop
// -----------Draw particles
transp(97)
effector( EFF_HBLUR, 2, WHITE, - StageW_2 , - StageH_2, StageW, StageH )
effector( EFF_VBLUR, 2, WHITE, - StageW_2 , - StageH_2, StageW, StageH )
transp(12)
clear()
transp(255)
for( i = 0; i < Numparticles; i + 1 )
{
// ---------- friction
ParticleVx[ i ] = ParticleVx[ i ] * Frictioncoeff
ParticleVy[ i ] = ParticleVy[ i ] * Frictioncoeff
ParticleVz[ i ] = ParticleVz[ i ] * Frictioncoeff
// ----------- move
ParticleX[ i ] = ParticleX[ i ] + ParticleVx[ i ]
ParticleY[ i ] = ParticleY[ i ] + ParticleVy[ i ]
ParticleZ[ i ] = ParticleZ[ i ] + ParticleVz[ i ]
// ----------WRAP INTO FIELD
ParticleX[ i ] = mod( ParticleX[ i ], StageW )
if ParticleX[ i ] < 0 { ParticleX[ i ] = ParticleX[ i ] + StageW }
ParticleY[ i ] = mod( ParticleY[ i ], StageH )
if ParticleY[ i ] < 0 { ParticleY[ i ] = ParticleY[ i ] + StageH }
ParticleZ[ i ] = mod( ParticleZ[ i ], StageD )
if ParticleZ[ i ] < 0 { ParticleZ[ i ] = ParticleZ[ i ] + StageD }
//dot3D( ParticleX[ i ], ParticleY[ i ], ParticleZ[ i ], Particlecolor[ i ] )
//dot( ParticleX[ i ] - StageW_2, ParticleY[ i ] - StageH_2, ParticleStagecolor[ i ] )
dot( ParticleX[ i ] - StageW_2, ParticleY[ i ] - StageH_2, ParticleStagecolor[ i ] )
//dot( ParticleX[ i ] - StageW_2, ParticleY[ i ] - StageH_2, WHITE )
}
frame()
}
//goto mainroutine
Re: pixiVerse - artificial life
This one is amazing, it features higher order structures like quasi symmetric motion of seperate groups.
You have to wait for it
You have to wait for it
Code: Select all
Numparticles = 256
Distscale = 1 - 0.159 //0.717
Distmax = sqrt(1280*1280 + 720*720 + 720*720)
//sqrt(640*640 + 360*360 + 360*360)
//sqrt(1280*1280 + 720*720 + 720*720)
Distmin = 1.382
Distmin1_2 = Distmin / 2
Distrange = Distmax - Distmin
Repulsrange = 6 / Distrange
Frictioncoeff = 0.851//0.81 0.87
Speedstep = 0.13 //.23
Maxlife = 8000
Minbright = 0 //255 * 0.382
Lifetime = new( Numparticles )
Particlecolor = new( Numparticles )
ParticleX = new( Numparticles,1 ,FLOAT32 )
ParticleY = new( Numparticles,1 ,FLOAT32 )
ParticleZ = new( Numparticles,1 ,FLOAT32 )
ParticleVx = new( Numparticles,1 ,FLOAT32 )
ParticleVy = new( Numparticles,1 ,FLOAT32 )
ParticleVz = new( Numparticles,1 ,FLOAT32 )
StageW = 360
StageH = 360
StageD = 360
//202
StageW_2 = StageW / 2
StageH_2 = StageH / 2
StageD_2 = StageD / 2
norm = 1 / 255
norm32 = 1 / 32767
normA = 1 / ( 255*255*3*2)
normB = 1 / ( 255*510*3*2)
norm6 = 1/6
norm12 = 1/12
rand_seed(12345)
// ----------SET UP CANVAS
//set_pixel_size( WINDOW_XSIZE / StageW )
//resize( get_screen(), WINDOW_XSIZE, WINDOW_YSIZE )
Maincanvas = new( StageW , StageH )
set_screen( Maincanvas )
// -----------------------
//mainroutine:
while (1)
{
// loop per each particle1 with x1, y1, z1, R1, G1, B1
// loop per each particle2 with x2, y2, z2, R2, G2, B2
for( i = 0; i < Numparticles; i + 1)
{
// ‐---------init particle
if Lifetime[ i ] < 1
{
rando = rand()
Lifetime[ i ] = Maxlife * rando * norm32 * 0.618 + Maxlife * 0.382
R = rand() & 255
G = rand() & 255
B = rand() & 255
//R = ( rand() & 3 ) * 64 + 63
//G = ( rand() & 3 ) * 64 + 63
//B = ( rand() & 3 ) * 64 + 63
//R = ( rand() & 1 ) * 128 + 127
//G = ( rand() & 1 ) * 128 + 127
//B = ( rand() & 1 ) * 128 + 127
R = ( R * ( 255 - Minbright ) * norm + Minbright ) & 255
G = ( G * ( 255 - Minbright ) * norm + Minbright ) & 255
B = ( B * ( 255 - Minbright ) * norm + Minbright ) & 255
Particlecolor[ i ] = get_color(R,G,B)
ParticleStagecolor[ i ] = get_color(R/4 + 191,G/4 + 191,B/4 + 191)
ParticleX[ i ] = StageW_2 + rand() * norm32 * StageW
ParticleY[ i ] = StageH_2 + rand() * norm32 * StageH
ParticleZ[ i ] = StageD_2 + rand() * norm32 * StageD
}
Lifetime[ i ] = Lifetime[ i ] - 1
//------------‐---------------‐--‐------- calculate‐-------------------
R1 = get_red( Particlecolor[ i ] )
G1 = get_red( Particlecolor[ i ] )
B1 = get_blue( Particlecolor[ i ] )
for( j = 0; j < Numparticles; j + 1 )
{
R2 = get_blue( Particlecolor[ j ] )
G2 = get_green( Particlecolor[ j ] )
B2 = get_green( Particlecolor[ j ] )
// attraction-repulsion weight by color
Cweight = (R1*R2 + G1*G2 + B1*B2)*normA
Cweight = - Cweight + ( R1 * ( G2 + B2 ) + G1 * ( R2 + B2 ) + B1 * ( R2 + G2 ) )*normB
//Cweight = Cweight * abs(Cweight)
//Cweight = Cweight * Cweight * Cweight
Cweight = (floor(pow(Cweight,3) * 4 )+ 0.236523620109034688) / 4.236523620109034688
if Cweight > 0 { SgnC = 1 }
else {
Cweight = Cweight * Repulsrange
SgnC = -1
}
AbsCW = abs( Cweight )
// attraction-repulsion weight by distance
DistX = ParticleX[ j ] - ParticleX[ i ]
if abs( DistX ) > StageW_2 - 0.5
{ DistX = - ( StageW - DistX - 0.5 ) }
if DistX < 0 { SgnX = -1 } else { SgnX = 1 }
DistY = ParticleY[ j ] - ParticleY[ i ]
if abs( DistY ) > StageH_2 - 0.5
{ DistY = - ( StageH - DistY - 0.5 ) }
if DistY < 0 { SgnY = -1 } else { SgnY = 1 }
DistZ = ParticleZ[ j ] - ParticleZ[ i ]
if abs( DistZ ) > StageD_2 - 0.5
{ DistZ = - ( StageD - DistZ - 0.5 ) }
if DistZ < 0 { SgnZ = -1 } else { SgnZ = 1 }
//DistrangeScaled = Distrange * ( 1 - Distscale ) + Distrange * Distscale * AbsCW
DistrangeScaled = Distrange * Distscale
DistrangeScaled = Distrange - DistrangeScaled + DistrangeScaled * AbsCW
Distrange_2 = DistrangeScaled / 2
if SgnC > 0 {
Tx = abs( DistX ) - Distmin1_2
if Tx < Distmin
{ DXweight = - SgnX * Tx / Distmin1_2 }
else { if Tx < DistrangeScaled
{ DXweight = SgnX * (1- ( Tx - Distmin1_2 )/ DistrangeScaled )}
else
{ DXweight = 0 }
}
Ty = abs( DistY ) - Distmin1_2
if Ty < Distmin
{ DYweight = - SgnY * Ty / Distmin1_2 }
else { if Ty < DistrangeScaled
{ DYweight = SgnY * (1- ( Ty - Distmin1_2 )/ DistrangeScaled )}
else
{ DYweight = 0 }
}
Tz = abs( DistZ ) - Distmin1_2
if Tz < Distmin
{ DZweight = - SgnZ * Tz / Distmin1_2 }
else { if Tz < DistrangeScaled
{ DZweight = SgnZ * (1- ( Tz - Distmin1_2 )/ DistrangeScaled )}
else
{ DZweight = 0 }
}
} else {
Tx = abs( DistX )
if Tx < DistrangeScaled
{ DXweight = - SgnX * ( 1- Tx / DistrangeScaled )
}
else
{ DXweight = 0 }
Ty = abs( DistY )
if Ty < DistrangeScaled
{ DYweight = - SgnY * ( 1- Ty / DistrangeScaled )
}
else
{ DYweight = 0 }
Tx = abs( DistZ )
if Tz < DistrangeScaled
{ DZweight = - SgnZ * ( 1- Tz / DistrangeScaled )
}
else
{ DZweight = 0 }
}
// ----------- update velocity
Accel = Speedstep * AbsCW
ForceX = DXweight * DXweight * DXweight * Accel
ParticleVx[ i ] = ParticleVx[ i ] + ForceX
ParticleVx[ j ] = ParticleVx[ j ] + ForceX
ForceY = DYweight * DYweight * DYweight * Accel
ParticleVy[ i ] = ParticleVy[ i ] + ForceY
ParticleVy[ j ] = ParticleVy[ j ] + ForceY
ForceZ = DZweight * DZweight * DZweight * Accel
ParticleVz[ i ] = ParticleVz[ i ] + ForceZ
ParticleVz[ j ] = ParticleVz[ j ] + ForceZ
}
}
// end inner loop
// end outer loop
// -----------Draw particles
transp(97)
effector( EFF_HBLUR, 2, WHITE, - StageW_2 , - StageH_2, StageW, StageH )
effector( EFF_VBLUR, 2, WHITE, - StageW_2 , - StageH_2, StageW, StageH )
transp(12)
clear()
transp(255)
for( i = 0; i < Numparticles; i + 1 )
{
// ---------- friction
ParticleVx[ i ] = ParticleVx[ i ] * Frictioncoeff
ParticleVy[ i ] = ParticleVy[ i ] * Frictioncoeff
ParticleVz[ i ] = ParticleVz[ i ] * Frictioncoeff
// ----------- move
ParticleX[ i ] = ParticleX[ i ] + ParticleVx[ i ]
ParticleY[ i ] = ParticleY[ i ] + ParticleVy[ i ]
ParticleZ[ i ] = ParticleZ[ i ] + ParticleVz[ i ]
// ----------WRAP INTO FIELD
ParticleX[ i ] = mod( ParticleX[ i ], StageW )
if ParticleX[ i ] < 0 { ParticleX[ i ] = ParticleX[ i ] + StageW }
ParticleY[ i ] = mod( ParticleY[ i ], StageH )
if ParticleY[ i ] < 0 { ParticleY[ i ] = ParticleY[ i ] + StageH }
ParticleZ[ i ] = mod( ParticleZ[ i ], StageD )
if ParticleZ[ i ] < 0 { ParticleZ[ i ] = ParticleZ[ i ] + StageD }
//dot3D( ParticleX[ i ], ParticleY[ i ], ParticleZ[ i ], Particlecolor[ i ] )
//dot( ParticleX[ i ] - StageW_2, ParticleY[ i ] - StageH_2, ParticleStagecolor[ i ] )
dot( ParticleX[ i ] - StageW_2, ParticleY[ i ] - StageH_2, ParticleStagecolor[ i ] )
//dot( ParticleX[ i ] - StageW_2, ParticleY[ i ] - StageH_2, WHITE )
}
frame()
}
//goto mainroutine
Re: pixiVerse - artificial life
Here is demo video of the particle code abive (with some changes)
Note there are only a gravity like force and a repulsive force.
Yet the particles behave like choreographed, like a ballet.
Remote groups carry out symmetric movements.
This seems all due to a force factor related to the golden ratio.
Quite a discovery I think.
Note there are only a gravity like force and a repulsive force.
Yet the particles behave like choreographed, like a ballet.
Remote groups carry out symmetric movements.
This seems all due to a force factor related to the golden ratio.
Quite a discovery I think.
Re: pixiVerse - artificial life
And here is a comparison between two systems,
on the left the weights of the particles are constraint to classes of the same weight, on the right the weights are not constraint to classes but arbitrary. The masses have the same value range.
Otherwise both systems are identical
on the left the weights of the particles are constraint to classes of the same weight, on the right the weights are not constraint to classes but arbitrary. The masses have the same value range.
Otherwise both systems are identical