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.

1. Woche : Videofilter

Februar 27, 2012

Meine Idee war es einen "Distortion"-FIlter zu erstellen, welcher auch die vorherigen Aufgaben mitbeinhaltet. So sind sowohl Klassen-Objekte, Histogramm als auch Pixelauslesen und -verändern in einem Programm zusammengefasst. Der Distortionfilter ist aus drei verschiedenen "Effekten" zusammengestellt: 1. Bereiche des "Bildes" werden in einen Bild-Buffer kopiert und dann leichrt verschoben wieder auf das Bild eingefügt. Es gibt zwei verschiedene Arten, der erste ist ein kleiner quadratischer Ausschnitt der nur leicht verschoben wird, dadurch entsteht ein Flimmern. Die zweiten sind lineare Bereiche die horizontal in grösserem Abstand verschoben werden, dadurch entsteht eine Art "Zeilenverschiebung" wie man sie von Bildsignalstörungen bei alten analogen Fernseher kennt. 2. Einen einfachen Zeileneffekt der jede zweite Zeile abdunkelt. 3. Einem zufälligen Abdunkeln des ganzen Bildes. Download Code: hier Code: Hauptcode:
int fullHours;
int fullMinutes;
int manFullHours;
int fullSeconds;
int dayColor;
int maxDistSize;
int bigFlash;

int[] histB = new int[255];

Random generator;

float arcScale;
LineText hText, mText, sText;
TimeArc sArc, mArc, hArc;

ArrayList pgDistortions;

PGraphics full;

PImage bgPicture;

void setup() {
  generator = new Random();
  size(800, 800);
  frameRate(30);
  maxDistSize = 100;
  full = createGraphics(width+2*maxDistSize, height+2*maxDistSize, P2D);
  //println(full.height);
  bgPicture = loadImage("background.jpg");

  bigFlash = 0;

  sArc = new TimeArc(full);
  mArc = new TimeArc(full);
  hArc = new TimeArc(full);
  arcScale = 1;

  //background(255);
  smooth();
  full.smooth();
  pgDistortions = new ArrayList();
  for (int i=0;i<30;i++)
  {
    pgDistortions.add(new Distort(200, 10, 2, false)); // width,height,peak,line?
  }
  for (int i=0;i<10;i++)
  {
    pgDistortions.add(new Distort(200, 100, 20, false)); // width,height,peak,line?
  }
  for (int i = 0;i<5;i++)
  {
    pgDistortions.add(new Distort(width, int(random(5, 50)), int(random(5, 40)), true)); // width,height,peak,line?
  }
}

void draw() {
  full.colorMode(RGB, 255);
  full.beginDraw();
  full.image(bgPicture, 0, 0, full.width, full.height);

  full.noFill();
  noCursor();

  clock(mouseX+maxDistSize/2, mouseY+maxDistSize/2);
}

void clock(int xWert, int yWert) {

  arcScale = map(yWert, 0, height, 3, 5)+random(0.1);
  full.noStroke();
  colorMode(HSB, 360);

  fullHours = (hour()*3600+minute()*60+second())*360/86400;
  fullMinutes = (minute()*60+second())*360/3600;
  fullSeconds = (second())*360/60;

  full.pushMatrix();
  full.translate(xWert, yWert);
  full.rotate(-PI/2);
  manFullHours = fullHours;
  if (manFullHours < 43200*360/86400) // 0 -12:00 Uhr
  {
    dayColor= int(map(manFullHours, 0, 180, -120, 60));
    //println("0:00-12:00");
  }

  else
  {
    dayColor= int(map(manFullHours, 180, 359, 60, -120));
    //println("12:00-0:00");
  }

  if ( dayColor < 0)
  {
    dayColor = 360 + dayColor;
  }
  //println(dayColor);

  dayColor = 240;

  hArc.update(color(dayColor, 60, 180), 40, 2*fullHours, fullHours*24/360, arcScale);
  hArc.draw();

  mArc.update(color(dayColor, 240, 200), 30, fullMinutes, fullMinutes*60/360, arcScale);
  mArc.draw();

  sArc.update(color(dayColor, 360, 200), 20, fullSeconds, fullSeconds*60/360, arcScale);
  sArc.draw();
  full.popMatrix();

  loadPixels();

  full.endDraw();
  updatePixels();

  pNoise();
  television();

  image(full, -maxDistSize/2, -maxDistSize/2);
  for (int i = 0; i < pgDistortions.size(); i++)
  {
    Distort distortion = (Distort) pgDistortions.get(i);
    distortion.draw();
  }

  if (bigFlash <= 1)
  {

    //full.background(360);

    filter(ERODE);
    if (bigFlash == 0)
    {
      bigFlash = int(random(10, 80));
    }
  }
  bigFlash--;

  histogram();
}

void pNoise()
{
  loadPixels();

  for ( int x = 0; x < full.width; x++)
  {
    for (int y = 0; y < full.height; y++)
    {
      int loc = x + y * full.width;
      colorMode(RGB, 255);
      color col = full.pixels[loc];

      //noise
      int dColor = int(random(-50, 50));
      full.pixels[loc] = color(red(col)+dColor, green(col)+dColor, blue(col)+dColor, 100);
    }
  }

  updatePixels();
}

void television()
{
  loadPixels();

  for ( int x = 0; x < full.width; x++)
  {
    for (int y = 0; y < full.height; y++)
    {
      if (y % 4 == 0)
      {
        int loc = x + y * full.width;
        colorMode(RGB, 255);
        color col = full.pixels[loc];

        //noise
        full.pixels[loc] = color(red(col)-50, green(col)-50, blue(col)-50);
      }
    }
  }

  updatePixels();
}

float randomNormal()
{
  float x = 1.0, y = 1.0,
  s = 2.0; // s = x^2 + y^2
  while (s >= 1.0)
  {
    x = random(-1.0f, 1.0f);
    y = random(-1.0f, 1.0f);
    s = x*x + y*y;
  }
  return x * sqrt(-2.0f * log(s)/s);
}

void histogram(){
  for (int x=0; x<width; x++)
  {
    for (int y=0; y<height; y++)
    {
      int bright = int(brightness(get(x,y)));
      histB[bright]++;

    }
  }

  int histMax = max(histB);

  stroke(0);

  for (int i = 0; i < width; i+=2)
  {
    int wich = int(map(i, 0, width, 0, 255));

    int y = int(map(histB[wich],0,histMax, height,0));

    line(i, height, i, y);
  }

}
Distort Klasse:
class Distort {

  int dSizeX, dSizeY, peak;
  int oldMillis;
  int[] saveXY = new int[2];
  PGraphics pg;
  int pgX;
  int pgY;
  int randomValue;
  boolean dLine;

  Distort(int _dSizeX, int _dSizeY, int _peak, boolean _dLine)

  {
    dLine = _dLine;
    dSizeX = _dSizeX;
    dSizeY = _dSizeY;
    peak = _peak;
    pg = createGraphics(_dSizeX, _dSizeY, P2D);
    randomValue = int(random(500, 4000));
    oldMillis = -randomValue;
    pg.smooth();
  }

  void draw()

  {

    if (millis()-oldMillis >= randomValue)
    {
      if (dLine)
      {
        saveXY[0]=width/2;
        float gauss = (float)generator.nextGaussian()/2.0;
        if (gauss <= -1.0) {
          gauss = -1.0;
        }
        if (gauss >= 1.0) {
          gauss = 1.0;
        }
        //println(int((gauss+1.0)*height/2.0));
        saveXY[1]=int((gauss+1.0)*height/2.0);
      }
      else
      {
        saveXY[0]= int(random(0, 800));
        saveXY[1]= int(random(0, 800));
        dSizeX = int(random(50, maxDistSize));
        dSizeY = int(random(50, maxDistSize));
      }
      //println(saveXY);
      pg = createGraphics(dSizeX, dSizeY, P2D);
      //println(pg.width);
      randomValue = int(random(1000, 2000));
      oldMillis=millis();
    }
    full.loadPixels();
    pg.loadPixels();

    pgX=0;
    for ( int dX = saveXY[0]-pg.width/2; dX < saveXY[0]+pg.width/2; dX++)
    {
      pgY=0;
      for (int dY = saveXY[1]-pg.height/2; dY < saveXY[1]+pg.height/2; dY++)
      {
        int dLoc = dX+maxDistSize/2 + (dY+maxDistSize/2) *full.width;
        int pgLoc = pgX + pgY * pg.width;
        pg.pixels[pgLoc] = full.pixels[dLoc];

        // Start Zeichnen im Offscreen Buffer pg
        pgY++;
      }
      pgX++;
    }
    pg.updatePixels();

    image(pg, saveXY[0]-pg.width/2+random(-peak, peak), saveXY[1]-pg.height/2+random(-peak, peak));
  }
}

TimeArc-Klasse:
class TimeArc {

  int xCord,yCord, arcRadius, arcValue,arcT;
  float arcScale;
  color c;
  LineText arcText;
  PGraphics arcFull;
  int arcWeight;
  int arcTimer;

 TimeArc(PGraphics _arcFull)
 {
   arcFull = _arcFull;
   xCord = 0;
   yCord = 0;
   arcRadius = 0;
   arcValue = 0;
   c = color(0,0,0);
   arcText = new LineText();
   arcScale = 1;
   arcWeight = 30;
   arcTimer = 0;
 }

 TimeArc(color _c,int _arcRadius, int _arcValue, int _arcT, float _arcScale)
 {
   xCord = 0;
   yCord = 0;
   arcRadius = _arcRadius;
   arcValue = _arcValue;
   arcT = _arcT;
   c = _c;
   arcScale = _arcScale;
   arcText = new LineText(c,arcRadius, arcRadius+10,arcValue,arcT,arcScale, arcWeight);

 }
 void update(color _c,int _arcRadius, int _arcValue, int _arcT, float _arcScale){
   xCord = 0;
   yCord = 0;
   arcRadius = _arcRadius;
   arcValue = _arcValue;
   arcT = _arcT;
   c = _c;
   arcScale = _arcScale;

 }

 void draw(){
  arcFull.smooth();
  arcFull.colorMode(HSB,360);
  arcFull.fill(c);
  arcFull.noStroke();
  if(arcValue > 360)
  {
     arcValue = arcValue -360;
  }
  arcFull.noFill();
  arcFull.strokeWeight(arcWeight);
  arcFull.stroke(c);
  arcFull.arc(0, 0, arcRadius*2*arcScale, arcRadius*2*arcScale, 0, radians(arcValue));

  if (arcValue == 0)
  {
    arcTimer = 0;
  }

  if (arcTimer <=200)
{
  arcFull.strokeWeight(1*arcScale);
  arcFull.stroke(360,0,360,360/20*(20-arcTimer));
  arcFull.arc(0, 0, arcRadius*2*arcScale+arcWeight, arcRadius*2*arcScale+arcWeight, 0, 2*PI);
  arcTimer++;
  }

  arcText.update(c, arcRadius, arcRadius, radians(arcValue), arcT, arcScale, arcWeight);
  arcText.draw();
  /*
  arcFull.noStroke();
  arcFull.fill(360);
  arcFull.ellipse(0, 0, ((2*arcRadius)-20)*arcScale, ((2*arcRadius)-20)*arcScale);
   */
 }

}
LineText-Klasse:
class LineText {
  color c;
  float lineStart,lineLength, pScale, arcWeight;
  float arcValue, oldArcValue, saveArcValue; // Winkel
  int lText, oldLText, saveText, textCounter;
  PFont font;

  LineText() {
    c = color(255, 255, 255);
    lineLength = 0;
    arcValue = 0;
    lText = 0;
  }

  LineText(color _c, float _lineStart, float _lineLength, float _arcValue, int _lText, float _pScale, int _arcWeight) {

    c = _c;
    lineLength = _lineLength;
    lineStart = _lineStart;
    arcWeight = _arcWeight;
    arcValue = _arcValue;
    lText = _lText;
    pScale = _pScale;
    oldLText = lText;
    oldArcValue = arcValue;
    saveText = lText;
    saveArcValue = arcValue;
    textCounter = 1000;
  }

  void draw()
  {
    font = loadFont("FrutigerLTCom-Light-48.vlw");
    full.textFont(font, 12*pScale);
    full.pushMatrix();
    full.rotate(arcValue);
    full.strokeWeight(1*pScale);
    full.stroke(c);
    full.line(lineStart*pScale-arcWeight/2, 0, (lineLength+45)*pScale, 0);
    full.fill(c);
    full.textAlign(RIGHT);
    full.text(lText, (lineLength+45)*pScale, -4);
    full.popMatrix();

    if (oldLText != lText)
    {
      saveText= lText;
      saveArcValue = arcValue;
      textCounter= 0;
    }

    if(textCounter<= 10)
    {
    font = loadFont("FrutigerLTCom-Light-48.vlw");

    full.textFont(font, 12*pScale*(1+textCounter*0.1*pScale));
    //println(textCounter);
    full.pushMatrix();

    full.rotate(saveArcValue);
    full.translate(textCounter*0.2*12*pScale,textCounter*0.2*pScale*12);
    full.fill(c,map(textCounter,0,10,200,0));
    full.text(saveText, (lineLength+45)*pScale+random(-2,2), -4+random(-2,2));

    textCounter++;
    oldLText = lText;
    oldArcValue = arcValue;
    full.popMatrix();
    }
  }

  void update(color _c, float _lineStart, float _lineLength, float _arcValue, int _lText, float _pScale, int _arcWeight) {

    c = _c;
    pScale = _pScale;
    lineLength = _lineLength;
    lineStart = _lineStart;
    arcWeight = _arcWeight;
    arcValue = _arcValue;
    lText = _lText;
    font = loadFont("DIN-Light-12.vlw");
    full.textFont(font, 12*pScale);
  }
}