diff --git a/GrafAnim/README.md b/GrafAnim/README.md index 5c83cf7..4eb6e46 100644 --- a/GrafAnim/README.md +++ b/GrafAnim/README.md @@ -13,6 +13,8 @@ un peu foireux sur les tracés de ligne... Distorsions approximatives de la courbe de Lissajous. +Expériences inspirées par https://bleuje.com/tutorial1/ que c'est d'la balle ! + ## doubledice Ou comment dessiner des gaussiennes. diff --git a/GrafAnim/doubledice.f90 b/GrafAnim/doubledice.f90 index b913143..2277bd6 100644 --- a/GrafAnim/doubledice.f90 +++ b/GrafAnim/doubledice.f90 @@ -1,9 +1,61 @@ program doubledice use usegenplot + use utils_ga + implicit none - call init_genplot("essai.genplot") + integer :: nbarg, numframe + character(len=256) :: arg + integer :: idx, foo, bar, xpos + integer :: buckets(12) - call end_genplot("OK boomer") + nbarg = IARGC() + if (nbarg .GT. 0) then + call GETARG(1, arg) + ! write (0, '(A40, A5)') "argument = ", arg + read (arg, *) numframe + endif + + write(0, '(" ------------- DOUBLE DICE ----------")') + write(0, '(" --> frame number:", I5)') numframe + call init_genplot("dummy.genplot") + call gplt_rect(0, 0, 800, 600) + call gplt_setcol(3) + call gplt_rect(8, 8, 48, 38) + call gplt_setcol(2) + + buckets = 0 + do idx=1, numframe + call jouer_un_tour(buckets, idx) + foo = maxval(buckets) + ! write(0, *) "max value", foo + enddo + + call gplt_line(5, 40, 795, 40) + do bar=1, 12 + xpos = bar*50 + 25 + ! write(0, *) bar, xpos, buckets(bar) + call gplt_rect(xpos, 41, xpos+50, 41+15*buckets(bar)) + enddo + + call end_genplot("OK boomer...") + +contains + +! --------------------------------------------------------- + +subroutine jouer_un_tour(table, compte) + integer,intent(inout) :: table(12) + integer, intent(in) :: compte + + integer :: DA, DB, valeur + + DA = fair_random_dice() + DB = fair_random_dice() + valeur = DA + DB + ! write(0, *) "pass ", compte, " = ", DA, DB, valeur + table(valeur) = table(valeur) + 1 + +end subroutine end program diff --git a/GrafAnim/doublegauss.f90 b/GrafAnim/doublegauss.f90 new file mode 100644 index 0000000..a29b5da --- /dev/null +++ b/GrafAnim/doublegauss.f90 @@ -0,0 +1,33 @@ +program doublegauss + use pixrgb + use utils_ga + implicit none + + type(t_pixrgb), allocatable :: pic(:,:) + character (len=80) :: filename + integer :: pass, iter + integer :: xrnd, yrnd + + write(0, *) "----- making a doublegauss picture ----" + + allocate(pic(320, 240)) + call rgbpix_set_to_zero(pic) + + do pass=0, 99 + do iter=1, 15000 + xrnd = fair_random_gauss(320) + yrnd = fair_random_gauss(240) + ! print *, xrnd, yrnd + pic(xrnd,yrnd)%r = pic(xrnd,yrnd)%r + 1 + pic(xrnd,yrnd)%g = pic(xrnd,yrnd)%g + 2 + pic(xrnd,yrnd)%b = pic(xrnd,yrnd)%b + 3 + end do + + write (filename, "(a, i5.5, a)") "F/DBG/", pass, ".pnm" + print *, trim(filename) + call rgbpix_spit_as_pnm_8 (pic, trim(filename)) + + end do + +end program + diff --git a/GrafAnim/runme.sh b/GrafAnim/runme.sh new file mode 100755 index 0000000..fc9cc4d --- /dev/null +++ b/GrafAnim/runme.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +set -e + +SCRATCH="dummy.genplot" + +make doubledice + +rm -f F/????.tga + +for foo in $(seq 1 250) +do + rm -f dummy.genplot + ./doubledice $foo + filename=$(printf "F/%04d.tga" $foo) + genplot2 -s 640x480 ${SCRATCH} $filename +done + +convert -delay 10 F/????.tga foo.gif diff --git a/GrafAnim/usegenplot.f90 b/GrafAnim/usegenplot.f90 index 1d5760f..73390a1 100644 --- a/GrafAnim/usegenplot.f90 +++ b/GrafAnim/usegenplot.f90 @@ -3,26 +3,40 @@ module usegenplot implicit none integer, private :: color = 4 + integer, private :: iochannel = -1 logical, private :: initialised = .FALSE. + contains ! ------------------------------------------------------------------- subroutine init_genplot(filename) - character(*), intent(in) :: filename + + integer :: errcode + write(0, *) '--> init genplot "', filename, '"' + open(newunit=iochannel, file=filename, iostat=errcode) + write(0, *) 'iochannel', iochannel, 'errcode', errcode + initialised = .TRUE. color = 4 + ! XXX STOP 'ABEND' + end subroutine subroutine end_genplot(message) - character(*), intent(in) :: message + + integer :: errcode + write(0, *) '--> end genplot "', message, '"' initialised = .FALSE. + close(unit=iochannel, iostat=errcode) + write(0, *) 'close errcode', errcode + end subroutine ! ------------------------------------------------------------------- @@ -38,7 +52,7 @@ subroutine do_initialise_once(motif) end subroutine ! ------------------------------------------------------------------- - +!- getter, setter, wtf ? subroutine gplt_setcol(col) integer, intent(in) :: col color = col @@ -55,8 +69,7 @@ subroutine gplt_move(x, y) if (.NOT. initialised) then call do_initialise_once('in gplt_move') endif - - print *, x, y, 0 + write(iochannel, '(3I8)') x, y, 0 end subroutine ! ------------------------------------------------------------------- @@ -66,7 +79,7 @@ subroutine gplt_draw(x, y) if (.NOT. initialised) then call do_initialise_once('in gplt_draw') endif - print *, x, y, color + write(iochannel, '(3I8)') x, y, color end subroutine ! ------------------------------------------------------------------- @@ -78,10 +91,23 @@ subroutine gplt_line(x1, y1, x2, y2) end subroutine ! ------------------------------------------------------------------- +!- +! sx, sy +! +-------------------+ +! | x2,y2 | +! | | +! | | +! | x1,y1 | +! +-------------------+ +! 0,0 subroutine gplt_rect(x1, y1, x2, y2) integer, intent(in) :: x1, y1, x2, y2 + if (.NOT. initialised) then + call do_initialise_once('in gplt_rect') + endif + call gplt_move(x1, y1) call gplt_draw(x2, y1) call gplt_draw(x2, y2) diff --git a/GrafAnim/utils_ga.f90 b/GrafAnim/utils_ga.f90 new file mode 100644 index 0000000..b3f8f38 --- /dev/null +++ b/GrafAnim/utils_ga.f90 @@ -0,0 +1,41 @@ +! ------------------------------------------------------------------- +!- fonctions diverses pour faire des images bizarres +! ------------------------------------------------------------------- + +module utils_ga + use pixrgb + implicit none + + contains + +! ------------------------------------------------------------------- +function fair_random_dice() + integer :: fair_random_dice + + fair_random_dice = 1 + int(rand()*6.0) + +end function +! ------------------------------------------------------------------- +! usage --> see doublegauss.f90 +function fair_random_gauss(hilevel) + integer, intent(in) :: hilevel + integer :: fair_random_gauss + integer :: foo, bar + + foo = int(rand()*hilevel/2) + bar = int(rand()*hilevel/2) + fair_random_gauss = 1 + foo + bar + +end function +! ------------------------------------------------------------------- +! usage --> see doublegauss.f90 +subroutine increment_pixel(pix, k) + type(t_pixrgb), intent(inout) :: pix + integer :: k + + + +end subroutine +! ------------------------------------------------------------------- + +end module diff --git a/GrafAnim/vue3axes.f90 b/GrafAnim/vue3axes.f90 new file mode 100644 index 0000000..514c070 --- /dev/null +++ b/GrafAnim/vue3axes.f90 @@ -0,0 +1,12 @@ +module vue3axes + use pixrgb + implicit none +!------------------------------------------------------------- + + +!------------------------------------------------------------- +!- +!- ouf, c'est fini +!- +end module +