- import javax.swing.*;
- import java.awt.*;
- import java.awt.image.*;
- import java.awt.color.*;
- import java.awt.event.*;
- class Main extends JPanel
- {
- BufferedImage image; // RYSUJEMY W TYM BUFORZE A WYNIK KOPIUJEMY NA EKRAN
- static Graphics2D gc; // "KONTEKST GRAFICZNY" ZWIĄZANY Z RYSOWANIEM W BUFORZE
- JFrame ramka;
- public Main(int width, int height)
- {
- ramka = new JFrame();
- Dimension d = new Dimension(width, height);
- setPreferredSize(d);
- setSize(d);
- image = new BufferedImage(getWidth(), getHeight(),
- BufferedImage.TYPE_INT_ARGB);
- gc = image.createGraphics();
- gc.setComposite(AlphaComposite.Src);
- this.setBackground(Color.white);
- ramka.add(this);
- ramka.pack();
- ramka.setVisible(true);
- this.gc.setColor(Color.WHITE);
- this.gc.fillRect(0, 0, this.getWidth(), this.getHeight());
- this.gc.setColor(Color.black);
- }
- public static void putPixel(int x, int y)
- {
- gc.drawRect(x, y, 1, 1);
- }
- public static void putPixe2(int x, int y)
- {
- gc.fillRect(x, y, 2, 2);
- }
- public void paintComponent(Graphics g)
- {
- super.paintComponent(g);
- Graphics2D g2 = (Graphics2D) g;
- g2.setComposite(AlphaComposite.Src);
- g2.drawImage(image, null, 0, 0);
- }
- public void Fraktal(Graphics g)
- {
- double xc = 0;
- double yc = 0;
- double size = 4;
- Complex c = new Complex(-0.123,0.745);
- int picturesize = 600;
- int max = 255;
- for (int i = 0; i < picturesize; i++)
- {
- for (int j = 0; j < picturesize; j++)
- {
- System.out.println("jestem");
- double x0 = xc - size/2 + size*i/picturesize;
- double y0 = yc - size/2 + size*j/picturesize;
- Complex z0 = new Complex(x0, y0);
- int gray = max - juli(z0, max,c);
- //int gray = max - mand(z0,max);
- Color color = new Color(gray, (gray+150)%255, (gray+300)%255);
- g.setColor(color);
- g.drawRect(i, picturesize-1-j, 1, 1);
- }
- }
- }
- public int mand(Complex z0, int max)
- {
- Complex z = z0;
- for (int t = 0; t < max; t++)
- {
- if (z.abs() > 2.0) return t;
- z = z.times(z).plus(z0);
- }
- return max;
- }
- public int juli(Complex z0, int max,Complex c)
- {
- Complex z = z0;
- for (int t = 0; t < max; t++)
- {
- if (z.abs() > 2.0) return t;
- z = z.times(z).plus(c);
- }
- return max;
- }
- public static void main(String args[])
- {
- Main m = new Main(600,600);
- m.Fraktal(gc);
- m.repaint();
- }
- }import javax.swing.*;
- import java.awt.*;
- import java.awt.image.*;
- import java.awt.color.*;
- import java.awt.event.*;
- class Main extends JPanel
- {
- BufferedImage image; // RYSUJEMY W TYM BUFORZE A WYNIK KOPIUJEMY NA EKRAN
- static Graphics2D gc; // "KONTEKST GRAFICZNY" ZWIĄZANY Z RYSOWANIEM W BUFORZE
- JFrame ramka;
- public Main(int width, int height)
- {
- ramka = new JFrame();
- Dimension d = new Dimension(width, height);
- setPreferredSize(d);
- setSize(d);
- image = new BufferedImage(getWidth(), getHeight(),
- BufferedImage.TYPE_INT_ARGB);
- gc = image.createGraphics();
- gc.setComposite(AlphaComposite.Src);
- this.setBackground(Color.white);
- ramka.add(this);
- ramka.pack();
- ramka.setVisible(true);
- this.gc.setColor(Color.WHITE);
- this.gc.fillRect(0, 0, this.getWidth(), this.getHeight());
- this.gc.setColor(Color.black);
- }
- public static void putPixel(int x, int y)
- {
- gc.drawRect(x, y, 1, 1);
- }
- public static void putPixe2(int x, int y)
- {
- gc.fillRect(x, y, 2, 2);
- }
- public void paintComponent(Graphics g)
- {
- super.paintComponent(g);
- Graphics2D g2 = (Graphics2D) g;
- g2.setComposite(AlphaComposite.Src);
- g2.drawImage(image, null, 0, 0);
- }
- public void Fraktal(Graphics g)
- {
- double xc = 0;
- double yc = 0;
- double size = 4;
- Complex c = new Complex(-0.123,0.745);
- int picturesize = 600;
- int max = 255;
- for (int i = 0; i < picturesize; i++)
- {
- for (int j = 0; j < picturesize; j++)
- {
- System.out.println("jestem");
- double x0 = xc - size/2 + size*i/picturesize;
- double y0 = yc - size/2 + size*j/picturesize;
- Complex z0 = new Complex(x0, y0);
- int gray = max - juli(z0, max,c);
- //int gray = max - mand(z0,max);
- Color color = new Color(gray, (gray+150)%255, (gray+300)%255);
- g.setColor(color);
- g.drawRect(i, picturesize-1-j, 1, 1);
- }
- }
- }
- public int mand(Complex z0, int max)
- {
- Complex z = z0;
- for (int t = 0; t < max; t++)
- {
- if (z.abs() > 2.0) return t;
- z = z.times(z).plus(z0);
- }
- return max;
- }
- public int juli(Complex z0, int max,Complex c)
- {
- Complex z = z0;
- for (int t = 0; t < max; t++)
- {
- if (z.abs() > 2.0) return t;
- z = z.times(z).plus(c);
- }
- return max;
- }
- public static void main(String args[])
- {
- Main m = new Main(600,600);
- m.Fraktal(gc);
- m.repaint();
- }
- }