Skip to content

Commit 845807e

Browse files
authored
Merge pull request #2 from crazycat9942/wip
1.0.3
2 parents 29219a0 + 1f890fb commit 845807e

File tree

4 files changed

+360
-178
lines changed

4 files changed

+360
-178
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
- Input the functions of the vector field such that the x component is in the "P" box and the y component is in the "Q" box. For example, P = y and Q = 0 would make the x component of the vectors proportional to the y value.
77
- The default colors of the vectors get brighter with increasing magnitude and vice versa. The hue (whether it's red, green, blue, yellow, etc.) is determined by the direction the arrow is pointing.
88
- The P and Q boxes can accept equations that depend on t (time), x (left to right of the screen), and y (down and up on the screen)
9-
- You can zoom in and out of the vector field with a mouse scroll wheel or zooming in on a trackpad. You can also move the center of the vector field by dragging.
9+
- You can zoom in and out of the vector field with a mouse scroll wheel or zooming in on a trackpad. You can also move the center of the vector field by dragging.
10+
- Add a test point using the button in the menu to see the path a point would take forward and backward in time if directed by the vector field
1011

1112
**Creating a complex equation:**
1213
- To increase the detail (at the expense of performance) of the complex equation use the slider in the menu
1314
- Complex equations can be made by putting any function of z (e.g. z<sup>2</sup>) into the "P" box.
1415
- Complex equations take in 2 inputs (the x and y coordinate of a pixel on screen converted to real (x) and imaginary (y) values) and spit out 2 outputs.
15-
- The outputs of the complex equation have an argument (direction) and modulus (magnitude). Similar to the vector fields, the argument controls the hue and the modulus controls the brightness.
16+
- The outputs of the complex equation have an argument (direction) and modulus (magnitude). Similar to the vector fields, the argument controls the hue and the modulus controls the brightness.
17+
- Create contour integrals (integrals of complex functions) with the buttons in the menu for either a freeform, closed freeform, or circular contour. The value of the contour integral is shown in the upper left corner of the screen.
1618

1719
**Mandelbrot set info:**
1820
- This is an extra thing I put in because it looks pretty. To view the set type "zm" into the "P" box. To increase the number of max iterations slide the slider for the mandelbrot set in the menu.

src/Arrow.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public class Arrow
2424
double DQDX;
2525
double DQDY;
2626
double DQDT;
27+
int endX;
28+
int endY;
2729
public Arrow(double initX, double initY, Panel panelInit)
2830
{
2931
panel = panelInit;
@@ -59,8 +61,8 @@ public void update(Graphics g, Panel panel)
5961
curl = panel.getCurl(coordX, coordY);
6062
angle = tempPoint.getY();
6163
panel.vector_to_rgb(this);
62-
int endX = (int)(screenX + 2*length*Math.cos(angle));
63-
int endY = (int)(screenY + 2*length*Math.sin(angle));
64+
endX = (int)(screenX + 2*length*Math.cos(angle));
65+
endY = (int)(screenY + 2*length*Math.sin(angle));
6466
/*int leftX = endX - (int)(length*Math.sin(angle));
6567
int leftY = endY + (int)(length*Math.cos(angle));
6668
int rightX = endX + (int)(length*Math.sin(angle));

src/Main.java

Lines changed: 61 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)