This is a basic pursuit curve. This is what is looks like:

pursuit

The source code is here:

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JFrame;
import javax.swing.JPanel;
public class TestCurve extends JFrame{
Drew d = new Drew();
public static void main(String args[]) {
new TestCurve();
}
public TestCurve() {
setTitle(“Pursuit curve”);
setSize(600,600);
add(d);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
setVisible(true);
}
}
class Drew extends JPanel {
double maxX, maxY, minMax, xCenter, yCenter;

public void init() {
maxX = getWidth();
maxY = getHeight();
minMax = Math.min(maxX, maxY);
xCenter = maxX/2;
yCenter = maxY/2;
}
public int iX(float x) {
return Math.round(x);
}
public int iY(float y) {
return (int) (maxX – Math.round(y));
}
public Drew() {
setBackground(Color.BLACK);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
init();
//g.setColor(Color.green);
float side = (float) (0.95f * minMax);
float halfSide = side / 2;
float h = (float) (halfSide * Math.sqrt(3));
float q = 0.05f;
float p = 1 – q;

/*float xA = (float) (xCenter – halfSide);
float yA = (float) (xCenter – halfSide);

float xB = (float) (xCenter + halfSide);
float yB = yA;

float xC = (float) (xCenter);
float yC = (float) (yCenter + 0.5f * h);*/

float xA = (float) (1.0f);
float yA = (float) (1.0f);

float xB = (float) (600.0f);
float yB = 1.0f;

float xC = (float) (600.0f);
float yC = (float) (600.0f);

float xD = (float) (1.0f);
float yD = (float) (600.0f);

int iter = 255;
int iter2 = 165;
for(int i = 0; i < 50; i++) {
if(!(iter <= 10) && !(iter2 <= 10)) {
g.setColor(new Color(iter, iter2, 0));
iter -= 12;
iter2 -= 13;
}
else {
g.setColor(new Color(iter, iter2, 0));
}
g.drawLine(iX(xA), iY(yA), iX(xB), iY(yB));
g.drawLine(iX(xB), iY(yB), iX(xC), iY(yC));
g.drawLine(iX(xC), iY(yC), iX(xD), iY(yD));
g.drawLine(iX(xD), iY(yD), iX(xA), iY(yA));

float xA1 = p * xA + q * xB;
float yA1 = p * yA + q * yB;

float xB1 = p * xB + q * xC;
float yB1 = p * yB + q * yC;

float xC1 = p * xC + q * xD;
float yC1 = p * yC + q * yD;

float xD1 = p * xD + q * xA;
float yD1 = p * yD + q * yA;

xA = xA1;
yA = yA1;

xB = xB1;
yB = yB1;

xC = xC1;
yC = yC1;

xD = xD1;
yD = yD1;
}
}
}

 

Advertisements