• fullscreen
  • muster_10.pde
  • /**
     *    spheres
     */
    
    import processing.pdf.*;       // PDF library (Plugin) laden
    
    
    /* ------ variablen anlegen ------ */
    
    int     grid_size  = 105;      // rastergrösse in pixeln
    float x = 0;
    float y = 0;
    
    
    
    /* ------ variablen für einstellungen ------ */
    
    boolean save_pdf   = false;    // pdf sichern? true oder false
    
                                   // name des PDFs
    String  pdf_name   = "beispiel";
    
    
    
    /* ------ setup und draw ------ */
    
    void setup ()               // einstellungen machen
    {
        size(screen.width, screen.height);      // grösse der zeichenfläche und pdf
     
        smooth();               // kantenglättung an!
        grid_size  = width/10; 
    }
    
    
    void draw ()                // hauptschleife vom programm, loopt
    {
        grid_size  = width/20; 
        if ( save_pdf )
            beginRecord( PDF, "muster-4-"+pdf_name+"-####.pdf" );    // pdf schreiben? dann beginnen
        
        background(0);                                     // hintergrund weiss füllen (löschen)
        
        float grid_w = (width/grid_size);                      // anzahl rasterelemente in der höhe
        float grid_h = (height/grid_size);                     // anzahl rasterelemente in der höhe
            
        for ( int ix = 0; ix <= grid_w; ix = ix+1 )             // von links nach rechts
        {
            
            for ( int iy = 0; iy <= grid_h; iy++ )              // von oben nach unten
            {
              pushMatrix();                                  // alten nullpunkt merken
                
              translate( ix*grid_size, iy*grid_size );   // nullpunkt ins rasterfeld
              translate( grid_size/2, grid_size/2 );     // nullpunkt in die mitte vom rasterfeld
                    if((ix+iy)%2 == 0){
                    
                      x = (grid_size-(abs(grid_w-2*ix))*grid_size/grid_w);
                      y = (grid_size-(abs(grid_h-2*iy))*grid_size/grid_h);              // elementMalen aufrufen
                    
                      float sc =map((x+y), 0, 2*grid_size, 0.1, 1);
                      scale(sc*2);
                      noFill();
                    
                      elementMalen(x, y);
                    
                    }
              popMatrix();                 // nullpunkt auf alten zurücksetzen
        
          }
        }
    
        if ( save_pdf ) endRecord();                           // pdf schreiben? dann fertig!
    
        noLoop();                                              // loop anhalten
    }
    
    
    
    /* ------ mouse abfrage ------ */
    
    void mousePressed ()     // wird aufgerufen wenn die mouse gedrückt wurde / ist
    {
        redraw();            // einmal neu zeichnen
    }
    
    
    
    /* ------ muster funktionen ------ */
    
    void elementMalen ( float w, float h )
    {
        float grid_w = (width/grid_size);                      // anzahl rasterelemente in der höhe
        float grid_h = (height/grid_size);                     // anzahl rasterelemente in der höhe
     
    
            
            for ( float i = grid_w; i > 0; i=i-2 )              // von oben nach unten
            {
                pushMatrix();                                  // alten nullpunkt merken
                  
                    x = i*(grid_size/grid_w);
                    y = (grid_size);               // elementMalen aufrufen
                  
                   stroke(5*w, 5*h, 0);
                   strokeWeight(0.5);
                   
                   
                    ellipse( 0,0, x, y );
                    
                    ellipse( 0,0, y, x );                
                    
                popMatrix();                                   // nullpunkt auf alten zurücksetzen
            }
        
      
    }
    

    code

    tweaks (0)

    about this sketch

    This sketch is running as Java applet, exported from Processing.

    license

    advertisement

    benja

    another sphere-pattern

    Add to Faves Me Likey@!
    You must login/register to add this sketch to your favorites.

    one more variation...

    subpixel
    25 Apr 2009
    This looks cool. I can't understand some of the code, though. It seems very confused.

    x = (grid_size-(abs(grid_w-2*ix))*grid_size/grid_w);
    y = (grid_size-(abs(grid_h-2*iy))*grid_size/grid_h);
    float sc =map((x+y), 0, 2*grid_size, 0.1, 1);
    scale(sc*2);
    elementMalen(x, y);

    It looks overly complicated, which usually means it is! If the width is, say, 900 pixels, then the x values go (approximately) from 0 to 45 and back to 0. In elementMalen(), the w and h values are actually used for the stroke colour, not positioning, and the idea is (or seems to be) to reduce the red/green values away from the centre.

    Consider:

    a = 1 - abs( map(ix, 0, grid_w, -1, 1) ); // values 0 to 1 to 0 again
    b = 1 - abs( map(iy, 0, grid_h, -1, 1) ); // values 0 to 1 to 0 again
    scale(a + b);
    benja
    12 May 2009
    hey subpixel,
    thanks for your comment,
    i tried out your code, and it works well.

    sorry for my code beeing that "confused", its because i was too :)
    You need to login/register to comment.