digrach

ParticleMarch28

Mar 27th, 2014
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 KB | None | 0 0
  1. import javafx.scene.paint.Paint;
  2.  
  3. public class Particle {
  4.  
  5.     private double posy;
  6.     private double posx;
  7.     private double targetx;
  8.     private double targety;
  9.     private double width;
  10.     private double height;
  11.     private Paint color;
  12.     private double randomEase;
  13.     private double travelRate;
  14.  
  15.     public Particle(double posx, double posy, double targetx, double targety,
  16.             int width, int height, Paint color) {
  17.  
  18.         this.posy = posy;
  19.         this.posx = posx;
  20.         this.targetx = targetx;
  21.         this.targety = targety;
  22.         this.width = width;
  23.         this.height = height;
  24.         this.color = color;
  25.         randomEase = Math.random() * 0.03;
  26.         travelRate = 0.03;
  27.     }
  28.  
  29.     public void update() {
  30.         posx += calculateXDistance(targetx) * (travelRate);
  31.         posy += calculateYDistance(targety) * (travelRate + randomEase);
  32.     }
  33.  
  34.     private double  calculateYDistance(double yTarget) {
  35.         return yTarget - posy;
  36.     }
  37.  
  38.     private double  calculateXDistance(double xTarget) {
  39.         return xTarget - posx;
  40.     }
  41.    
  42.     // Getters / setters....
  43.  
  44.     public double getPosy() {
  45.         return posy;
  46.     }
  47.  
  48.     public double getPosx() {
  49.         return posx;
  50.     }
  51.  
  52.     public double getTargetx() {
  53.         return targetx;
  54.     }
  55.  
  56.     public double getTargety() {
  57.         return targety;
  58.     }
  59.  
  60.     public double getWidth() {
  61.         return width;
  62.     }
  63.    
  64.     public void setWidth(double width) {
  65.         this.width = width;
  66.     }
  67.  
  68.     public double getHeight() {
  69.         return height;
  70.     }
  71.    
  72.     public void setHeight(double height) {
  73.         this.height = height;
  74.     }
  75.  
  76.     public Paint getColor() {
  77.         return color;
  78.     }
  79.  
  80.     public double getRandomEase() {
  81.         return randomEase;
  82.     }
  83.  
  84.     public double getTravelRate() {
  85.         return travelRate;
  86.     }
  87.    
  88.    
  89.    
  90. }
Advertisement
Add Comment
Please, Sign In to add comment