From 920a864b227a31bcbc4c07ec8c441b6b1de90a2e Mon Sep 17 00:00:00 2001 From: tTh Date: Fri, 9 Jun 2023 23:59:54 +0200 Subject: [PATCH] update noisepictures --- GrafAnim/Makefile | 3 +- GrafAnim/noisepic.f90 | 29 +++----------- Modules/noisepictures.f90 | 80 +++++++++++++++++++++++++++++++++++++++ Modules/trnd.f90 | 63 +++++++++++++++++++++++++----- 4 files changed, 141 insertions(+), 34 deletions(-) create mode 100644 Modules/noisepictures.f90 diff --git a/GrafAnim/Makefile b/GrafAnim/Makefile index bb577a0..e333017 100644 --- a/GrafAnim/Makefile +++ b/GrafAnim/Makefile @@ -21,7 +21,8 @@ trigofest: trigofest.f90 Makefile vue3axes.o utils_ga.o utils_ga.o -o $@ noisepic: noisepic.f90 Makefile - gfortran $(GFOPT) $< ../Modules/spitpgm.o ../Modules/pixrgb.o \ + gfortran $(GFOPT) $< ../Modules/spitpgm.o ../Modules/pixrgb.o \ + ../Modules/noisepictures.o \ -o $@ # ---- modules locaux diff --git a/GrafAnim/noisepic.f90 b/GrafAnim/noisepic.f90 index 7f36696..dc791ab 100644 --- a/GrafAnim/noisepic.f90 +++ b/GrafAnim/noisepic.f90 @@ -2,6 +2,7 @@ program noisepic use spitpgm use pixrgb + use noisepictures implicit none integer :: numframe = 0 @@ -17,11 +18,11 @@ program noisepic read (arg, *) numframe endif - ranges(0) = 10 ; ranges(2) = 90 + ranges(1) = 10 ; ranges(2) = 90 ranges(3) = 110 ; ranges(4) = 166 ranges(5) = 205 ; ranges(6) = 230 nbre = 1000+(numframe*555) - call make_noise_color_range_pic(numframe, ranges, nbre) + call make_noise_bw_pic (numframe) contains !-- ------------------------------------------------------------------ @@ -44,33 +45,13 @@ subroutine make_noise_bw_pic (value) foo = irand() print *, 'val=', value, ' rnd=', foo - call plot_noise_bw_pic(pic, 15000) + ! call plot_noise_bw_pic(pic, 15000) + call noise_gray8_pic(pic, 15000) write (filename, "(a, i5.5, a)") "", value, ".pgm" call spit_as_pgm_8(pic, trim(filename)) end subroutine !-- ------------------------------------------------------------------ -subroutine plot_noise_bw_pic(picz, nbre) - implicit none - - integer, dimension(:,:), intent(inout) :: picz - integer, intent(in) :: nbre - - integer :: width, height - integer :: quux, ix, iy, iv - - width = ubound(picz, 1) ; height = ubound(picz, 2) - ! print *, 'sz picz', width, height - - do quux=1, nbre - ix = 1 + mod ( irand(), width ) - iy = 1 + mod ( irand(), height ) - iv = mod ( irand(), 256 ) - ! print *, ix, iy - picz(ix, iy) = iv - enddo -end subroutine - !-- ------------------------------------------------------------------ !- !- Colorized diff --git a/Modules/noisepictures.f90 b/Modules/noisepictures.f90 new file mode 100644 index 0000000..4e1e10e --- /dev/null +++ b/Modules/noisepictures.f90 @@ -0,0 +1,80 @@ +module noisepictures + use pixrgb + implicit none + + contains ! a lot of garbage ? + +!----------------------------------------------------------------------- +subroutine noise_gray8_pic(pict, nbre) + implicit none + integer, dimension(:,:), intent(inout) :: pict + integer, intent(in) :: nbre + integer :: quux, ix, iy, width, height + + width = ubound(pict, 1) ; height = ubound(pict, 2) + + do quux=1, nbre + ix = 1 + mod ( irand(), width ) + iy = 1 + mod ( irand(), height ) + pict(ix, iy) = mod ( irand(), 256 ) + enddo + +end subroutine +!----------------------------------------------------------------------- +subroutine noise_gray16_pic(pict, nbre) + implicit none + integer, dimension(:,:), intent(inout) :: pict + integer, intent(in) :: nbre + integer :: quux, ix, iy, width, height + + width = ubound(pict, 1) ; height = ubound(pict, 2) + + do quux=1, nbre + ix = 1 + mod ( irand(), width ) + iy = 1 + mod ( irand(), height ) + pict(ix, iy) = mod ( irand(), 65536 ) + enddo + +end subroutine +!----------------------------------------------------------------------- +subroutine noise_rgb8_pic(prgb, nbre) + implicit none + type(t_pixrgb), dimension(:,:), intent(inout) :: prgb + integer, intent(in) :: nbre + integer :: quux, ix, iy, width, height + + print *, 'noise_rgb_pic', nbre + + width = ubound(prgb, 1) ; height = ubound(prgb, 2) + + do quux=1, nbre + ix = 1 + mod ( irand(), width ) + iy = 1 + mod ( irand(), height ) + prgb(ix, iy)%r = mod ( irand(), 256 ) + prgb(ix, iy)%g = mod ( irand(), 256 ) + prgb(ix, iy)%b = mod ( irand(), 256 ) + enddo + +end subroutine +!----------------------------------------------------------------------- +subroutine noise_rgb16_pic(prgb, nbre) + implicit none + type(t_pixrgb), dimension(:,:), intent(inout) :: prgb + integer, intent(in) :: nbre + integer :: quux, ix, iy, width, height + + print *, 'noise_rgb_pic', nbre + + width = ubound(prgb, 1) ; height = ubound(prgb, 2) + + do quux=1, nbre + ix = 1 + mod ( irand(), width ) + iy = 1 + mod ( irand(), height ) + prgb(ix, iy)%r = mod ( irand(), 65536 ) + prgb(ix, iy)%g = mod ( irand(), 65536 ) + prgb(ix, iy)%b = mod ( irand(), 65536 ) + enddo + +end subroutine +!----------------------------------------------------------------------- +end module noisepictures \ No newline at end of file diff --git a/Modules/trnd.f90 b/Modules/trnd.f90 index a520c3e..32ad182 100644 --- a/Modules/trnd.f90 +++ b/Modules/trnd.f90 @@ -1,21 +1,66 @@ program essai use mathstuff2 + use pixrgb + use spitpgm + use noisepictures implicit none integer :: foo, bar - real :: quux - double precision :: somme write(0, *) "----------------- essai -------------------" call init_random_seed() ! in module 'mathstuff' - somme = 0.0 - do foo=1, 500 - quux = rand() + rand() - somme = somme + quux - bar = mod(irand(), 7) - print *, foo, quux, somme/foo, bar - enddo + call test_noisepictures_rgb() + call test_noisepictures_gray() + +contains +!----------------------------------------------------------------------- + +subroutine test_noisepictures_rgb () + implicit none + + type(t_pixrgb), allocatable :: pix (:,:) + integer :: nombre + print *, '------ test des noisepictures RGB' + + allocate(pix(800, 600)) + nombre = (800*600)/4 + + call rgbpix_set_to_rgb(pix, 0, 0, 0) + call noise_rgb8_pic(pix, nombre) + call rgbpix_spit_as_pnm_8(pix, 'foo8.pnm') + + call rgbpix_set_to_rgb(pix, 0, 0, 0) + call noise_rgb16_pic(pix, nombre) + call rgbpix_spit_as_pnm_16(pix, 'foo16.pnm') + + deallocate (pix) + +end subroutine +!----------------------------------------------------------------------- +subroutine test_noisepictures_gray () + implicit none + + integer, allocatable :: pix (:,:) + integer :: nombre + print *, '------ test des noisepictures GRAY' + + allocate(pix(800, 600)) + nombre = (800*600)/4 + + pix = 0 + call noise_gray8_pic(pix, nombre) + call spit_as_pgm_8(pix, 'bar8.pgm') + + pix = 0 + call noise_gray16_pic(pix, nombre) + call spit_as_pgm_16(pix, 'bar16.pgm') + + deallocate (pix) + +end subroutine + +!----------------------------------------------------------------------- end program