first Julia set plotted
This commit is contained in:
parent
2578d3cd6b
commit
a41a630889
4
Fraktalism/.gitignore
vendored
Normal file
4
Fraktalism/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
julia
|
||||
|
||||
*.pgm
|
19
Fraktalism/Makefile
Normal file
19
Fraktalism/Makefile
Normal file
@ -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 $@
|
||||
|
||||
# ---------------------------------------------
|
65
Fraktalism/fraktals.f90
Normal file
65
Fraktalism/fraktals.f90
Normal file
@ -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
|
30
Fraktalism/julia.f90
Normal file
30
Fraktalism/julia.f90
Normal file
@ -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
|
||||
|
||||
!-----------------------------------------------------
|
50
Fraktalism/spitpgm.f90
Normal file
50
Fraktalism/spitpgm.f90
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user