Compare commits

..

No commits in common. "ed2b04caeb54f84456fda3ad9884ee55d62173f7" and "92f6e5cf23f994ce9f22b521f52d7f0614273008" have entirely different histories.

13 changed files with 114 additions and 323 deletions

View File

@ -13,7 +13,6 @@ exportbloubs
genbloubs
movebloubs
mergebloubs
listbloubs
essai
core

View File

@ -1,7 +1,6 @@
all: genbloubs movebloubs exportbloubs mergebloubs \
listbloubs \
essai
# ------------------------------------------------------------
@ -11,8 +10,8 @@ OBJS = bloubspace.o povstuff.o mathstuff.o
# ------------------------------------------------------------
essai: essai.f90 Makefile $(OBJS)
gfortran $(GFOPT) $< $(OBJS) -o $@
essai: essai.f90 Makefile mathstuff.o
gfortran $(GFOPT) $< mathstuff.o -o $@
# ------------------------------------------------------------
@ -47,9 +46,6 @@ genbloubs: genbloubs.f90 Makefile $(OBJS)
movebloubs: movebloubs.f90 Makefile $(OBJS)
gfortran $(GFOPT) $< $(OBJS) -o $@
listbloubs: listbloubs.f90 Makefile $(OBJS)
gfortran $(GFOPT) $< $(OBJS) -o $@
exportbloubs: exportbloubs.f90 Makefile $(OBJS)
gfortran $(GFOPT) $< $(OBJS) -o $@

View File

@ -6,17 +6,15 @@ Le BloubWorld (que l'on appelle aussi BloubSpace) est un espace borné
dans lequel se déplacent des **bloubs**, lesquels sont
des sortes de particule
munie de certaines propriétés (age, grosseur, vitesses, etc...).
Lesquelles valeurs peuvent évoluer en fonction du temps.
Lesquelles évoluent en fonction du temps.
## Description d'un bloub
Attention cette description n'est qu'un exemple !
```
type t_bloubs
character(8) :: nick
logical :: alive
integer :: state
integer :: num
real :: px, py, pz
real :: vx, vy, vz
real :: radius
@ -69,18 +67,14 @@ Sortie sur `stdout` de certaines propriétes des bloubs, qui seront
reprise par un (ou des) scripts écrits en `awk`, afin de générer
ce qu'il faut pour les différents moteurs de rendu.
Bon, pour le moment, il n'y a que POVray, mais Gnuplot arrivera en second.
Bon, pour le moment, il n'y a que POVray :)
### mergebloubs
Alors, celui-ci, il n'est pas vraiment au point. Il faut tout ré-écrire
et faire gaffe à l'explosion quadratique.
Alors, celui-ci, il n'est pas vraiment au point.
## TODO
- Concevoir un système de _bouding box_ facile à utiliser
- Réfléchir à une politique de vieillissement des bloubs
- le `merge` de deux bloubs est-il un acte politique ?

View File

@ -1 +0,0 @@
cube -0.35 -0.5 -0.5 5.0 5.0 5.0

View File

@ -11,139 +11,35 @@ module bloubspace
type t_bloubs
character(8) :: nick
logical :: alive
integer :: state
integer :: num ! ???
real :: px, py, pz
real :: vx, vy, vz
real :: radius
integer :: age, agemax
integer :: age
end type t_bloubs
type t_boundingbox
character(8) :: id
real :: xm, ym, zm
real :: xp, yp, zp
end type t_boundingbox
contains ! -----------------------------------------
! ----------------------------------------------------------------
subroutine load_boundingbox(infile, where, name)
character(*), intent(in) :: infile
type(t_boundingbox), intent (out) :: where
character(8), intent(in) :: name
integer :: fd, errcode
character(200) :: message
print *, "try to load ", infile
! put some default values
where%id = "default"
where%xm = -5.0 ; where%ym = -5.0 ; where%zm = -5.0
where%xp = 5.0 ; where%yp = 5.0 ; where%zp = 5.0
! and now, try to read the file
open (newunit=fd, file=trim(infile), &
status='old', action='read', &
iostat=errcode, iomsg=message)
if (errcode .NE. 0) then
stop 'OPEN ERROR ' // message
endif
do
read(unit=fd, iostat=errcode, iomsg=message, &
fmt='(A,6F8.3)') where
if (errcode .NE. 0) then
! print *, "errcode ", errcode
print *, "message: ", message
exit
endif
enddo
close(fd)
end subroutine load_boundingbox
! ----------------------------------------------------------------
subroutine random_pv (blb)
type(t_bloubs), intent (out) :: blb
type(t_bloubs), intent (inout) :: blb
blb%px = 4.33 * (rand() - 0.50)
blb%py = 3.33 * (rand() - 0.50)
blb%pz = 4.51 * (rand() - 0.50)
blb%px = 1.35 * (rand() - 0.50)
blb%py = 0.50 + (rand() * 0.50)
blb%pz = 1.90 * (rand() - 0.50)
blb%vx = (rand()) / 2.000
blb%vy = (rand()) / 2.900
blb%vz = (rand()) / 2.000
blb%vx = (rand() - 0.5) / 2.500
blb%vy = (rand() - 0.1) / 4.000
blb%vz = (rand() - 0.5) / 2.500
blb%state = 0
blb%alive = .TRUE.
blb%age = 0
blb%agemax = 500
end subroutine
! ----------------------------------------------------------------
! Load a blbs file into an array of bloubs
subroutine spit_bloubs_to_file (fname, blbarray, towrite)
character(*), intent(in) :: fname
type(t_bloubs), dimension(:) :: blbarray
integer, intent(in) :: towrite
write (0, '(" spiting", (I6), "bloubs to", (A), "file")') &
towrite, trim(fname)
STOP ' : NOT IMPLEMENTED'
end subroutine
! ----------------------------------------------------------------
! Dump an array of bloubs to a blbs file.
!
subroutine slurp_bloubs_file_in_array (infile, blbarray, nbread)
character(*), intent(in) :: infile
type(t_bloubs), dimension(:), intent(out) :: blbarray
integer, intent(out) :: nbread
character(200) :: chaine
integer :: input, errcode, idx
type(t_bloubs) :: bloub
write(0, '(" slurping from file [", (A), "]")') trim(infile)
open( newunit=input, &
file=trim(infile), form='unformatted', &
iostat=errcode, iomsg=chaine, &
action='read', status='old')
if (0 .ne. errcode) then
write(0, '(" errcode ", I8, 2X, A)') errcode, chaine
STOP " : CAN'T OPEN FILE " // trim(infile)
endif
! write(0, '((A, I3))') " slurping from unit ", input
nbread = 0
idx = 1;
do
read (unit=input, iostat=errcode, iomsg=chaine) bloub
if (0 .ne. errcode) then
! may be we got an EOF ?
! write(0, '(" got errcode on read ", (I8,1X,A))') errcode, chaine
exit
endif
nbread = nbread + 1
! print *, bloub%nick, bloub%radius
if (bloub%alive) then
blbarray(idx) = bloub
idx = idx + 1
endif
enddo
close(input) ! no error checking ?
write(0, '(" read ", (I8), " bloubs")') nbread
end subroutine
! ----------------------------------------------------------------
! Display a bloub content to stderr
@ -180,42 +76,37 @@ module bloubspace
end subroutine
! ----------------------------------------------------------------
!
! detection des collisions avec les parois de la boite
! laquelle boite gagnerais beaucoup a etre parametrable.
!
subroutine bound_a_blob (blb)
type(t_bloubs), intent (inout) :: blb
if ( 5.0 .lt. (blb%px + blb%radius)) then
if (5.0 .lt. blb%px) then
blb%vx = -1.0 * blb%vx
blb%px = 5.0
blb%age = blb%age + 1
endif
if (-5.0 .gt. (blb%px + blb%radius)) then
if (-5.0 .gt. blb%px) then
blb%vx = -1.0 * blb%vx
blb%px = -5.0
blb%age = blb%age + 1
endif
! vertical axe
if (-4.99 .gt. (blb%py + blb%radius)) then
if (0.0 .gt. blb%py) then
blb%vy = -1.0 * blb%vy
blb%py = blb%radius
blb%py = 0.0
blb%age = blb%age + 1
endif
if ( 4.99 .lt. (blb%py + blb%radius)) then ! overshoot ?
if (4.99 .lt. blb%py) then !!
blb%vy = -1.0 * blb%vy
blb%age = blb%age + 1
blb%py = 5.0 - blb%radius !!
blb%py = 4.99 !!
endif
if ( 5.0 .lt. (blb%pz + blb%radius)) then
if (5.0 .lt. blb%pz) then
blb%vz = -1.0 * blb%vz
blb%age = blb%age + 1
blb%pz = 5.0
endif
if (-5.0 .gt. (blb%pz + blb%radius)) then
if (-5.0 .gt. blb%pz) then
blb%vz = -1.0 * blb%vz
blb%age = blb%age + 1
blb%pz = -5.0
@ -243,14 +134,7 @@ module bloubspace
subroutine green_soylent (blb)
type(t_bloubs), intent (inout) :: blb
if (blb%age .gt. 18) then
blb%alive = .FALSE.
endif
! this is juste a molly-guard, don't worry
!
if (blb%radius .GT. 2.0) then
if (blb%age .gt. 8) then
blb%alive = .FALSE.
endif
end subroutine

View File

@ -1,39 +1,19 @@
program essai
use bloubspace
use mathstuff
implicit none
type(t_boundingbox) :: bbox
call load_boundingbox("WS/boundinboxes.dat", bbox, "cube ")
print *, bbox
! call test_random(20)
STOP ': BECAUSE JOB IS DONE'
! --------------------------------------------------------------
contains
subroutine test_random(nbre)
integer, intent(in) :: nbre
integer :: foo, bar
integer :: foo
real :: quux
double precision :: somme
call init_random_seed() ! in module 'mathstuff'
call init_random_seed()
somme = 0.0
do foo=1, nbre
do foo=1, 5
quux = rand()
somme = somme + quux
bar = mod(irand(), 7)
print *, foo, quux, somme/foo, bar
print *, foo, quux, somme/foo
enddo
end subroutine test_random
! --------------------------------------------------------------
end program

View File

@ -18,20 +18,22 @@ program genbloubs
call getarg(2, str)
read(str,*) nbbloubs
write (0, '(A,I8,A)') &
write (0, '(A,I6,A)') &
"*** generating ", nbbloubs, " bloubs to "//trim(filename)
open(newunit=idu, file=trim(filename), &
form='unformatted', &
access="sequential", &
! print *, "generating ", nbbloubs, "bloubs to ", filename
open(newunit=idu, file=trim(filename), form='unformatted', &
action='write', status='replace')
do i = 1, nbbloubs
bloub%nick = 'noname '
bloub%num = i + 41
bloub%alive = .TRUE.
call random_pv(bloub)
bloub%radius = 0.035 + (0.03*rand())
bloub%radius = 0.025
bloub%age = 0
write(idu) bloub ! no error control ?

View File

@ -1,45 +0,0 @@
program movebloubs
use bloubspace
implicit none
integer, parameter :: NB_MAX_BLOUBS = 200000
! --------------------------------------------------------------
character(200) :: infile
integer :: errcode, i
integer :: nbgot
type(t_bloubs), dimension(:), allocatable :: bloubs
i = IARGC()
if (i .ne. 1) then
STOP ": BAD ARG ON COMMAND LINE"
endif
call getarg(1, infile)
write (0, '(A)') &
"*** listing bloubs from "//trim(infile)
allocate (bloubs(NB_MAX_BLOUBS), stat=errcode)
if (0 .NE. errcode) then
STOP " : NO ENOUGH MEMORY"
endif
do i = 1, NB_MAX_BLOUBS
bloubs(i)%alive = .FALSE.
enddo
call slurp_bloubs_file_in_array(trim(infile), bloubs, nbgot)
write(0, '(A,I6,1X,A)') "slurped ", nbgot, "bloubs"
do i=1,nbgot
write(6, '(A8, 1X, 1L, 1X, I2, 3X, F8.3, 3X, 3F8.3, 3X, 3F8.3)') &
bloubs(i)%nick, bloubs(i)%alive, &
bloubs(i)%state, &
bloubs(i)%radius, &
bloubs(i)%px, bloubs(i)%py, bloubs(i)%pz, &
bloubs(i)%vx, bloubs(i)%vy, bloubs(i)%vz
enddo
end program
! \o_

View File

@ -5,23 +5,21 @@ module mathstuff
! ----------------------------------------------------------------
! really quick'n'dirty hack
! not really tested yet...
! not working yet...
subroutine init_random_seed()
integer, dimension(3) :: tarray
integer :: t3, foo
integer :: t3
real :: dummy
call itime(tarray)
t3 = 3600*tarray(1) + 60*tarray(2) + tarray(3)
! write(0, '(A,3I3,A,I6)') "sranding: ", tarray, " --> ", t3
write(0, '(A,3I3,A,I6)') "sranding: ", tarray, " --> ", t3
call srand(t3)
! after initializing the random generator engine,
! you MUST use it for initializing the initializer
do foo=1, tarray(1)+5
dummy = rand()
enddo
end subroutine

View File

@ -42,8 +42,6 @@ program movebloubs
STOP " : CAN'T OPEN " // trim(outfile) // "FOR WRITE"
endif
! write(0, '("Units: ", 2I5)') inu, outu
bx = 0.0; by = 0.0; bz = 0.0
compteur = 0
killed = 0
@ -55,20 +53,18 @@ program movebloubs
exit
endif
! moving, morphing and boundingboxing
call move_bloub (bloub, 0.185)
! moving and boundingboxing
call move_bloub (bloub, 0.14)
call bound_a_blob (bloub)
if (bloub%radius .GT. 0.0151) then
bloub%radius = bloub%radius * 0.9970
if (bloub%radius .GT. 0.052) then
bloub%radius = bloub%radius * 0.985
endif
call green_soylent (bloub)
if (.NOT. bloub%alive) then
! write(0, '(A)') " KILL!"
killed = killed + 1
! cycle ! ???
cycle
endif
! calcul du barycentre
bx = bx + dble(bloub%px)
by = by + dble(bloub%py)
@ -87,11 +83,11 @@ program movebloubs
! ok, we have read all the bloubs in the input file
! insert some fancy conditional here
if (compteur .LT. 3000) then
if (compteur .LT. 1600) then
rnd = rand()
write (0, '(A,1X,F9.6)') "try to add bloubs, rnd is", rnd
if (rnd .LT. 0.0450) then
call add_more_bloubs(outu, 24, 0.0990)
write (0, '(A,1X,F5.3)') "try to add bloubs, rnd is", rnd
if (rnd .LT. 0.02) then
call add_more_bloubs(outu, 12, 0.210)
endif
endif
@ -109,23 +105,22 @@ program movebloubs
! --------------------------------------------------------------
contains
subroutine add_more_bloubs(un, nbre, rayon)
subroutine add_more_bloubs(un, nbre, wtf)
integer, intent(in) :: un, nbre
real, intent(in) :: rayon
real, intent(in) :: wtf
type(t_bloubs) :: bloub
integer :: foo, count
integer :: foo
count = nbre+mod(irand(), 7)
write(0, '(A,I4,1X,A)') "adding", count, "bloubs"
write(0, '(A,I4,1X,A)') "adding", nbre, "bloubs"
do foo=1, count
do foo=1, nbre
bloub%nick = 'newbie '
call random_pv(bloub)
bloub%radius = rayon + (0.15*rand())
bloub%radius = wtf
bloub%age = 1
bloub%alive = .TRUE.
bloub%num = mod(irand(), 42)
! call display_bloub (bloub, "new bloub")
write(un) bloub ! no error control ?
enddo

View File

@ -7,15 +7,15 @@
INCFILE="WS/bloubs.inc"
TMPPNG="/dev/shm/bloubs7.png"
POVOPT="+Q9 +a -v -d -W1600 -H1200 -WT2"
DDIR="frames/a"
POVOPT="+Q9 +a -v -d -W1024 -H768 -WT2"
DDIR="frames"
LOGERR="log.error"
# --- put the work file in ramdisk
BLBS_IN="/dev/shm/in.blbs"
BLBS_OUT="/dev/shm/out.blbs"
NBIMG=3000
NBIMG=1800
make all
err=$?
@ -30,9 +30,9 @@ printf "\n#declare NbImg = %d;\n" $NBIMG > WS/nbimg.inc
# first, we have to make a seminal buch of bloubs
# --> this function need to be parametrizable
#
./genbloubs ${BLBS_IN} 3000
./genbloubs ${BLBS_IN} 15
for idx in $(seq 0 $((NBIMG-1)) )
for idx in $(seq 0 $NBIMG)
do
echo "======== run passe $idx ========="
@ -43,41 +43,45 @@ do
if [ 0 -ne $? ] ; then
tail -15 $LOGERR
sleep 30
else
grep "Trace Time" $LOGERR
fi
td=$(date +'%F %R:%S')
hi=$(printf "#%05d" $idx)
count=$(tail -1 "WS/log.nb_bloubs")
count=$(head -1 "WS/log.nb_bloubs")
PNG=$(printf "%s/%05d.png" ${DDIR} $idx)
convert ${TMPPNG} \
-font Courier-Bold \
-pointsize 24 \
-fill Yellow \
-pointsize 16 \
-fill Orange \
-gravity south-east \
-annotate +25+5 "$td" \
-annotate +15+10 "$td" \
-gravity south-west \
-annotate +25+5 "$hi" \
-annotate +15+10 "$hi" \
-fill Yellow \
-pointsize 48 \
-pointsize 32 \
-gravity north-east \
-annotate +25+5 "$count" \
-gravity north-west \
-annotate +25+5 "BloubWorld" \
-annotate +15+10 "$count" \
$PNG
echo $PNG '[done]'
./movebloubs ${BLBS_IN} ${BLBS_OUT}
# ./mergebloubs ${BLBS_OUT} ${BLBS_IN}
mv ${BLBS_OUT} ${BLBS_IN}
echo
sleep 15
done
rm $LOGERR
# XXX convert -delay 10 -resize 50% -colors 192 \
# XXX $DDIR/????[0]*.png foo.gif
nice ./encode.sh

View File

@ -5,14 +5,12 @@
#version 3.7;
global_settings {
ambient_light rgb <0.14, 0.08, 0.08>
ambient_light rgb <0.12, 0.04, 0.04>
assumed_gamma 1.0
}
#include "colors.inc"
#include "WS/nbimg.inc"
#declare NormClock = clock / NbImg;
@ -21,28 +19,21 @@ global_settings {
#include "WS/bloubs.inc"
#fopen LC "WS/log.nb_bloubs" append
#write (LC, " ", Nb_Bloubs, "\n")
#fopen LC "WS/log.nb_bloubs" write
#write (LC, Nb_Bloubs, "\n")
#fclose LC
object {
Bloubs
finish { phong 0.55 specular 0.55 }
finish { phong 0.33 specular 0.95 }
}
object {
union {
plane { <1, 0, 0>, -32 }
plane { <1, 0, 0>, 32 }
plane { <0, 1, 0>, -23 }
plane { <0, 1, 0>, 23 }
plane { <0, 0, 1>, 50 }
plane {
<0, 1, 0>, 0
texture {
pigment { color srgb <0.125, 0.144, 0.111> }
finish { phong 0.18 metallic 0.25 reflection 0.35 }
}
pigment { color srgb <0.133, 0.144, 0.111> }
finish { phong 0.18 metallic 0.55 }
}
}
@ -50,23 +41,23 @@ object {
#declare BH = 5; // H = taille en horizontal
#declare BV = 5; // V = taille en vertical
#declare BR = 0.028;
#declare BR = 0.035;
#declare Une_Borne = object
{
merge {
cylinder { <0, BV, 0>, <0, -BV, 0>, BR }
cylinder { <0, 0.012, 0>, <0, -0.012, 0>, BR*4 }
cylinder { <0, 0, 0>, <0, BV, 0>, BR }
cylinder { <0, 0, 0>, <0, 0.04, 0>, BR*6 }
}
}
#declare Un_Cadre = object
{
merge {
#local Ruc = BR * 0.90;
#local Ruc = BR * 0.666;
cylinder { <-BH, 0, -BH>, <-BH, 0, BH>, Ruc }
cylinder { < BH, 0, -BH>, < BH, 0, BH>, Ruc }
cylinder { < BH, 0, -BH>, <-BH, 0, -BH>, Ruc }
cylinder { < BH, 0, -BH>, < BH, 0, BH>, BR }
cylinder { < BH, 0, -BH>, <-BH, 0, -BH>, BR }
cylinder { < BH, 0, BH>, <-BH, 0, BH>, Ruc }
}
pigment { color Gray40 }
@ -75,9 +66,9 @@ pigment { color Gray40 }
#declare Les_Bornes = object
{
union {
#local E = 0.002;
#local E = 0.02;
object { Un_Cadre translate y*(BV-E) }
object { Un_Cadre translate -y*(BV-E) }
object { Un_Cadre translate y*E }
object { Une_Borne translate <-BH, 0, -BH> pigment { color Blue } }
object { Une_Borne translate < BH, 0, -BH> pigment { color Green } }
@ -109,22 +100,24 @@ union {
}
// ----------------------------------------------------------
light_source { <19, -12, -17> color Gray80 }
light_source { <11, 14, 9> color Gray60 }
// object { Repere scale 2+(1.9*NormClock) translate y*2.5 }
#declare XCAM = 8 - ( 15 * NormClock);
#declare YCAM = 1 + (0.75 * NormClock);
#declare ZCAM = -17.5;
light_source { <9, 22, -17> color Gray80 }
light_source { <11, 19, 9> color Gray60 }
#declare XLAT = Bary_X;
#declare YLAT = Bary_Y;
#declare ZLAT = Bary_Z;
#declare XCAM = 8 - ( 8 * NormClock);
#declare YCAM = 5 + ( 6 * NormClock);
#declare ZCAM = -17;
// object { Repere scale 2.5 translate <XLAT, YLAT, ZLAT> }
/*
#fopen LC "WS/log.camera" append
#write (LC, clock, " ", NormClock, " ", YCAM, "\n")
#fclose LC
*/
camera {
location <XCAM, YCAM, ZCAM>
look_at <XLAT, YLAT, ZLAT>
look_at <0, 1.5, 0>
right x*image_width/image_height
angle 66
angle 42
}

View File

@ -5,22 +5,17 @@
BEGIN {
count = 0
bx = by = bz = 0.0
print "// GENERATED FILE, DON'T TOUCH IT !"
print "#declare Bloubs = object\n{"
print "union\t{"
}
{
age = $5
if (age < 2) color = "Orange"
else if (age > 8) color = "Gray70"
else color = "Sienna"
bx += $1
by += $2
bz += $3
if ($5 > 4) color = "Magenta"
else color = "Cyan"
pigment = "pigment { color " color " }"
printf "\tsphere { <%f, %f, %f>, %f %s }\n", \
printf "\t\tsphere { <%f, %f, %f>, %f %s }\n", \
$1, $2, $3, $4, pigment
count++
}
@ -28,7 +23,4 @@ BEGIN {
END {
print "\t} // end of union\n}\n"
print "#declare Nb_Bloubs = ", count, ";\n"
print "#declare Bary_X = ", bx/count, ";";
print "#declare Bary_Y = ", by/count, ";";
print "#declare Bary_Z = ", bz/count, ";";
}