-
Notifications
You must be signed in to change notification settings - Fork 0
Changing Algorithm
Dependencies: WriteLogF.java, DrawAsk.java and FunctionsLol.java
Changing DrawTheLuigi.java is recommended because it is the "main" file. But you can change whatever you want, just make sure you know what you are doing.
Download DrawTheLuigi.java, Customizer.jar.
Remember to delete package libBezierFiveLines; at the top of each file (if the file contains it).
Note: Changing the algorithm will result in hash-mismatched error when running the program, which is not gonna affect the program. Hash-checking is there just to check if there is any modifications to the program.
Depends on what function you want to change or to improve.
// calculate the reflection line by finding the length between perpend line and projected line
private void getPathSlope() {
//calculating the intersection of the path and 400 (y)
dapathx = (395 - toY)/( (supperBigNumber-toY)/((supperBigNumber/find_perpend_tan(toX))-toX)) + toX -4;
//slope line perpendicular to the path
double hps = (supperBigNumber-toY)/(supperBigNumber/((-1)*(400 - toX)/Math.abs(400 - toY)) - toX);
// the slope of the normal line to the tangent line to the curve
double fpt = ( (supperBigNumber-toY)/((supperBigNumber/find_perpend_tan(toX))-toX));
// the slope of the tangent line
double fd = ( (supperBigNumber-toY)/((supperBigNumber/find_derivative(toX))-toX));
// find the x where they intersect
double testx = (fpt*(toX-4) - fd*(395) + 395 - toY)/(fpt - fd);
// find the y where they intersect
double testy = fd*(testx - 395) + 395;
double lengthd = 250;
// calculating the length 400,400 to the normal line
double length = Math.sqrt( Math.pow( (395 - testx), 2) + Math.pow( (395 - testy), 2));
// calculate the x and y of the predicted path of the ball knowing the slope, length between points and the starting coords
// since it gives two x's and y's
if (dapathx >= 400) {
// perpendicular to the curve
coorx[0] = toX - lengthd*Math.sqrt(1/(1+ Math.pow(fpt, 2)));
coory[0] = toY - fpt*lengthd*Math.sqrt(1/(1+ Math.pow(fpt, 2)));
//tangent line
coorx[1] = toX + lengthd*Math.sqrt(1/(1+ Math.pow(fd, 2)));
coory[1] = toY + fd*lengthd*Math.sqrt(1/(1+ Math.pow(fd, 2)));
coorx[2] = toX - lengthd*Math.sqrt(1/(1+ Math.pow(fd, 2)));
coory[2] = toY - fd*lengthd*Math.sqrt(1/(1+ Math.pow(fd, 2)));
// perpendicular to the path of the ball
coorx[3] = toX - lengthd*Math.sqrt(1/(1+ Math.pow(hps, 2)));
coory[3] = toY - hps*lengthd*Math.sqrt(1/(1+ Math.pow(hps, 2)));
coorx[4] = toX + lengthd*Math.sqrt(1/(1+ Math.pow(hps, 2)));
coory[4] = toY + hps*lengthd*Math.sqrt(1/(1+ Math.pow(hps, 2)));
//reflection path
coordsx = testx + length*Math.sqrt(1/(1+ Math.pow(fd, 2)));
coordsy = testy + fd*length*Math.sqrt(1/(1+ Math.pow(fd, 2)));
}
else {
coorx[0] = toX + lengthd*Math.sqrt(1/(1+ Math.pow(fpt, 2)));
coory[0] = toY + fpt*lengthd*Math.sqrt(1/(1+ Math.pow(fpt, 2)));
if ((400 - dapathx <= 6.5) && toX >= 400) {
coorx[0] = toX- lengthd*Math.sqrt(1/(1+ Math.pow(fpt, 2)));
coory[0] = toY - fpt*lengthd*Math.sqrt(1/(1+ Math.pow(fpt, 2)));
}
coorx[1] = toX - lengthd*Math.sqrt(1/(1+ Math.pow(fd, 2)));
coory[1] = toY - fd*lengthd*Math.sqrt(1/(1+ Math.pow(fd, 2)));
coorx[2] = toX + lengthd*Math.sqrt(1/(1+ Math.pow(fd, 2)));
coory[2] = toY + fd*lengthd*Math.sqrt(1/(1+ Math.pow(fd, 2)));
coorx[3] = toX + lengthd*Math.sqrt(1/(1+ Math.pow(hps, 2)));
coory[3] = toY + hps*lengthd*Math.sqrt(1/(1+ Math.pow(hps, 2)));
coorx[4] = toX - lengthd*Math.sqrt(1/(1+ Math.pow(hps, 2)));
coory[4] = toY - hps*lengthd*Math.sqrt(1/(1+ Math.pow(hps, 2)));
coordsx = testx - length*Math.sqrt(1/(1+ Math.pow(fd, 2)));
coordsy = testy - fd*length*Math.sqrt(1/(1+ Math.pow(fd, 2)));
}
} // calculate the slope of the ball and the cue --> find the path of the ball and the cue
private void ballAndStickLogic() {
//if the ball moves
if(ball_go) {
// if the cue touch the ball
if (stick_cy <= 400) {
// ball keeps going until touches the curve
if ((ball_y) <=toY) {
ball_go= false;
ball_kgo = true;
}else {
ball_y -= theSub; theSub+=1;
// equation to find x according to y; shift right 395 and up 395
ball_x = (int) (((ball_y-395)*(400-toX))/Math.abs(400-toY)) + 395;
}
} else {stick_cy -= the_sub; the_sub +=2;}
} else if (ball_kgo) {
// if ball passes 400, stops.
if (ball_y > 400) {
ball_kgo= false;
}
// ball bounce back
ball_y+=theSub; theSub -=1;
//calculate the path using slope-line equation
ball_x = (int) (((ball_y - toY)/((coordsy-toY)/(coordsx - toX))) + toX-7);
}
}public void paint(Graphics g) {
getTopCurve();
drawInformation(g);
drawCurve(g);
drawCoords(g);
drawBall(g);
drawNormalLineAndPathBall(g);
drawPathBounceBack(g);
drawStick(g);
drawTangentLine(g);
initComponents(g);
ballAndStickLogic();
getPathSlope();
writedalog();
} //draw the cue using bunch of lines instead of rect because rect cant rotate
private void drawStick(Graphics g) {
// using the same slope as the path of the ball to the curve
stick_sx = (int) (((stick_cy-395)*(400-toX))/Math.abs(400-toY)) + 395;
g.setColor(Color.ORANGE);
for (int i=0; i< 5; i++)
g.drawLine(stick_sx +i, stick_cy+i, getCueX() + 395+i, stick_cy + 200+i);
}
// draw the curve using lines
private void drawCurve(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
double i =top;
double j =bottom;
g.setColor(Color.MAGENTA);
// generate the curve by generating bunch of line; each line is i and j distance from each other
while (i <bottom && j>top) {
g2.draw( new Line2D.Double( ((-1)*(halfw*(i-400)/h) + 200+(-1)*(w/2-200)) ,(i+=DrawAsk.dis) , ((halfw*(j-400)/h)+400+(400-(200+(-1)*(w/2-200)))) , (j-=DrawAsk.dis) ));
count ++;
}
//count number of lines
g.setColor(Color.BLUE);
g.drawString("Number of Lines: "+count, 10, 45);
count = 0;
}When you click g, instead of starting the ball's animation, the program will turn on debug mode.
from
public void clickg() {
System.out.println("Clicked g");
wl.writeLog("Clicked g");
DrawTheLuigi.ball_go = true;
DrawTheLuigi.timer.start();
}to
public void clickg(){
DrawTheLuigi.toggle_perl = !DrawTheLuigi.toggle_perl;
System.out.println("Clicked d makes debug mode = " + DrawTheLuigi.toggle_perl);
wl.writeLog("Clicked d makes debug mode = "+ DrawTheLuigi.toggle_perl);
}Open Customizier.jar, change the argument to: jar uf PoolSimulator.jar FunctionsLol.class
After changing, run Customizer.jar;
Choose DrawTheLuigi.java and PoolSimulator.jar;
Next steps are essentially knowing java commands (Read more): jar uf and javac , leave as it if you don't understand.