Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PImage bg1;
- PImage bg2;
- Pixels[] px = new Pixels[9];
- void setup(){
- // bg1 = loadImage("bg1.jpg");
- // bg2 = loadImage("bg2.png");
- }
- public class Pixels extends Thread {
- // Constructor, create the thread
- // It is not running by default
- public Pixels (float pSize, float pX, float pY, float pOpacity, float pSpeed, int pBehave){
- }
- public void start ()
- {
- // Do whatever start does in Thread, don't forget this!
- super.start();
- }
- public void run ()
- {
- if(pBehave == 1){
- while (pSize < 6){
- pSize = pSize + pSpeed;
- rect(pX,pY,pSize,pSize);
- // Ok, let's wait for however long we should wait
- try {
- sleep((long)(1));
- }
- catch (Exception e) {
- }
- if(pSize >= 6){
- pBehave = 2;
- }
- }}else{
- pSize = pSize - pSpeed;
- rect(pX,pY,pSize,pSize);
- // Ok, let's wait for however long we should wait
- try {
- sleep((long)(1));
- }
- catch (Exception e) {
- }
- }
- // The thread is done when we get to the end of run()
- }
- // Our method that quits the thread
- public void quit()
- {
- System.out.println("Quitting.");
- running = false; // Setting running to false ends the loop in run()
- interrupt(); // in case the thread is waiting. . .
- }
- }
- void draw(){
- background(0);
- // image(bg1,0,0);
- for(int i = 0; i < 9; i = i + 1){
- px[i] = new Pixels(random(2,6),random(20,780),random(20,155),0,random(0.1,0.8),1);
- px[i].start();
- }
- }
Add Comment
Please, Sign In to add comment