Skip to content

Instantly share code, notes, and snippets.

@rlieberman
Last active August 29, 2015 14:07
Show Gist options
  • Save rlieberman/ee0f34a3823e0cc60dd1 to your computer and use it in GitHub Desktop.
Save rlieberman/ee0f34a3823e0cc60dd1 to your computer and use it in GitHub Desktop.
IChing_Step2_HexagramArrays
int num = 6;
Hexagram [] hexagrams = new Hexagram [num];
Hexagram h1;
void setup () {
size (600, 300);
int xspacing = 100;
for (int i = 0; i < hexagrams.length; i++) {
hexagrams [i] = new Hexagram (10+i*xspacing, height/2-50, 5);
}
}
void draw () {
background (255);
for (int i = 0; i < hexagrams.length; i++) {
hexagrams[i].display ();
}
}
class Hexagram {
//pivot point is the top left corner of the whole hexagram
float pivotX;
float pivotY;
float lineWeight;
// I'm a little bit confused as to how I'm using the array here, since I'm not declaring it in the way I saw in the book.
// Am I using an array here as a variable that stores 6 values? A little bit confused about syntax
boolean[] configuration = {true, false,false,true,false,false,true};
Hexagram (float temppivotX, float temppivotY, float templineWeight) {
pivotX = temppivotX;
pivotY = temppivotY;
lineWeight = templineWeight;
}
void display () {
float spacing = lineWeight*2;
float lineLength = (lineWeight*6) + (spacing*4);
//draw the hexagram using variables!!!!
strokeCap (SQUARE);
stroke (0);
strokeWeight (lineWeight);
for (int i = 0; i < 6; i++) {
myline(pivotX, pivotY+i*spacing, lineLength, configuration[i]);
}
}
}
//myline is a function for drawing a single line -- we want to pass this into the object
void myline (float lineStartX, float lineStartY, float len, boolean broken) {
//line styling
if (!broken) {
line (lineStartX, lineStartY, lineStartX+len, lineStartY);
}
else {
//first line
line (lineStartX, lineStartY, lineStartX+len/2 - 10, lineStartY);
//second line
//how do i pass a variable from the object into this function? always want the two lines to be separated by the line weight, which gets declared and initialized in the object
line (lineStartX+len/2 +10, lineStartY, lineStartX+len, lineStartY);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment