• fullscreen
  • _3dboxfun_04.pde
  • cube.pde
  • cubegrid.pde
  • int cubesPerSide = 20;
    int numCubes = cubesPerSide*cubesPerSide;
    cubegrid cubeGrid = new cubegrid();
    
    
    void setup()
    {
      size(500,500,P3D);
    }
    
    void draw()
    {
      background(0,0,0);
      cubeGrid.render();
    }
    
    void mouseMoved()
    {
      cubeGrid.attractCubes((float)mouseX,(float)mouseY);
    }
    
    class cube
    {
      float x, y, z, w;
      color cubeColor, selectionColor, finalColor;
      boolean selected;
     
      cube(float xpos, float ypos, float boxWidth)
      {
        selected = false;
        x = xpos;
        y = ypos;
        z = 0;
        w = boxWidth;
      }
      
      void render()
      {
        cubeColor = color(255,0,255,30);
        if(selected)
        {
          selectionColor = color(255,255,255,255);
        }
        else
        {
          selectionColor = color(constrain((red(selectionColor)*8+red(cubeColor))/9,0,255), 
                                 constrain((green(selectionColor)*8+green(cubeColor))/9,0,255),
                                 constrain((blue(selectionColor)*8+blue(cubeColor))/9,0,255), 
                                 constrain((alpha(selectionColor)*8+alpha(cubeColor))/9,0,255));
        }
        pushMatrix();
          translate(x,y,z);
          if(selected)
          {
            fill(selectionColor);
          }
          else
          {
            fill(selectionColor);
          }
          stroke(0,0,0,255);
          box(30,30,w);
        popMatrix();
      }
    }
    
    class cubegrid
    {
      cube[] cubes = new cube[numCubes];
      
      cubegrid()
      {
        for(int x = 0; x < cubesPerSide; x++)
        {
          for(int y = 0; y < cubesPerSide; y++)
          {
            cubes[x+y*cubesPerSide] = new cube(x*30,y*30,30);
          }
        }
      }
      
      void attractCubes(float xPos, float yPos)
      {
        for(int i = 0; i < numCubes; i++)
        {
          float distance = dist(xPos,yPos,cubes[i].x,cubes[i].y);
          cubes[i].w = distance / 10;
          if(distance<40)
          {
            cubes[i].selected = true;
          }
          else
          {
            cubes[i].selected = false;
          }
        }
        
      }
      
      void render()
      {
        for(int i = 0; i < numCubes; i++)
       {
          cubes[i].render();
       } 
      }
    }
    

    code

    tweaks (0)

    about this sketch

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

    license

    advertisement

    Starkes

    3dboxfun

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

    boxes in p3d with some nifty color fading. fun for a few seconds.

    subpixel
    26 Jan 2009
    I like this - it seems more like a real object than most thing you can draw squiggles on. :o)
    Starkes
    1 Feb 2009
    its a cubegrid object lol.
    You need to login/register to comment.