first bloubspace run done

This commit is contained in:
tth 2022-02-06 23:45:08 +01:00
parent 91f7a07990
commit c0c031f21a
12 changed files with 432 additions and 0 deletions

7
.gitignore vendored
View File

@ -2,6 +2,13 @@
# Prerequisites
*.d
# added by tTh
# ---
# Compiled Object files
*.slo
*.lo

10
BloubWorld/.gitignore vendored Normal file
View File

@ -0,0 +1,10 @@
bloubs.inc
*.gif
*.blbs
frames/*
exportbloubs
genbloubs
movebloubs

33
BloubWorld/Makefile Normal file
View File

@ -0,0 +1,33 @@
all: genbloubs movebloubs exportbloubs
GFOPT = -Wall -Wextra -g -time
OBJS = bloubspace.o povstuff.o
# ------------------------------------------------------------
initial.blbs: genbloubs Makefile
./genbloubs $@ 1000
# ------------------------------------------------------------
bloubspace.o: bloubspace.f90 Makefile
gfortran $(GFOPT) -c $<
povstuff.o: povstuff.f90 Makefile
gfortran $(GFOPT) -c $<
# ------------------------------------------------------------
genbloubs: genbloubs.f90 Makefile $(OBJS)
gfortran $(GFOPT) $(OBJS) $< -o $@
movebloubs: movebloubs.f90 Makefile bloubspace.o
gfortran $(GFOPT) $(OBJS) $< -o $@
exportbloubs: exportbloubs.f90 Makefile bloubspace.o
gfortran $(GFOPT) $(OBJS) $< -o $@
# ------------------------------------------------------------

29
BloubWorld/README.md Normal file
View File

@ -0,0 +1,29 @@
# BloubWorld
C'est quoi ?
Le BloubWorld (que l'on appelle aussi BloubSpace) est un espace borné
dans lequel se déplcent des **bloubs**, une sorte de particule
munie de certaines propriétés. Lesquelles évoluent en fonction du temps.
## Description d'un bloubs
```
type t_bloubs
character(8) :: nick
integer :: num
real :: px, py, pz
real :: vx, vy, vz
real :: radius
integer :: seq
end type t_bloubs
```
C'est simple, en fait. Le plus compliqué, c'est de savoir quoi en faire.
## Comment ça fonctionne ?
Pas trop mal pour un premier jet. Il suffit de lire
le script `runme.sh` pour avoir une idée de l'enchainement
des opérations.

54
BloubWorld/bloubspace.f90 Normal file
View File

@ -0,0 +1,54 @@
!
! fonctions de base de gestion des bloubs
!
module bloubspace
implicit none
! ----------------------------------------------------------------
type t_bloubs
character(8) :: nick
logical :: alive
integer :: num
real :: px, py, pz
real :: vx, vy, vz
real :: radius
integer :: seq
end type t_bloubs
contains ! -----------------------------------------
subroutine random_pv (blb)
type(t_bloubs), intent (inout) :: blb
blb%px = rand() - 0.50
blb%py = rand() * 0.25
blb%pz = rand() - 0.50
blb%vx = (rand() - 0.5) / 5.000
blb%vy = (rand() - 0.5) / 5.000
blb%vz = (rand() - 0.5) / 5.000
end subroutine
! ----------------------------------------------------------------
subroutine move_bloub (blb, coef)
type(t_bloubs), intent (inout) :: blb
real, intent (in) :: coef
blb%px = blb%px + (blb%vx * coef)
blb%py = blb%py + (blb%vy * coef)
blb%pz = blb%pz + (blb%vz * coef)
blb%seq = blb%seq + 1
end subroutine
! ----------------------------------------------------------------
end module

View File

@ -0,0 +1,41 @@
program genbloubs
use bloubspace
implicit none
character(200) :: filename
integer, parameter :: idu = 33
integer :: i, compte, errcode
type(t_bloubs) :: bloub
! parsing command line
i = IARGC()
if (1 .ne. i) then
STOP ' :BAD COMMAND LINE'
endif
call getarg(1, filename)
write (0, '(A, A)') "*** exporting from ", trim(filename)
open(unit=idu, file=trim(filename), form='unformatted', &
iostat=errcode, &
action='read', status='old')
if (0 .ne. errcode) then
! print *, 'errcode ', errcode
STOP " : CAN'T OPEN FILE " // trim(filename)
endif
compte=0
do
read (unit=idu, iostat=errcode) bloub
if (0 .ne. errcode) then
exit
endif
print *, bloub%px, bloub%py, bloub%pz, bloub%radius
compte = compte + 1
enddo
close(idu)
end program

43
BloubWorld/genbloubs.f90 Normal file
View File

@ -0,0 +1,43 @@
program genbloubs
use bloubspace
integer :: nbbloubs
integer :: i
character(200) :: filename
character(30) :: str
type(t_bloubs) :: bloub
integer, parameter :: idu = 33
i = IARGC()
if (i .ne. 2) then
STOP ": BAD ARGS ON COMMAND LINE"
endif
call getarg(1, filename)
call getarg(2, str)
read(str,*) nbbloubs
write (0, '(A,I6,A)') &
"*** generating ", nbbloubs, " bloubs to "//trim(filename)
! print *, "generating ", nbbloubs, "bloubs to ", filename
open(unit=idu, file=trim(filename), form='unformatted', &
action='write', status='replace')
do i = 1, nbbloubs
bloub%nick = 'noname '
bloub%alive = .TRUE.
call random_pv(bloub)
bloub%radius = 0.009999
bloub%seq = 0
write(idu) bloub ! no error control ?
end do
close(unit=idu)
end program

68
BloubWorld/movebloubs.f90 Normal file
View File

@ -0,0 +1,68 @@
program movebloubs
use bloubspace
use povstuff
implicit none
character(200) :: infile, outfile
integer :: inu, outu, errcode, i
type(t_bloubs) :: bloub
double precision :: bx, by, bz
i = IARGC()
if (i .ne. 2) then
STOP ": BAD ARGS ON COMMAND LINE"
endif
call getarg(1, infile)
call getarg(2, outfile)
inu = 42 ; outu = 51
write (0, '(A)') &
"*** moving bloubs from "//trim(infile)//" to "//trim(outfile)
open(unit=inu, file=trim(infile), form='unformatted', &
iostat=errcode, &
action='read', status='old')
if (0 .ne. errcode) then
STOP " : CAN'T OPEN FILE " // trim(infile)
endif
open(unit=outu, file=trim(outfile), form='unformatted', &
iostat=errcode, &
action='write', status='replace')
if (0 .ne. errcode) then
STOP " : CAN'T WRITE TO " // trim(outfile)
endif
bx = 0.0; by = 0.0; bz = 0.0
do
read (unit=inu, iostat=errcode) bloub
if (0 .ne. errcode) then
exit
endif
call move_bloub (bloub, 0.333)
bx = bx + bloub%px
by = by + bloub%py
bz = bz + bloub%pz
! boundingbox action
if (0.0 .gt. bloub%py) then
bloub%vy = -1.0 * bloub%vy
bloub%py = 0.0
endif
write(outu) bloub ! no error control ?
enddo
close(inu) ; close(outu)
end program

27
BloubWorld/povstuff.f90 Normal file
View File

@ -0,0 +1,27 @@
module povstuff
implicit none
! ----------------------------------------------------------------
type t_boundb
real :: BBminX, BBmaxX, BBminY, BBmaxY, BBminZ, BBmaxZ
integer :: id
end type
contains ! -----------------------------------------
subroutine show_bbox( bbox )
type (t_boundb), intent(in) :: bbox
print *, bbox%bbminx, bbox%bbminy, bbox%bbminz
print *, bbox%bbmaxx, bbox%bbmaxy, bbox%bbmaxz
end subroutine
! ----------------------------------------------------------------
end module

58
BloubWorld/runme.sh Executable file
View File

@ -0,0 +1,58 @@
#!/bin/bash
#
# how to run this mess in a batch style
#
INCFILE="bloubs.inc"
TMPPNG="/dev/shm/bloubs7.png"
POVOPT="+Q9 -v -d -W640 -H480"
DDIR="frames"
make all
err=$?
if [ $err -ne 0 ] ; then
echo 'make error = ' $err
exit 1
fi
#
# first, we have to make a seminal buch of bloubs
# --> this function need to be paraletrizable
#
./genbloubs in.blbs 10000
for idx in $(seq 0 40)
do
echo "======== run passe $idx ========="
./exportbloubs in.blbs | awk -f toinc.awk > $INCFILE
povray -Iscene.pov -K${idx} -O${TMPPNG} ${POVOPT} 2> toto
grep "Trace Tim" toto
txt=$(date +'%F %R:%S')
PNG=$(printf "%s/%05d.png" ${DDIR} $idx)
echo $PNG $txt
convert ${TMPPNG} \
-font fixed \
-pointsize 12 \
-fill orange \
-gravity south-east \
-annotate +10+10 "$txt" \
$PNG
./movebloubs in.blbs out.blbs
cp out.blbs in.blbs
sleep 2 ; echo
done
rm toto
convert -delay 10 -colors 32 $DDIR/*.png foo.gif

40
BloubWorld/scene.pov Normal file
View File

@ -0,0 +1,40 @@
/*
* BLOUBSWORLD
* new Sun 06 Feb 2022 01:33:39 PM CET, rue Ernest Renan
*/
#version 3.7;
global_settings {
ambient_light rgb <0.02, 0.02, 0.09>
assumed_gamma 1.0
}
#include "colors.inc"
#include "bloubs.inc"
object {
Bloubs
texture {
pigment { color Gray50 }
finish { phong 0.58 metallic 0.45 }
}
}
plane {
<0, 1, 0>, 0
texture {
pigment { color Gray10 }
finish { phong 0.58 metallic 0.45 }
}
}
light_source { <4, 1, -9> color White }
light_source { <4, 9, 9> color White }
camera {
location <1, 3, -5>
look_at <0, 0, 0>
right x*image_width/image_height
angle 48
}

22
BloubWorld/toinc.awk Normal file
View File

@ -0,0 +1,22 @@
#
# this code is (C) 2022 tTh
#
BEGIN {
count = 0
print "// GENERATED FILE, DON'T TOUCH IT !"
print "#declare Bloubs = object\n{"
print "union\t{"
}
{
printf "\t\tsphere { <%f, %f, %f>, %f }\n", \
$1, $2, $3, $4
count++
}
END {
print "\t} // end of union\n}\n"
print "#declare Nb_Bloubs = ", count, ";\n"
}