Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

for loop in a class

$
0
0
hi processing community,

im a bit of a processing newbie and perhaps you can help me:
I want to make a programm where there are 5 small movies that i can drag around .. 
so far it all works fine but my problem is that the for loop in the Circle class i guess.
the code only shows me the same movie, i guess that the display block in the circle class is not looping.
and the array and the for loop has no influence on the  image(eye[i],xpos,ypos,304,224); in line 95
can anybody help me with that?
sorry for my bad englisch

Thanks for any help

  1. import processing.video.*;

  2.  
  3. Movie myMovie;
  4. Movie myMovie2;

  5. Movie [] eye = new Movie [5];


  6. Circle [] circles = new Circle[5];
  7.  
  8. void setup()
  9. {
  10.   
  11.   
  12.   eye[0] = new Movie(this, "eye.mov");
  13.   eye[0].loop();
  14.   
  15.   eye[1] = new Movie(this, "eye.mov");
  16.   eye[1].loop();
  17.   
  18.   eye[2] = new Movie(this, "eye.mov");
  19.   eye[2].loop();
  20.    
  21.   eye[3] = new Movie(this, "eye.mov");
  22.   eye[3].loop();
  23.   
  24.   eye[4] = new Movie(this, "eye2.mov");
  25.   eye[4].loop();
  26.   
  27.   

  28.   size(1920,1000);
  29.   smooth();
  30.   for (int i = 0; i < circles.length; i++)
  31.   {
  32.     circles[i] = new Circle();
  33.   }
  34. }

  35.  
  36. void draw()
  37. {

  38.   

  39.  background(0);
  40.  
  41.  
  42.   for (int i = 0; i < circles.length; i++)
  43.   {
  44.     circles[i].display();
  45.   }
  46.   

  47.   
  48. }


  49.  
  50. void mouseDragged()
  51. {
  52.   for (int i = 0; i < circles.length; i++)
  53.   {
  54.     circles[i].move();
  55.   }
  56. }
  57.  
  58. class Circle
  59. {
  60.   float r;
  61.   float xpos;
  62.   float ypos;
  63.  
  64.   Circle()
  65.   {
  66.     xpos = random(width);
  67.     ypos = random(height);
  68.    noFill();
  69.     r = 10;
  70.     
  71.          
  72.     
  73.   }
  74.   void display()
  75.   {
  76.     noStroke();
  77.     //fill(255,80);
  78.     
  79.  
  80.  for (int i = 0; i < eye.length; i++) 
  81.    
  82.     {      
  83.     image(eye[i],xpos,ypos,304,224);
  84.     }
  85.     
  86.     rect(xpos,ypos,r*2,r*2);
  87.     loop();
  88.   }
  89.  
  90.   void move()
  91.   {
  92.     if(dist(mouseX,mouseY,xpos,ypos)<r)
  93.     {
  94.       xpos = mouseX;
  95.       ypos = mouseY;
  96.       if (xpos>width || ypos>height) {
  97.         xpos = 0;
  98.         ypos = 0;
  99.       }
  100.     }
  101.   }
  102. }



  103. void movieEvent(Movie m) {
  104.   m.read();
  105. }


Viewing all articles
Browse latest Browse all 1768

Trending Articles