Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package hr.tel.fer.kp.lab3;
- import java.awt.*;
- public class GraphicThread implements Runnable {
- private static int MAX = 64;
- private double viewX;
- private double viewY;
- private double zoom;
- private Graphics g;
- private Dimension size;
- private int startY, startX, endY, endX;
- public GraphicThread(Graphics g, Dimension size, int startY, int startX, int endY, int endX, double zoom, double viewX, double viewY){
- this.g = g;
- this.startX = startX;
- this.startY = startY;
- this.endX = endX;
- this.endY = endY;
- this.zoom = zoom;
- this.viewX = viewX;
- this.viewY = viewY;
- this.size = size;
- }
- @Override
- public void run() {
- for (int y = startY; y < endY; y++) {
- for (int x = startX; x < endX; x++) {
- double r = zoom / Math.min(size.width, size.height);
- double dx = 2.5 * (x * r + viewX) - 2.0;
- double dy = 1.25 - 2.5 * (y * r + viewY);
- int value = mandel(dx, dy);
- value = value * 255 / MAX;
- synchronized(g){
- g.setColor(new Color(value, value, value));
- g.drawLine(x, y, x, y);
- }
- }
- }
- }
- private int mandel(double px, double py) {
- int value = 0;
- double zx = 0.0;
- double zy = 0.0;
- double zx2 = 0.0;
- double zy2 = 0.0;
- while (value < MAX && zx2 + zy2 < 4.0) {
- zy = 2.0 * zx * zy + py;
- zx = zx2 - zy2 + px;
- zx2 = zx * zx;
- zy2 = zy * zy;
- value++;
- }
- return value == MAX ? 0 : MAX - value;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement