Skip to content

3 more translations #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
// This sketch is part of the ReCode Project - http://recodeproject.com
// From Computer Graphics and Art vol1 no4 pg 6
// Generative Drawings
// by Manfred Mohr
//
// Quin Kennedy
// 2012
// Creative Commons license CC BY-SA 3.0
static final int cellWidth = 30;
static final int boxSize = 7;
static int numEdges = 9;
static final int cubeEdges = 12;
static final int numUnique = factorial(cubeEdges)/(factorial(numEdges)*factorial(cubeEdges-numEdges));
static final int numCellsWide = ceil(sqrt(numUnique));
static final int gutterWidth = 10;
static final int canvasWidth = numCellsWide*cellWidth+gutterWidth*2;
static final boolean showMirror = true;
static final boolean closerMatch = true;

public static final int factorial(int n){
int output = 1;
for(;n>0; n--){
output *= n;
}
return output;
}

void setup(){
size(canvasWidth * (showMirror ? 2 : 1), canvasWidth, P3D);
noLoop();
}

void draw(){
background(0);
noFill();
stroke(255);
strokeWeight(1.5);
ortho();
drawGrid();
drawSet();
if (showMirror){
translate(width/2, 0, 0);
drawGrid();
numEdges = cubeEdges-numEdges;
drawSet();
}
}

void drawSet(){
pushMatrix();
int currCubeEdges = (closerMatch ? initCubeFlags() : 0);
float rX = PI/3;//random(TWO_PI);
float rY = 0;//random(TWO_PI);
float rZ = PI*2/3;//random(TWO_PI);
translate(gutterWidth+cellWidth/2., numCellsWide*cellWidth+gutterWidth-cellWidth/2., 0);
for(int i = 0; i < numCellsWide; i++){
pushMatrix();
for(int j = 0; j < numCellsWide; j++){
pushMatrix();
rotateX(rX);
rotateY(rY);
rotateZ(rZ);
scale(boxSize);
if (closerMatch){
drawCube(currCubeEdges);
currCubeEdges = getNextCube(currCubeEdges);
} else {
for(;currCubeEdges <= 0xfff; currCubeEdges++){
if (numFlags(currCubeEdges) == numEdges){
drawCube(currCubeEdges);
currCubeEdges++;
break;
}
}
}
popMatrix();
translate(0, -cellWidth, 0);
}
popMatrix();
translate(cellWidth, 0, 0);
}
popMatrix();
}

int numFlags(int f){
int output = 0;
while(f > 0){
if ((f & 1) == 1){
output++;
}
f >>= 1;
}
return output;
}

void drawGrid(){
int currX = gutterWidth;
for(int i = 0; i <= numCellsWide; i++, currX += cellWidth){
line(currX, gutterWidth, currX, numCellsWide*cellWidth+gutterWidth);
line(gutterWidth, currX, numCellsWide*cellWidth+gutterWidth, currX);
}
}

int initCubeFlags(){
int firstFlags = 0;
for(int i = 0; i < numEdges; i++){
firstFlags <<= 1;
firstFlags++;
}
return firstFlags;
}

int getNextCube(int sideFlags){
return incrementFlags(sideFlags, cubeEdges-1);
}

int incrementFlags(int sideFlags, int lastValidIndex){
int myMask = 1;
int bitMask = 1;
for(int i = 1; i <= lastValidIndex; i++){
bitMask <<= 1;
myMask <<= 1;
myMask++;
}
if ((sideFlags & bitMask) > 1){
//if there are no flags below us, we are done, return 0;
if ((sideFlags & (myMask >> 1)) == 0){
return 0;
}
//move the flags below us
int nextFlags = incrementFlags(sideFlags, lastValidIndex-1);
//if we receive 0, we are done with the whole series
if (nextFlags == 0){
return 0;
}
//otherwise reset our flag to directly after theirs
while(bitMask > 0 && (nextFlags & (bitMask >> 1)) == 0){
bitMask >>= 1;
}
return (nextFlags | bitMask);
} else {
//move this flag up by one position
//find where the flag is
while(bitMask > 0 && (sideFlags & (bitMask >> 1)) == 0){
bitMask >>= 1;
}
//mask my section, remove the current flag and add the new flag
return (((sideFlags & myMask) ^ (bitMask >> 1)) | bitMask);
}
}

void drawCube(int sideFlags){
if (closerMatch){
if ((sideFlags & 0x1) != 0){
line(1, -1, -1, 1, 1, -1);
}
if ((sideFlags & 0x2) != 0){
line(1, 1, 1, 1, -1, 1);
}
if ((sideFlags & 0x4) != 0){
line(-1, -1, 1, -1, 1, 1);
}
if ((sideFlags & 0x8) != 0){
line(-1, -1, -1, 1, -1, -1);
}
if ((sideFlags & 0x10) != 0){
line(1, -1, -1, 1, -1, 1);
}
if ((sideFlags & 0x20) != 0){
line(-1, -1, 1, 1, -1, 1);
}
if ((sideFlags & 0x40) != 0){
line(-1, -1, -1, -1, -1, 1);
}
if ((sideFlags & 0x80) != 0){
line(-1, -1, -1, -1, 1, -1);
}
if ((sideFlags & 0x100) != 0){
line(-1, 1, -1, 1, 1, -1);
}
if ((sideFlags & 0x200) != 0){
line(1, 1, 1, 1, 1, -1);
}
if ((sideFlags & 0x400) != 0){
line(1, 1, 1, -1, 1, 1);
}
if ((sideFlags & 0x800) != 0){
line(-1, 1, -1, -1, 1, 1);
}
} else {
if ((sideFlags & 0x1) != 0){
line(-1, -1, -1, -1, -1, 1);
}
if ((sideFlags & 0x2) != 0){
line(-1, -1, -1, -1, 1, -1);
}
if ((sideFlags & 0x4) != 0){
line(-1, -1, -1, 1, -1, -1);
}
if ((sideFlags & 0x8) != 0){
line(1, 1, 1, 1, 1, -1);
}
if ((sideFlags & 0x10) != 0){
line(1, 1, 1, 1, -1, 1);
}
if ((sideFlags & 0x20) != 0){
line(1, 1, 1, -1, 1, 1);
}
if ((sideFlags & 0x40) != 0){
line(-1, -1, 1, 1, -1, 1);
}
if ((sideFlags & 0x80) != 0){
line(-1, -1, 1, -1, 1, 1);
}
if ((sideFlags & 0x100) != 0){
line(-1, 1, -1, 1, 1, -1);
}
if ((sideFlags & 0x200) != 0){
line(-1, 1, -1, -1, 1, 1);
}
if ((sideFlags & 0x400) != 0){
line(1, -1, -1, 1, 1, -1);
}
if ((sideFlags & 0x800) != 0){
line(1, -1, -1, 1, -1, 1);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// This sketch is part of the ReCode Project - http://recodeproject.com
// From Computer Graphics and Art vol3 no1 pg 9
// P-196A
// by Manfred Mohr
//
// Quin Kennedy
// 2012
// Creative Commons license CC BY-SA 3.0
static final int boxSize = 300;
static final int canvasSize = 600;

void setup(){
size(canvasSize, canvasSize, P2D);
noLoop();
}

void draw(){
translate(width/2, height/2, 0);
PGraphics topLight = createGraphics(width, height, P3D);
PGraphics bottomLight = createGraphics(width, height, P3D);
PGraphics topHeavy = createGraphics(width, height, P3D);
PGraphics bottomHeavy = createGraphics(width, height, P3D);
float rX = random(TWO_PI);
float rY = random(TWO_PI);
float rZ = random(TWO_PI);
drawBox(topLight, rX, rY, rZ, 1, 255);
drawBox(topHeavy, rX, rY, rZ, 4, 252);
rX = random(TWO_PI);
rY = random(TWO_PI);
rZ = random(TWO_PI);
drawBox(bottomLight, rX, rY, rZ, 1, 255);
drawBox(bottomHeavy, rX, rY, rZ, 4, 252);

copy(topLight, 0, 0, width, height/2, 0, 0, width, height/2);
copy(bottomLight, 0, height/2, width, height/2, 0, height/2, width, height/2);
int pX = (width-boxSize)/2;
int pY = (height-boxSize)/2;
int cW = boxSize;
int cH = boxSize/2;
copy(topHeavy, pX, pY, cW, cH, pX, pY, cW, cH);
pY += boxSize/2;
copy(bottomHeavy, pX, pY, cW, cH, pX, pY, cW, cH);
line(0, height/2, width, height/2);
}

void drawBox(PGraphics g, float rotX, float rotY, float rotZ, float weight, int backgroundColor){
g.beginDraw();
g.ortho();
g.translate(width/2, height/2, 0);
g.rotateX(rotX);
g.rotateY(rotY);
g.rotateZ(rotZ);
g.background(backgroundColor);
g.stroke(0);
g.strokeWeight(weight);
g.noFill();
g.box(boxSize);
g.endDraw();
}
Loading