@@ -75,6 +75,7 @@ class Panel extends JPanel {
7575 boolean zoomChanged = true ;
7676 boolean panChanged = true ;
7777 double mandelbrotDetail ;
78+ boolean userPressed = false ;
7879 Panel ()
7980 {
8081 parser = new JEP ();
@@ -136,16 +137,25 @@ public void mouseWheelMoved(MouseWheelEvent e) {
136137 });
137138 this .addMouseListener (new MouseAdapter ()
138139 {
140+ @ Override
141+ public void mouseReleased (MouseEvent e ) {
142+ super .mouseReleased (e );
143+ userPressed = false ;
144+ }
145+
139146 public void mousePressed (MouseEvent m )
140147 {
141- lastPoint = m .getPoint ();
148+ if (!menu .contourFreeformActive && !menu .contourFreeformClosedActive ) {
149+ lastPoint = m .getPoint ();
150+ }
151+ userPressed = true ;
142152 }
143153 });
144154 this .addMouseMotionListener (new MouseAdapter ()
145155 {//panning
146156 public void mouseDragged (MouseEvent m )//when mouse dragged
147157 {
148- if (lastPoint != null )//if lastpoint is defined
158+ if (lastPoint != null && ! menu . contourFreeformActive && ! menu . contourFreeformClosedActive )//if lastpoint is defined
149159 {
150160 panChanged = true ;
151161 lastCenter = new Point2D .Double (centerX , centerY );
@@ -367,36 +377,54 @@ public void run() {
367377 }
368378 else
369379 {
380+ if (!zoomChanged && !panChanged && tempImage != null ) {
381+ g .drawImage (tempImage , 0 , 0 , null );
382+ }
383+ else
384+ {
370385 parser .addVariable ("t" , time );
371- double [][][] colorData = new double [numIStep ][numJStep ][5 ];
372386 colors = new int [1600 ][900 ];
387+ Complex m ;
388+ double argument ;
389+ double modulus ;
390+ Complex R ;
391+ Color tempColor ;
373392 for (int i = 0 ; i < numIStep ; i ++) {
374393 for (int j = 0 ; j < numJStep ; j ++) {
375- Complex m = new Complex (screenToCoordsX (i * iStep ), screenToCoordsY (j * jStep ));
394+ m = new Complex (screenToCoordsX (i * iStep ), screenToCoordsY (j * jStep ));
376395 parser .addComplexVariable ("z" , m .re (), m .im ());
377396 parser .parseExpression (menu .P .getText ());
378- Complex R = parser .getComplexValue ();
397+ R = parser .getComplexValue ();
379398 //System.out.println(R);
380- double argument = Math .toDegrees (Math .atan2 (R .im (), R .re ()));
399+ argument = Math .toDegrees (Math .atan2 (R .im (), R .re ()));
381400 if (argument < 0f ) {
382401 argument = argument + 360f ;
383402 }
384- double modulus = Math .sqrt (Math .pow (R .re (), 2 ) + Math .pow (R .im (), 2 ));
403+ modulus = Math .sqrt (Math .pow (R .re (), 2 ) + Math .pow (R .im (), 2 ));
385404 modulus = (float ) Math .pow ((1f - Math .exp (-0.02f * modulus )), 0.3 );
386- Color tempColor = hslToRGB ((float ) argument , (float ) modulus , (float ) modulus );
387- colorData [i ][j ] = new double []{tempColor .getRed (), tempColor .getGreen (), tempColor .getBlue (), m .re (), m .im ()};
405+ tempColor = hslToRGB ((float ) argument , (float ) modulus , (float ) modulus );
406+ int rgbval = tempColor .getRGB ();
407+ for (int k = i *iStep ; k < (i +1 )*iStep ; k ++)
408+ {
409+ for (int l = j *jStep ; l < (j +1 )*jStep ; l ++)
410+ {
411+ colors [k ][l ] = rgbval ;
412+ }
413+ }
388414 /*for(int k = i*iStep; k < (i + 1)*iStep; k++)
389415 {
390416 for(int l = j*jStep; l < (j + 1)*jStep; l++)
391417 {
392418 colors[(k * iStep) - 1][(l * jStep)] = tempColor.getRGB();
393419 }
394420 }*/
395- g .setColor (tempColor );
396- g .fillRect (i *iStep , j *jStep , (i + 1 ) * iStep , (j + 1 ) * jStep );
421+ //g.setColor(tempColor);
422+ //g.fillRect(i * iStep, j * jStep, (i + 1) * iStep, (j + 1) * jStep);
423+ }
397424 }
398425 }
399- //tempImage = createImage(colors);
426+ tempImage = createImage (colors );
427+ g .drawImage (tempImage , 0 , 0 , null );
400428 //g.drawImage(tempImage, 0, 0, null);
401429 /*for(int i = 0; i < numIStep; i++)
402430 {
@@ -860,11 +888,27 @@ public Color mandelbrotColor(Complex z)
860888 double g = color1[1] + (n - Math.floor(n)) * (color2[1] - color1[1]);
861889 double b = color1[2] + (n - Math.floor(n)) * (color2[2] - color1[2]);*/
862890 //double n = 0.99;
863- double h = (Math .log (i + 20 ) * 100 ) % 360 ;
891+ double h = (Math .log (i + 15 ) * 100 ) % 360 ;
864892 //double c_ = 100;
865893 //double l = 100;
866894 //return hslToRGB((float)Math.pow(((double)i/maxIter)*360, 1.5) % 360f, 0.5f, ((float)(i/maxIter)));
867- return HCLToRGB (h , 100 , 1.5 );
895+ return HCLToRGB (h , 100 , 2 );
896+ }
897+ public int mandelbrotDiverge (Complex z ) {//gives number of iterations before the mandelbrot thing diverges (goes past 2 in magnitude)
898+ int i = 0 ;
899+ double xsqr = 0 ;
900+ double ysqr = 0 ;
901+ double x = z .re ();
902+ double y = z .im ();
903+ int maxIter = (int ) mandelbrotDetail ;
904+ while (i < maxIter && xsqr + ysqr < 4 )
905+ {
906+ xsqr = z .re () * z .re ();
907+ ysqr = z .im () * z .im ();
908+ z = new Complex (xsqr - ysqr + x , 2 * z .re () * z .im () + y );
909+ i ++;
910+ }
911+ return i ;
868912 }
869913 public Complex mandelbrot (Complex z )
870914 {
@@ -915,8 +959,8 @@ protected void paintComponent(Graphics gInit) {
915959 else
916960 {
917961 userMouse = MouseInfo .getPointerInfo ().getLocation ();
918- menu .update (g );
919962 colorComplex ();
963+ menu .update (g );
920964 }
921965 axes .update (g );
922966 /*if(!Double.isNaN(forceAtMouse.getX()))
@@ -944,8 +988,8 @@ public void actionPerformed(ActionEvent e) {
944988 }
945989 });
946990 timer .setRepeats (true );
947- // Aprox. 60 FPS
948- timer .setDelay (17 );
991+ // Aprox. 60 FPS at 17
992+ timer .setDelay (1 );
949993 timer .start ();
950994 }
951995 @ Override
0 commit comments