• fullscreen
  • classes1_spageti.pde
  • tube.pde
  • tube t1 = new tube(10, 0.0, 0.01);
    tube t2 = new tube(20, 10.0, 0.01);
    tube t3 = new tube(30, 5.0, 0.01);
    tube t4 = new tube(40, 2.5, 0.01);
    tube t5 = new tube(10, 7.5, 0.01);
    tube t6 = new tube(20, 1.0, 0.01);
    
    PImage img;// image var
    int ix;// x location of image pixel, used for color data
    int iy;// y location of image pixel, used for color data
    //color c;// color data at point(ix,iy) of img
    int border = 50;
    
    void setup()
    {
      size(500,500);
      background(0);
      smooth();
      
      img = loadImage("desert.gif");
      ix = int(random(img.width));
      iy = int(random(img.height));
      t1.xCenter = width/2;
      t1.yCenter = height/2;
      t1.c = img.get(ix, iy); 
      t2.xCenter = width/2;
      t2.yCenter = height/2;
      t2.c = img.get(ix, iy);
      t3.xCenter = width/2;
      t3.yCenter = height/2;
      t3.c = img.get(ix, iy); 
      t4.xCenter = width/2;
      t4.yCenter = height/2;
      t4.c = img.get(ix, iy);
      t5.xCenter = width/2;
      t5.yCenter = height/2;
      t5.c = img.get(ix, iy); 
      t6.xCenter = width/2;
      t6.yCenter = height/2;
      t6.c = img.get(ix, iy);
    }
    
    void draw()
    {
      // functions
      t1.update();
      t2.update();
      t3.update();
      t4.update();
      t5.update();
      t6.update();
    }
    
    public class tube {
      color c;// color
      float x;// begin line x point
      float y;// begin line y point
      float xCenter;// end line x point
      float yCenter;// end line y point
      float radius;// line length...actually changes depending on perlin noise value
      float xoff;// for perlin noise
      float xincrement;// incrementer for perlin noise
      //int border = 50;
      tube (float r, float xo, float xi) {  
        radius = r; 
        xoff = xo;
        xincrement = xi;
        
      } 
      void update()
      {
        float n = noise(xoff)*10000;
        float r = noise(xoff)*10;
        float sc = noise(xoff)*100;
        xoff += xincrement;
        radius = r;
        x = (cos(radians(n)) * radius) + xCenter;
        y = (sin(radians(n)) * radius) + yCenter;
        if(mousePressed == true){
          x = mouseX;
          y = mouseY;
        }
        //strokeWeight(sc); 
        //stroke(c,200);
        if(((x > 0 - border) && (x < width + border)) && ((y > 0 - border) && (y < height + border))){
    
          strokeWeight(sc+2); 
          stroke(0);
          line(x, y, xCenter, yCenter);
          strokeWeight(sc); 
          stroke(c, 200);
          line(x, y, xCenter, yCenter);
        } 
        else {
          // if the line goes off the screen...
          // select a new color and...
          ix = int(random(img.width));
          iy = int(random(img.height));
          c = img.get(ix, iy);
          // make restart the line in the center of the screen.
          x = width/2;
          y = height/2;
        }
        xCenter = x;
        yCenter = y;
      }
    }
    
    

    code

    tweaks (0)

    about this sketch

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

    license

    advertisement

    Matt Richard plus+

    Tubes

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

    Uses classes and Perlin noise to draw cool spaghetti like things.
    <br>
    <A href="http://idblab.blogspot.com">Check out my blog</A>

    You need to login/register to comment.