Advertisement
dentonpotter

Cube Ring Greyscale

Oct 17th, 2015
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.21 KB | None | 0 0
  1. /* CUBE RING
  2. * Inspired by an image from tumblr
  3. * http://regolo54.tumblr.com/post/121360473702
  4. *
  5. * CC-BY 4.0 Karen Cropper
  6. * October 2015
  7. * Larger scale 1600px greyscale
  8. */
  9.  
  10. // global variables
  11.  
  12. float centreX, centreY; // centre of circle
  13. float margin;
  14.  
  15. float angle = PI/6;
  16. float ringRad;
  17.  
  18. int fillcol = 100; // greyscale version
  19. int backcol = 240; // background colour
  20. int backtrans = 60; // amount of transparency for depth
  21.  
  22. // set up
  23. void setup(){
  24.    size(1600,1600);
  25.  
  26.    background(backcol);
  27.    margin = -width/50;
  28.  
  29.    centreX = width/2;
  30.    centreY = height/2;
  31.    
  32.    // move to centre point
  33.    translate(centreX, centreY);
  34.  
  35.    /*                    *\
  36.     * draw smallest ring *
  37.    \*                    */
  38.    ringRad = 0.9*0.25*(width-(2*margin))/4; // ringRad used to calculate other points
  39.      
  40.    // call function
  41.    drawring(ringRad);
  42.    
  43.     /*                 *\
  44.     * draw middle ring *
  45.    \*                  */
  46.    ringRad = 0.98*0.5*(width-(2*margin))/4; // ringRad used to calculate other points
  47.      
  48.    // call function
  49.    drawring(ringRad);
  50.    
  51.    /*                 *\
  52.     * draw outer ring *
  53.    \*                 */
  54.    ringRad = (width-(2*margin))/4; // ringRad used to calculate other points
  55.      
  56.    // call function
  57.    drawring(ringRad);
  58.    
  59.  
  60.  }// end of set up
  61.  
  62.  // draw
  63.  void draw(){      
  64.    
  65.  // to use save option uncomment this and change path to own situation
  66.      /*
  67.      String humanName = "cubering"; // change this to a meaningful name
  68.      
  69.      // this then makes a unique filename with the date in a sortable order
  70.      // you can change the part at the end to jpg or tga or if you leave that out it will default to TIF
  71.      String fileName = "C:/Users/Karen/Documents/Processing/mySketches/CubeRing/"+humanName+"_"+year()+month()+day()+"_"+hour()+minute()+second()+".jpg";
  72.      
  73.      if (keyPressed == true && key == 's') {
  74.      
  75.       println("the filename is "+fileName);
  76.       save(fileName);  
  77.    
  78.      }// end of save
  79.      */
  80.  
  81.  }// end of draw
  82.  
  83.  
  84.  // function called drawring
  85.  
  86. void drawring (float R){
  87.  
  88.    // give some depth
  89.    noStroke();
  90.    fill(backcol,backtrans);
  91.    rect(-centreX, -centreY,width, height);    
  92.  
  93.    // setting up the points to draw the cube from
  94.    float a; // this is the length of the side of the hexagon/equilateral triangles
  95.    float r;// this is the horizontal distance from centre ring to edge of hexagon
  96.    float Ax,Bx,Cx,Dx,Ex,Fx,FAx,FBx,Px; // using points so can keep track of the geometry
  97.    float Ay,By,Cy,Dy,Ey,Fy,FAy,FBy,Py;
  98.    
  99.    r = R * cos(angle/2) ; // angle/2 = 15 Deg
  100.    
  101.    a = 2 * R * sin(angle/2) ; // calculating side of hexagon from radius of ring
  102.  
  103.    Ax = r + 0 ;
  104.    Px = Ax + 0.5*sqrt(3)*a ; // centre point of shape  
  105.    Bx = Ax ;
  106.    Cx = Px ;  
  107.    Dx = Ax + sqrt(3)*a ;
  108.    Ex = Dx ;
  109.    FAx = Ax + (3+sqrt(3))*0.25*a; ;
  110.    FBx = Ax + a;
  111.    Fx = Px ;
  112.    
  113.    Py = 0 ; // centre point of shape  
  114.    Ay = 0.5*a ;
  115.    By = -Ay ;
  116.    Cy = -a ;
  117.    Dy = By ;  
  118.    Ey = Ay ;
  119.    FAy = (5-sqrt(3))*0.25*a ;
  120.    FBy = Ay ;
  121.    Fy = -Cy ;
  122.    
  123.    // point to see centre of ring
  124.    //ellipse(centreX, centreY, 5, 5);
  125.    
  126.    // draw points so can see what doing
  127.    /*fill(0);
  128.    
  129.    ellipse(Ax, Ay, 5,5);
  130.    ellipse(bx, by, 5,5);
  131.    ellipse(cx, cy, 5,5);
  132.    ellipse(dx, dy, 5,5);
  133.    ellipse(ex, ey, 5,5);  
  134.    ellipse(fx, fy, 5,5);
  135.    ellipse(gx, gy, 5,5);
  136.    ellipse(hx, hy, 5,5);
  137.    ellipse(qx, qy, 5,5);
  138.    */
  139.  
  140.    for (float theta = 0; theta < TWO_PI*0.95 ; theta += angle) {
  141.      
  142.    pushMatrix();
  143.    rotate(theta);
  144.    
  145.    stroke(0);
  146.    strokeWeight(4);
  147.    strokeJoin(BEVEL);
  148.    fill(fillcol, 160);  // mid tone
  149.    beginShape();
  150.    vertex(Ax,Ay);
  151.    vertex(Bx, By);
  152.    vertex(Cx, Cy);
  153.    vertex(Px, Py);
  154.    endShape(CLOSE) ;  
  155.    
  156.    fill(fillcol, 80); // lightest
  157.    beginShape();
  158.    vertex(Px,Py);
  159.    vertex(Cx, Cy);
  160.    vertex(Dx, Dy);
  161.    vertex(Ex, Ey);
  162.    endShape(CLOSE) ;
  163.    
  164.    fill(fillcol, 255); // solid colour
  165.    beginShape();
  166.    vertex(Ax,Ay);
  167.    vertex(Px, Py);
  168.    vertex(Ex, Ey);
  169.    vertex(FAx, FAy);
  170.    vertex(FBx, FBy);
  171.    endShape(CLOSE) ;
  172.    
  173.    popMatrix();
  174.  
  175.  
  176.    }// end of for loop  
  177.  
  178. }// end of drawring function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement