Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* CUBE RING
- * Inspired by an image from tumblr
- * http://regolo54.tumblr.com/post/121360473702
- *
- * CC-BY 4.0 Karen Cropper
- * October 2015
- * Larger scale 1600px greyscale
- */
- // global variables
- float centreX, centreY; // centre of circle
- float margin;
- float angle = PI/6;
- float ringRad;
- int fillcol = 100; // greyscale version
- int backcol = 240; // background colour
- int backtrans = 60; // amount of transparency for depth
- // set up
- void setup(){
- size(1600,1600);
- background(backcol);
- margin = -width/50;
- centreX = width/2;
- centreY = height/2;
- // move to centre point
- translate(centreX, centreY);
- /* *\
- * draw smallest ring *
- \* */
- ringRad = 0.9*0.25*(width-(2*margin))/4; // ringRad used to calculate other points
- // call function
- drawring(ringRad);
- /* *\
- * draw middle ring *
- \* */
- ringRad = 0.98*0.5*(width-(2*margin))/4; // ringRad used to calculate other points
- // call function
- drawring(ringRad);
- /* *\
- * draw outer ring *
- \* */
- ringRad = (width-(2*margin))/4; // ringRad used to calculate other points
- // call function
- drawring(ringRad);
- }// end of set up
- // draw
- void draw(){
- // to use save option uncomment this and change path to own situation
- /*
- String humanName = "cubering"; // change this to a meaningful name
- // this then makes a unique filename with the date in a sortable order
- // you can change the part at the end to jpg or tga or if you leave that out it will default to TIF
- String fileName = "C:/Users/Karen/Documents/Processing/mySketches/CubeRing/"+humanName+"_"+year()+month()+day()+"_"+hour()+minute()+second()+".jpg";
- if (keyPressed == true && key == 's') {
- println("the filename is "+fileName);
- save(fileName);
- }// end of save
- */
- }// end of draw
- // function called drawring
- void drawring (float R){
- // give some depth
- noStroke();
- fill(backcol,backtrans);
- rect(-centreX, -centreY,width, height);
- // setting up the points to draw the cube from
- float a; // this is the length of the side of the hexagon/equilateral triangles
- float r;// this is the horizontal distance from centre ring to edge of hexagon
- float Ax,Bx,Cx,Dx,Ex,Fx,FAx,FBx,Px; // using points so can keep track of the geometry
- float Ay,By,Cy,Dy,Ey,Fy,FAy,FBy,Py;
- r = R * cos(angle/2) ; // angle/2 = 15 Deg
- a = 2 * R * sin(angle/2) ; // calculating side of hexagon from radius of ring
- Ax = r + 0 ;
- Px = Ax + 0.5*sqrt(3)*a ; // centre point of shape
- Bx = Ax ;
- Cx = Px ;
- Dx = Ax + sqrt(3)*a ;
- Ex = Dx ;
- FAx = Ax + (3+sqrt(3))*0.25*a; ;
- FBx = Ax + a;
- Fx = Px ;
- Py = 0 ; // centre point of shape
- Ay = 0.5*a ;
- By = -Ay ;
- Cy = -a ;
- Dy = By ;
- Ey = Ay ;
- FAy = (5-sqrt(3))*0.25*a ;
- FBy = Ay ;
- Fy = -Cy ;
- // point to see centre of ring
- //ellipse(centreX, centreY, 5, 5);
- // draw points so can see what doing
- /*fill(0);
- ellipse(Ax, Ay, 5,5);
- ellipse(bx, by, 5,5);
- ellipse(cx, cy, 5,5);
- ellipse(dx, dy, 5,5);
- ellipse(ex, ey, 5,5);
- ellipse(fx, fy, 5,5);
- ellipse(gx, gy, 5,5);
- ellipse(hx, hy, 5,5);
- ellipse(qx, qy, 5,5);
- */
- for (float theta = 0; theta < TWO_PI*0.95 ; theta += angle) {
- pushMatrix();
- rotate(theta);
- stroke(0);
- strokeWeight(4);
- strokeJoin(BEVEL);
- fill(fillcol, 160); // mid tone
- beginShape();
- vertex(Ax,Ay);
- vertex(Bx, By);
- vertex(Cx, Cy);
- vertex(Px, Py);
- endShape(CLOSE) ;
- fill(fillcol, 80); // lightest
- beginShape();
- vertex(Px,Py);
- vertex(Cx, Cy);
- vertex(Dx, Dy);
- vertex(Ex, Ey);
- endShape(CLOSE) ;
- fill(fillcol, 255); // solid colour
- beginShape();
- vertex(Ax,Ay);
- vertex(Px, Py);
- vertex(Ex, Ey);
- vertex(FAx, FAy);
- vertex(FBx, FBy);
- endShape(CLOSE) ;
- popMatrix();
- }// end of for loop
- }// end of drawring function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement