Task: Julia set





Java: import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;

public class JuliaSet extends JPanel {
    private static final int MAX_ITERATIONS = 300;
    private static final double ZOOM = 1;
    private static final double CX = -0.7;
    private static final double CY = 0.27015;
    private static final double MOVE_X = 0;
    private static final double MOVE_Y = 0;

    public JuliaSet() {
        setPreferredSize(new Dimension(800, 600));
        setBackground(Color.white);
    }

    void drawJuliaSet(Graphics2D g) {
        int w = getWidth();
        int h = getHeight();
        BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);

        for (int x = 0; x < w; x++) {
            for (int y = 0; y < h; y++) {
                double zx = 1.5 * (x - w / 2) / (0.5 * ZOOM * w) + MOVE_X;
                double zy = (y - h / 2) / (0.5 * ZOOM * h) + MOVE_Y;
                float i = MAX_ITERATIONS;
                while (zx * zx + zy * zy < 4 && i > 0) {
                    double tmp = zx * zx - zy * zy + CX;
                    zy = 2.0 * zx * zy + CY;
                    zx = tmp;
                    i--;
                }
                int c = Color.HSBtoRGB((MAX_ITERATIONS / i) % 1, 1, i > 0 ? 1 : 0);
                image.setRGB(x, y, c);
            }
        }
        g.drawImage(image, 0, 0, null);
    }

    @Override
    public void paintComponent(Graphics gg) {
        super.paintComponent(gg);
        Graphics2D g = (Graphics2D) gg;
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
        drawJuliaSet(g);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setTitle("Julia Set");
            f.setResizable(false);
            f.add(new JuliaSet(), BorderLayout.CENTER);
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
        });
    }
}






Fortran: C     ==================================================================
      PROGRAM JULIA
C     ------------------------------------------------------------------
      INTEGER    NMAP,NROW,NCOL
      COMPLEX*16 C
      PARAMETER(NMAP=11,NROW=40,NCOL=100,C=(-0.798D0,0.1618D0))
      CHARACTER*1 MAP(NMAP)
      DATA MAP /' ','.',':','-','=','+','*','#','%','$','@'/
      REAL*8      X(NCOL), Y(NROW)
      INTEGER     IR, IC, I, J, MX
      CHARACTER*1 CLR, LINE(NCOL)
      COMPLEX*16  Z

      MX = (NMAP-1)*5
      CALL LINSPACE( NCOL, X, -1.5D0,  1.5D0 )
      CALL LINSPACE( NROW, Y,  1.0D0, -1.0D0 )

      WRITE (*,*) C

      DO 110 IR=1,NROW
         DO 100 IC=1,NCOL
            Z = DCMPLX( X(IC), Y(IR) )
            I  = 1
            CLR = ' '
 10         CONTINUE
            Z = Z*Z + C
            IF ( 2.0D0 .LT. CDABS(Z) ) THEN
               CLR = MAP(MOD(I,NMAP-1)+1)
               GOTO 20
            END IF
            I = I + 1
            IF ( MX .GT. I ) GOTO 10
 20         CONTINUE
            LINE(IC) = CLR
 100     CONTINUE
         WRITE(*,*) (LINE(J),J=1,NCOL)
 110  CONTINUE
      
      STOP
      END

C     ==================================================================
      SUBROUTINE LINSPACE( N, A, S, F )
C     ------------------------------------------------------------------
      INTEGER N
      REAL*8  N A(N), S, F
      INTEGER I
      REAL*8  D
      D = (F-S)/DBLE(N-1)
      A(1) = S
      DO 10 I=2,N
         A(I) = A(I-1) + D
 10   CONTINUE
      RETURN
      END