Reputation: 105
Currently, I've created a code that would generate the coordinates of a quadrilateral and inserted them into a list to generate the corners of the quad to make a polygon
I've currently generated the following code and the system.out.prints lets me know what coordinates were generated I've plotted them on a graph and I was satisfied with the plot that it generated
HOwever this is the code:
package endOfYearGame;
import java.awt.Color;
import java.awt.Graphics2D;
public class arrow {
double theta;
int x;
int y;
int horizontal = 70;
int vertical = 10;
int originalX = 50;
int originalY = 800-50;
public arrow() {
this.theta = Math.PI/4.0;
this.x = originalX;
this.y = originalY;
}
public void rotateRight() {
this.theta = this.theta - 0.1;
}
public void rotateLeft() {
this.theta = this.theta + 0.1;
}
public void drawArrow(Graphics2D win) {
win.setColor(Color.BLACK);
//x's of the rectangular arrows
int bottomRightX = (int)(this.x+horizontal*Math.cos(theta));
int topRightX = (int)(bottomRightX-Math.sin(this.theta)*vertical);
int topLeftX = (int)(this.x-Math.sin(this.theta)*vertical);
//y's of the rectangular arrows
int bottomRightY = (int)(this.y-Math.sin(this.theta)*horizontal);
int topRightY = (int)(bottomRightY-vertical*Math.cos(this.theta)) ;
int topLeftY = (int)(this.y-vertical/Math.cos(this.theta));
int Xs[] = {this.x, bottomRightX, topRightX, topLeftX};
int Ys[] = {this.y, bottomRightY, topRightY, topLeftY};
int Xss[] = {this.x, bottomRightX, topRightX, topLeftX,this.x};
int Yss[] = {this.y, bottomRightY, topRightY, topLeftY,this.y};
win.setColor(Color.RED);
win.drawPolygon(Xs,Ys,4);
win.fillPolygon(Xss, Yss, 4);
System.out.println("0000 bottomrightx = "+bottomRightX);
System.out.println("toprightx= "+topRightX);
System.out.println("topleftx= " + topLeftX);
System.out.println("bottomleftx = "+this.x);
System.out.println("bottomrighty = "+ bottomRightY );
System.out.println("toprighty = "+topRightY);
System.out.println("toplefty = "+topLeftY);
System.out.println("bottomlefty = "+this.y);
}
}
But it generates no polygon at all!
I was wondering if there was something wrong with this?
Upvotes: 0
Views: 55
Reputation: 123410
Your code never invokes drawArrow
. If it did, it would draw the polygon. Here's the output:
0000 bottomrightx = 99
toprightx= 91
topleftx= 42
bottomleftx = 50
bottomrighty = 700
toprighty = 692
toplefty = 735
bottomlefty = 750
And here's the result in a 1024x768 window:
Upvotes: 1