GMU:Processing im Park/Dirk Wäsch/Code Finale Aufgabe: Difference between revisions
From Medien Wiki
No edit summary |
No edit summary |
||
Line 14: | Line 14: | ||
size( 1366,768 ); | size( 1366,768 ); | ||
PImage im = loadImage( " | PImage im = loadImage( "http://waesch.host56.com/ablage/images/Ink-Image.jpg" ); | ||
background( 255 ); | background( 255 ); |
Latest revision as of 23:44, 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( "http://waesch.host56.com/ablage/images/Ink-Image.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();
}