From a41a63088964b827ddb2ab5943d90fd07b2b24eb Mon Sep 17 00:00:00 2001 From: tth Date: Sat, 12 Feb 2022 21:00:57 +0100 Subject: [PATCH] first Julia set plotted --- Fraktalism/.gitignore | 4 +++ Fraktalism/Makefile | 19 ++++++++++++ Fraktalism/fraktals.f90 | 65 +++++++++++++++++++++++++++++++++++++++++ Fraktalism/julia.f90 | 30 +++++++++++++++++++ Fraktalism/spitpgm.f90 | 50 +++++++++++++++++++++++++++++++ 5 files changed, 168 insertions(+) create mode 100644 Fraktalism/.gitignore create mode 100644 Fraktalism/Makefile create mode 100644 Fraktalism/fraktals.f90 create mode 100644 Fraktalism/julia.f90 create mode 100644 Fraktalism/spitpgm.f90 diff --git a/Fraktalism/.gitignore b/Fraktalism/.gitignore new file mode 100644 index 0000000..a521500 --- /dev/null +++ b/Fraktalism/.gitignore @@ -0,0 +1,4 @@ + +julia + +*.pgm diff --git a/Fraktalism/Makefile b/Fraktalism/Makefile new file mode 100644 index 0000000..d61be39 --- /dev/null +++ b/Fraktalism/Makefile @@ -0,0 +1,19 @@ + +GFOPT = -Wall -Wextra -time -g + +# --------------------------------------------- + +spitpgm.o: spitpgm.f90 Makefile + gfortran $(GFOPT) -c $< + +fraktals.o: fraktals.f90 Makefile + gfortran $(GFOPT) -c $< + +OBJS = spitpgm.o fraktals.o + +# --------------------------------------------- + +julia: julia.f90 Makefile $(OBJS) + gfortran $(GFOPT) $< $(OBJS) -o $@ + +# --------------------------------------------- diff --git a/Fraktalism/fraktals.f90 b/Fraktalism/fraktals.f90 new file mode 100644 index 0000000..b70dd92 --- /dev/null +++ b/Fraktalism/fraktals.f90 @@ -0,0 +1,65 @@ +module fraktals + implicit none + contains + +!----------------------------------------------------- +subroutine simple_julia(pic, cx, cy) + implicit none + integer, intent(inout), dimension (:,:) :: pic + real, intent(in) :: cx, cy + + integer :: ix, iy, width, height + real :: fx, fy + complex :: Z, C + integer :: iter, maxiter + + width = ubound(pic, 1) + height = ubound(pic, 2) + print *, "image size : ", width, height + ! print *, "constante : ", cx, cy + + maxiter = 500 + C = complex(cx, cy) + print *, "C = ", C + + do ix = 1, width + fx = (float(ix) / (float(width)/4.0) - 2.0) + do iy = 1, height + fy = (float(iy) / (float(height)/4.0) - 2.0) + + ! ------ traitement du pixel + iter = 0 + Z = complex(fx, fy) + do while ( (modulus2(Z) .LT. 4.0) .AND. & + (iter < maxiter) ) + Z = (Z * Z) + C + iter = iter + 1 + + end do + + pic(ix, iy) = iter + + ! print *, ix, iy, " ", fx, fy, " ", iter + + enddo + enddo + +end subroutine +!----------------------------------------------------- +function dist0 (x, y) + implicit none + real, intent(in) :: x, y + real :: dist0 + dist0 = ( x*x + y*y ) +end function + +!----------------------------------------------------- +function modulus2(pt) + implicit none + complex, intent(in) :: pt + real :: modulus2 + modulus2 = real(pt)*real(pt) + imag(pt)*imag(pt) +end +!----------------------------------------------------- + +end module fraktals diff --git a/Fraktalism/julia.f90 b/Fraktalism/julia.f90 new file mode 100644 index 0000000..dc20e2b --- /dev/null +++ b/Fraktalism/julia.f90 @@ -0,0 +1,30 @@ +! +! this is the main programm +! +!----------------------------------------------------- + +program julia + + use spitpgm + use fraktals + + implicit none + + integer, dimension(640, 480) :: picz + integer :: argc + character(200) :: filename + + argc = IARGC() + + if (1 .NE. argc) then + STOP ": JULIA PROGGY NEED A FILENAME" + endif + + call getarg(1, filename) + + call simple_julia(picz, 0.3, 0.6) + call spit_as_pgm(picz, trim(filename)) + +end program + +!----------------------------------------------------- diff --git a/Fraktalism/spitpgm.f90 b/Fraktalism/spitpgm.f90 new file mode 100644 index 0000000..8163c1d --- /dev/null +++ b/Fraktalism/spitpgm.f90 @@ -0,0 +1,50 @@ +module spitpgm + + implicit none + + contains + +!----------------------------------------------------- + +subroutine spit_as_pgm(pic, fname) + + ! implicit none + + integer, intent(in), dimension (:,:) :: pic + character (len=*), intent(in) :: fname + + integer :: io, foo + integer :: ix, iy + real :: fk, fpix + + print *, "> spit_as_pgm to ", fname + + open(newunit=io, file=fname) + write (io, '(a2)') "P2" + write (io, '(i0," ",i0)') size(pic, 1), size(pic, 2) + write (io, '(i0)') 65535 + + foo = MAXVAL(pic) + + if (foo .EQ. 0) then + print *, " IS SOMETHING WRONG GOING TO HAPPEN ?" + do ix = 1, size(pic) + write (io, "(i0)") 0 + enddo + else + fk = float(foo) / 65535.0 + print *, " max pix value", foo, " fk = ", fk + do iy = 1, ubound(pic, 2) + do ix = 1, ubound(pic, 1) + fpix = float(pic(ix, iy)) / fk + write (io, "(i0)") int(fpix) + end do + end do + endif + + close(io) + +end subroutine +!----------------------------------------------------- + +end module spitpgm