Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sample;
- import javafx.scene.canvas.GraphicsContext;
- import javafx.scene.paint.Color;
- import java.util.Random;
- public class Parallelogram extends Rectangle{
- private int x2, y2, x3, y3, x4, y4;
- public Parallelogram(int x, int y, int w, int h) {
- super(x, y, w, h);
- }
- public Parallelogram(Random random){
- super(random);
- setX(random.nextInt(((500 - 1) + 1) + 1));
- setY(random.nextInt(((500 - 1) + 1) + 1));
- setA(random.nextInt(((100 - 1) + 1) + 1));
- setB(random.nextInt(((100 - 1) + 1) + 1));
- x2 = getX() + getA();
- y2 = getY();
- x3 = getX() + getA() - (int) Math.round(getB()/2.0 * Math.sqrt(3.0));
- y3 = getY() + getB();
- x4 = getX() - (int) Math.round(getB()/2.0 * Math.sqrt(3.0));
- y4 = getY() + getB();
- }
- @Override
- public void Show(GraphicsContext gc, Color color){
- gc.setFill(color);
- gc.fillPolygon(new double[]{getX(), getX() + getA(),
- getX() + getA() - (int) Math.round(getB()/2.0 * Math.sqrt(3.0)),
- getX() - (int) Math.round(getB()/2.0 * Math.sqrt(3.0))},
- new double[]{getY(), getY(), getY() + getB(), getY() + getB()}, 4);
- }
- @Override
- public void MoveTo(int byX, int byY){
- Parallelogram.this.setX(getX() + byX);
- Parallelogram.this.setY(getY() + byY);
- x2 += byX;
- x3 += byX;
- x4 += byX;
- y2 += byY;
- y3 += byY;
- y4 += byY;
- }
- public void Turn(GraphicsContext gc){}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement