Guest User

Untitled

a guest
Jul 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. PImage bg1;
  2. PImage bg2;
  3. Pixels[] px = new Pixels[9];
  4.  
  5. void setup(){
  6. // bg1 = loadImage("bg1.jpg");
  7. // bg2 = loadImage("bg2.png");
  8. }
  9.  
  10.  
  11.  
  12. public class Pixels extends Thread {
  13. // Constructor, create the thread
  14. // It is not running by default
  15. public Pixels (float pSize, float pX, float pY, float pOpacity, float pSpeed, int pBehave){
  16. }
  17. public void start ()
  18. {
  19. // Do whatever start does in Thread, don't forget this!
  20. super.start();
  21. }
  22. public void run ()
  23. {
  24. if(pBehave == 1){
  25. while (pSize < 6){
  26. pSize = pSize + pSpeed;
  27. rect(pX,pY,pSize,pSize);
  28. // Ok, let's wait for however long we should wait
  29. try {
  30. sleep((long)(1));
  31. }
  32. catch (Exception e) {
  33. }
  34. if(pSize >= 6){
  35. pBehave = 2;
  36. }
  37. }}else{
  38. pSize = pSize - pSpeed;
  39. rect(pX,pY,pSize,pSize);
  40. // Ok, let's wait for however long we should wait
  41. try {
  42. sleep((long)(1));
  43. }
  44. catch (Exception e) {
  45. }
  46. }
  47.  
  48. // The thread is done when we get to the end of run()
  49. }
  50. // Our method that quits the thread
  51. public void quit()
  52. {
  53. System.out.println("Quitting.");
  54. running = false; // Setting running to false ends the loop in run()
  55. interrupt(); // in case the thread is waiting. . .
  56. }
  57. }
  58.  
  59. void draw(){
  60. background(0);
  61. // image(bg1,0,0);
  62. for(int i = 0; i < 9; i = i + 1){
  63. px[i] = new Pixels(random(2,6),random(20,780),random(20,155),0,random(0.1,0.8),1);
  64. px[i].start();
  65. }
  66. }
Add Comment
Please, Sign In to add comment