Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.image.BufferedImage;
- public class JuliaDrawer extends FractalDrawer {
- double pointX;
- double pointY;
- public JuliaDrawer(double[] imageDetails, Dimension size, Graphics g, double x, double y) {
- super(imageDetails, size, g);
- pointX = x;
- pointY = y;
- calculate();
- }
- public void setXY(double x, double y){
- pointX = x;
- pointY = y;
- }
- @Override
- public void draw() {
- g.drawImage (bufImg, 0, 0, null);
- }
- public void loadJulia(BufferedImage faveBuff){
- g.drawImage (faveBuff, 0, 0, null);;
- }
- public void calculate() {
- int row = 0;
- int col = 0;
- int pixPoint = 0;
- int panelWidthInt = (int) panelWidth;
- int panelHeightInt = (int) panelHeight;
- int pixNum = (panelWidthInt * panelHeightInt);
- int [] pixels = new int[pixNum];
- Complex z = new Complex(0,0);
- Complex c = new Complex(pointX, pointY);
- for(row = 0; row < panelHeightInt; row++){
- double y = yMaxVal - (row * yScale);
- for(col = 0; col < panelWidthInt; col++){
- pixPoint = col + (row * panelWidthInt);
- double x = xMinVal + (col * xScale);
- z.setReal(x);
- z.setImag(y);
- int iter = 0;
- boolean escaped = false;
- while(iter <= maxIter && !escaped){
- z.square();
- z.add(c);
- iter++;
- if(z.modulusSquared() < 4){
- escaped = false;
- }else{
- escaped = true;
- }
- }
- if(!escaped){
- pixels[pixPoint] = (0|0|0);
- }
- else{
- double smoothCol = iter + 1 - Math.log((Math.log(z.modulus())))/Math.log(2);
- smoothCol = smoothCol / maxIter;
- int buffPixel = Color.HSBtoRGB((float) (0.68f- smoothCol) ,0.9f,1.05f);
- pixels[pixPoint] = buffPixel;
- }
- }
- }
- bufImg = new BufferedImage (panelWidthInt, panelHeightInt, BufferedImage.TYPE_INT_RGB);
- bufImg.setRGB (0,0,panelWidthInt, panelHeightInt,pixels,0,panelWidthInt);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment