Willkommen auf unserem Seminar-Blog

Immer auf dem aktuellen Stand bleiben

Dieser Seminar-Blog befindet sich noch im Aufbau und wird in den kommenden Tagen entsprechend verfeinert.

Member Login

Lost your password?

Registration is closed

Sorry, you are not allowed to register by yourself on this site!

You must either be invited by one of our team member or request an invitation by email at viad.info {at} zhdk {dot} ch.

IAD Technoloogie Grundlagen 1 Woche 3

8. November 2011

In der dritten Woche hatten wir die Aufgabe einen Video Player zu coden. Meine Version erlaupt das Starten/Pausieren mit einem Umschaltknopf und einen Restart-Button. Der Code ist noch nicht Perfekt ausgereift. Um ein Nutzbares Resultat zu erhalten, müsste ich noch weitere Zeit investieren. Coding Space Video
import codeanticode.gsvideo.*;
GSMovie movie;

int clickTime = 0;
int clickSpeed = 200;
boolean clicked = false;
Checkbox checkbox1 = null;
Checkbox checkbox2 = null;

void setup() {
  size(640, 480);
  background(0);

  movie = new GSMovie(this, "Video.mov");

  // Pausing the video at the first frame.
  movie.play();
  movie.goToBeginning();
  movie.pause();

  checkbox1 = new Checkbox(width/2-25,height-100,50,50,false);
  checkbox2 = new Checkbox(width/2-150,height-100,50,50,false);
}

void movieEvent(GSMovie movie) {
  movie.read();
}

void draw() {
  // A new time position is calculated using the current mouse location:
   if (movie.ready()) {
     if(checkbox1._c)
     {
       movie.pause();
           if(checkbox2._c)
     {
          movie.goToBeginning();

          checkbox2._c = false;
      }
     }
     else
     {

       movie.play();
           if(checkbox2._c)
     {
          movie.goToBeginning();
          movie.pause();
          checkbox2._c = false;
      }
     }

  }

     if(checkbox2._c)
     {
          movie.goToBeginning();
          movie.pause();
          checkbox2._c = false;
      }

  image(movie, 0, 0, width, height);
  checkbox1.draw();
  checkbox2.draw();

}
void mousePressed()
{

  checkbox1.mousePos(mouseX,mouseY,true);
    checkbox2.mousePos(mouseX,mouseY,true);
}

Checkbox Klasse
class Checkbox
{
  PVector _p1;
  PVector _p2;
  int     _x;
  int     _y;
  int     _w;
  int     _h;
  boolean _c;
  
  Checkbox(int x,int y,int w,int h, boolean check)
  {   
    _x = x;
    _y = y;
    _h = h;
    _w = w;
    _c = check;
  }
  

  boolean isHit(int x,int y)
  {
    if(x > _x && x < _x + _w &&
       y > _y && y < _y + _h)
   { 
         return true;
   }
       else
       {
         return false;
       }
  }
  
  
  void draw()
  {
    drawBox();
   } 
   
  void drawBox()
  {
    pushStyle();
    stroke(255);
    fill(0);
    rect(_x-2,_y-2, _w+4,_h+4); 
    fill(255);
    rect(_x,_y, _w,_h); 
    if(_c)
    {
      stroke(0);
      fill(0);
       triangle(_x+_w-2,_y+_h/2,_x+2,_y+_h-1,_x+2,_y+1);
     }
     else
     {
      stroke(0);
      fill(0);
      rect(_x+_w/5,_y+ _h/8, _w/4,_h/4*3);
      rect(_x+_w/5*3,_y+ _h/8, _w/4,_h/4*3);
     }
      popStyle();
  }
 
 
    void mousePos(int x,int y,boolean pressed)
  {
    if(pressed && isHit(x,y))
    {     
          if( _c)
          {     
           _c = false;
          }
          else
          { 
           _c = true;
          }
     }
   }
}