Advertisement
RobertMlv

Untitled

Nov 20th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. package sample;
  2.  
  3. import javafx.scene.canvas.GraphicsContext;
  4. import javafx.scene.paint.Color;
  5.  
  6. import java.util.Random;
  7.  
  8. public class Parallelogram extends Rectangle{
  9.  
  10. private int x2, y2, x3, y3, x4, y4;
  11.  
  12. public Parallelogram(int x, int y, int w, int h) {
  13. super(x, y, w, h);
  14. }
  15.  
  16. public Parallelogram(Random random){
  17. super(random);
  18. setX(random.nextInt(((500 - 1) + 1) + 1));
  19. setY(random.nextInt(((500 - 1) + 1) + 1));
  20. setA(random.nextInt(((100 - 1) + 1) + 1));
  21. setB(random.nextInt(((100 - 1) + 1) + 1));
  22.  
  23. x2 = getX() + getA();
  24. y2 = getY();
  25.  
  26. x3 = getX() + getA() - (int) Math.round(getB()/2.0 * Math.sqrt(3.0));
  27. y3 = getY() + getB();
  28.  
  29. x4 = getX() - (int) Math.round(getB()/2.0 * Math.sqrt(3.0));
  30. y4 = getY() + getB();
  31. }
  32.  
  33. @Override
  34. public void Show(GraphicsContext gc, Color color){
  35. gc.setFill(color);
  36. gc.fillPolygon(new double[]{getX(), getX() + getA(),
  37. getX() + getA() - (int) Math.round(getB()/2.0 * Math.sqrt(3.0)),
  38. getX() - (int) Math.round(getB()/2.0 * Math.sqrt(3.0))},
  39. new double[]{getY(), getY(), getY() + getB(), getY() + getB()}, 4);
  40. }
  41.  
  42. @Override
  43. public void MoveTo(int byX, int byY){
  44. Parallelogram.this.setX(getX() + byX);
  45. Parallelogram.this.setY(getY() + byY);
  46. x2 += byX;
  47. x3 += byX;
  48. x4 += byX;
  49. y2 += byY;
  50. y3 += byY;
  51. y4 += byY;
  52. }
  53.  
  54. public void Turn(GraphicsContext gc){}
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement