Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Re : making a pdf-file

$
0
0
Good one GoToLoop! Never new of beginRaw() before,  but it does the job perfectly:


also scales perfectly:



so the code could be found on github:

  1. import processing.pdf.*;

  2. /* 
  3. Part of the ReCode Project (http://recodeproject.com)
  4. Based on "Cube Limit Series - Inward" by Manfred Mohr
  5. Originally published in "Computer Graphics and Art" vol1 no2, 1976
  6. Copyright (c) 2012 Calvin Hu - OSI/MIT license (http://recodeproject/license).
  7. */

  8. int offset = 30;
  9. int interval = 30;
  10. int[] bitPositions = {0, 1, 2, 3, 4, 5, 12};
  11. boolean[] permutation = {true,true,true,true,true,true,false,false,false,false,false,false};

  12. void draw_cube(int slength, boolean[] permutation){
  13.   int side = slength/2;
  14.   int start_point = -side;
  15.   if(permutation[0])
  16.     line(start_point, start_point, start_point, start_point, start_point, side);
  17.   if(permutation[1])
  18.     line(start_point, start_point, start_point, start_point, side, start_point);
  19.   if(permutation[2])
  20.     line(start_point, start_point, start_point, side, start_point, start_point);
  21.   if(permutation[3])
  22.     line(start_point, start_point, side, start_point, side, side);
  23.   if(permutation[4])
  24.     line(start_point, start_point, side, side, start_point, side);
  25.   if(permutation[5])
  26.     line(start_point, side, start_point, side, side, start_point);
  27.   if(permutation[6])
  28.     line(start_point, side, start_point, start_point, side, side);
  29.   if(permutation[7])
  30.     line(side, start_point, start_point, side, side, start_point);
  31.   if(permutation[8])
  32.     line(side, start_point, start_point, side, start_point, side);
  33.   if(permutation[9])  
  34.     line(side, side, start_point, side, side, side);
  35.   if(permutation[10])
  36.     line(side, start_point, side, side, side, side);
  37.   if(permutation[11])
  38.     line(start_point, side, side, side, side, side);
  39. }

  40. boolean[] swap_boolean_array(boolean[] boolArr, int indexFrom, int indexTo){
  41.   boolean temp = boolArr[indexTo];
  42.   boolArr[indexTo] = boolArr[indexFrom];
  43.   boolArr[indexFrom] = temp;
  44.   return boolArr;
  45. }

  46. boolean nextPermutation(){
  47.    for(int i = 5; i >= 0; i--){
  48.      if(bitPositions[i] + 1 < bitPositions[i + 1]){
  49.        permutation = swap_boolean_array(permutation, bitPositions[i], ++bitPositions[i]);
  50.        if(i < 5){
  51.          for(int j = i + 1 ; j < 6; j++){
  52.            permutation = swap_boolean_array(permutation, bitPositions[j], bitPositions[j - 1] + 1);
  53.            bitPositions[j] = bitPositions[j - 1] + 1;
  54.          } 
  55.        }
  56.        return true;
  57.      }
  58.    }
  59.    return false;
  60. }



  61. void setup(){
  62.     size(990, 990, P3D);
  63.     beginRaw(PDF, "something.pdf");
  64.     ortho();
  65.     //background(0); // this won't work in PDF, you need draw black rect istead
  66.     fill(0); 
  67.     rect(0,0, width, height);
  68.     
  69.     noFill();
  70.     stroke(255);
  71.     for(int i = 0; i < 32; i++){
  72.       int columnX = offset + i * interval;
  73.       line(columnX, offset, columnX, height - offset);
  74.     }
  75.     for(int i = 0; i < 32; i++){
  76.       int rowY = offset + i * interval;
  77.       line(offset, rowY, width - offset, rowY);
  78.     }
  79.     
  80.     
  81.     boolean anyPermsLeft = true;
  82.     pushMatrix();
  83.     translate(32 * interval + offset/2, offset/2);
  84.     for(int i = 0; i < 31 & anyPermsLeft; i++){
  85.       translate(-interval, 0);
  86.       pushMatrix();
  87.       for(int j = 0; j < 31 & anyPermsLeft; j++){
  88.           translate(0, interval);
  89.           pushMatrix();
  90.           rotateX(PI * 5/6);
  91.           rotateY(PI * -5/6);
  92.           draw_cube(15, permutation);
  93.           anyPermsLeft = nextPermutation();
  94.           popMatrix();
  95.       }
  96.       popMatrix();
  97.     }
  98.     popMatrix();
  99.     
  100.     endRaw();
  101. }

  102. void draw(){
  103. }

lines in bold red are the lines added to the original sketch

Viewing all articles
Browse latest Browse all 1768

Trending Articles