GMU:Processing im Park/Dirk Wäsch/Code Finale Aufgabe: Difference between revisions

From Medien Wiki
(Created page with "Processing v3.0.1 Quellcode: <br> <source lang="java"> float[] pixefs; ArrayList< Integer > neighbours; int area = 1; float influence = 0.75f; float power = 3.5f; void setup...")
 
No edit summary
Line 4: Line 4:
<source lang="java">
<source lang="java">
float[] pixefs;
float[] pixefs;
ArrayList< Integer > neighbours;
ArrayList< Integer > Farbe;
   
   
int area = 1;
int area = 1;
Line 14: Line 14:
   size( 1366,768 );
   size( 1366,768 );
    
    
   PImage im = loadImage( "beispiel2.jpg" );
   PImage im = loadImage( "bild.jpg" );
    
    
   background( 255 );
   background( 255 );
   image( im, 0, 0, width, height );
   image( im, 0, 0, width, height );
    
    
   neighbours = new ArrayList< Integer >();
   Farbe = new ArrayList< Integer >();
    
    
   loadPixels();
   loadPixels();
Line 37: Line 37:
         continue;
         continue;
       if ( active( x, y ) ) {
       if ( active( x, y ) ) {
         // println( x +" / "+ y + " has at least one neighbours who is not black" );
         // println( x +" / "+ y + "hat die letzte angrenzende Farbe schwarz" );
         getNeighbours( x, y, area );
         getFarbe( x, y, area );
         float inf = influence / neighbours.size();
         float inf = influence / Farbe.size();
         for ( int i = 0; i < neighbours.size(); i++ ) {
         for ( int i = 0; i < Farbe.size(); i++ ) {
           int nid = neighbours.get( i );
           int nid = Farbe.get( i );
           pixefs[ nid ] -= inf * pow( ( 255.f / pixefs[ nid ] ), power );
           pixefs[ nid ] -= inf * pow( ( 255.f / pixefs[ nid ] ), power );
           if ( pixefs[ nid ] < 0 )
           if ( pixefs[ nid ] < 0 )
Line 69: Line 69:
}
}
   
   
void getNeighbours( int x, int y, int range ) {
void getFarbe( int x, int y, int range ) {
   neighbours.clear();
   Farbe.clear();
   for ( int ty = y-range; ty <= y+range; ty++ ) {
   for ( int ty = y-range; ty <= y+range; ty++ ) {
     if ( ty < 0 )
     if ( ty < 0 )
Line 83: Line 83:
       if ( tx == x && ty == y )
       if ( tx == x && ty == y )
         continue;
         continue;
       neighbours.add( tx + ty * width );
       Farbe.add( tx + ty * width );
     }
     }
   }
   }

Revision as of 15:31, 1 April 2016

Processing v3.0.1 Quellcode:


float[] pixefs;
ArrayList< Integer > Farbe;
 
int area = 1;
float influence = 0.75f;
float power = 3.5f;
 
void setup() {
   
  size( 1366,768 );
   
  PImage im = loadImage( "bild.jpg" );
   
  background( 255 );
  image( im, 0, 0, width, height );
   
  Farbe = new ArrayList< Integer >();
   
  loadPixels();
  pixefs = new float[ pixels.length ];
  for ( int i = 0; i < pixels.length; i++ ) {
    pixefs[ i ] = brightness( pixels[ i ] );
  }
   
}
 
void process() {
  int ID = 0;
  for ( int y = 0; y < height; y++ ) {
    for ( int x = 0; x < width; x++ ) {
      ID = x + y * width;
      if ( pixefs[ ID ] != 0 )
        continue;
      if ( active( x, y ) ) {
        // println( x +" / "+ y + "hat die letzte angrenzende Farbe schwarz" );
        getFarbe( x, y, area );
        float inf = influence / Farbe.size();
        for ( int i = 0; i < Farbe.size(); i++ ) {
          int nid = Farbe.get( i );
          pixefs[ nid ] -= inf * pow( ( 255.f / pixefs[ nid ] ), power );
          if ( pixefs[ nid ] < 0 )
            pixefs[ nid ] = 0;
        }
      }
    }
  }
}
 
boolean active( int x, int y ) {
  for ( int ty = y-1; ty <= y+1; ty++ ) {
    if ( ty < 0 )
      continue;
    if ( ty >= height )
      break;
    for ( int tx = x-1; tx <= x+1; tx++ ) {
      if ( tx < 0 )
        continue;
      if ( tx >= width )
        break;
      if ( pixefs[ tx + ty * width ] > 0 )
        return true;
    }
  }
  return false;
}
 
void getFarbe( int x, int y, int range ) {
  Farbe.clear();
  for ( int ty = y-range; ty <= y+range; ty++ ) {
    if ( ty < 0 )
      continue;
    if ( ty >= height )
      break;
    for ( int tx = x-range; tx <= x+range; tx++ ) {
      if ( tx < 0 )
        continue;
      if ( tx >= width )
        break;
      if ( tx == x && ty == y )
        continue;
      Farbe.add( tx + ty * width );
    }
  }
}
 
void draw() {
   
  process();
  for ( int i = 0; i < pixels.length; i++ )
    pixels[ i ] = color( pixefs[ i ] );
  updatePixels();
 
}