Guest User

lapsefectSpeed_jfx

a guest
Jan 20th, 2015
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.92 KB | None | 0 0
  1. /*
  2.  * bem10jfx.blogspot.com
  3.  laps inds efects
  4.  */
  5. package pensa;
  6.  
  7. import java.util.Random;
  8. import javafx.animation.Interpolator;
  9. import javafx.animation.Timeline;
  10. import javafx.animation.TranslateTransition;
  11. import javafx.application.Application;
  12. import javafx.event.EventHandler;
  13. import javafx.scene.Group;
  14. import javafx.scene.Scene;
  15. import javafx.scene.input.MouseEvent;
  16. import javafx.scene.layout.VBox;
  17. import javafx.scene.paint.Color;
  18. import javafx.scene.shape.Rectangle;
  19. import javafx.scene.text.Text;
  20. import javafx.stage.Stage;
  21. import javafx.util.Duration;
  22.  
  23. /**
  24.  * speeds
  25.  */
  26. public class pensa extends Application {
  27.     int vlh,vlw;
  28.     int vlHpres,vlWpres;
  29.    
  30.     @Override
  31.     public void start(Stage stage) {
  32.        
  33.         final Group go=new Group();
  34.         final Scene scene=new Scene(go,400,400, Color.BLACK);
  35.         stage.setScene(scene);
  36.         final Text txh,txw,txhpres,txwpres,txflux;
  37.         VBox vbox=new VBox();
  38.         go.getChildren().add(vbox);
  39.        
  40.         txh=new Text   ("h    :"+vlw);
  41.         txw=new Text   ("w    :"+vlh);
  42.         txhpres=new Text("hpress :"+vlWpres);
  43.         txwpres=new Text("wpress :"+vlHpres);
  44.         txflux=new Text("Event:");
  45.         final Text txColor = new Text("CorRand:");
  46.         txh.setFill(Color.BLUE);
  47.  
  48.         txw.setFill(Color.BLUE);
  49.  
  50.         txhpres.setFill(Color.BLUE);
  51.         txwpres.setFill(Color.BLUE);
  52.         txflux.setFill(Color.BLUE);
  53.          txColor.setFill(Color.BLUE);
  54.         vbox.getChildren().addAll(txh,txw,txhpres,txwpres,txflux,txColor);
  55.        
  56.          scene.setOnMouseDragged(new EventHandler<MouseEvent>() {
  57.            @Override
  58.             public void handle(MouseEvent event) {
  59.           int cont =1;
  60.                      cont++;
  61.                 vlh=(int) event.getY();
  62.                 vlw=(int) event.getX();
  63.                  txh.setText("h    :"+vlh);
  64.                  txw.setText("w    :"+vlw);
  65.                  txflux.setText("Event :"+cont+"");
  66.                  String strEntry1 = "'=')";
  67.                  txColor.setText("CorRand:"+ strEntry1);
  68.                  //cor rando atual
  69.                  
  70.                         Random randOne[]=new Random[112];
  71.                        Random randsamir[]=new Random[112];    
  72.                        Rectangle rectcolors[] = new Rectangle[1000] ;
  73.                          
  74.                         Timeline tl[]=new Timeline[1000];
  75.                        
  76.                  for (int i = 0; i < 1000; i++) {
  77.                     randOne[i]=new Random(System.nanoTime());    
  78.                     randsamir[i]=new Random(System.nanoTime());                    
  79.                    
  80.                     rectcolors[i]=new Rectangle();
  81.                     rectcolors[i].setHeight(5);
  82.                     rectcolors[i].setWidth(5);
  83.                     int c =  randOne[i].nextInt((int )252),
  84.                             o = randsamir[i].nextInt((int) 5.6  ),
  85.                             r = 250;
  86.                    
  87.                     rectcolors[i].setFill(Color.rgb( o,r,c));
  88.                     rectcolors[i].setX(vlw);
  89.                     rectcolors[i].setY(vlh-20);
  90.                    
  91.                          TranslateTransition tt=new TranslateTransition(Duration.millis(10000), rectcolors[i]);
  92.                          tt.setCycleCount(Timeline.INDEFINITE);
  93.                          tt.setDelay(Duration.millis(10000));
  94.                        
  95.                      tt.setFromX(vlw);
  96.                      tt.setFromY(vlh-20);
  97.                      tt.toXProperty().bind(rectcolors[i].xProperty().divide(rectcolors[i].xProperty()).subtract(30));
  98.                     tt.toYProperty().bind(rectcolors[i].yProperty().divide(rectcolors[i].yProperty()).subtract(30));
  99.                     // tt.setToX (( rectcolors[i].getX())+randsamir[i].nextInt());
  100.                      //tt.setToY(( rectcolors[i].getY())+randsamir[i].nextInt());
  101.                      
  102.                      tt.setByX(vlw);
  103.                      tt.setByY(vlw-20);
  104.                      tt.play();
  105.                      go.getChildren().add(rectcolors[i]);
  106.                       txColor.setText("CorRand:"+ rectcolors[i].fillProperty().getValue().toString());
  107.                       txColor.setFill(Color.web(rectcolors[i].fillProperty().getValue().toString()));
  108.                       System.out.println("x"+i);
  109.                }
  110.  
  111.                            
  112.             }
  113.         });
  114.           scene.setOnMouseReleased(new EventHandler<MouseEvent>() {
  115.            @Override
  116.             public void handle(MouseEvent event) {
  117.          
  118.                 vlHpres=(int) event.getY();
  119.                 vlWpres=(int) event.getY();
  120.                  txhpres.setText("h    :"+vlw);
  121.                  txwpres.setText("w    :"+vlh);
  122.                
  123.             }
  124.         });
  125.        
  126.         stage.show();
  127.                
  128.     }
  129.     public static void main(String[] args) {
  130.         launch(args);
  131.     }
  132.    
  133. }
Advertisement
Add Comment
Please, Sign In to add comment