Skip to content

Instantly share code, notes, and snippets.

@rlieberman
Created October 15, 2014 13:09
Show Gist options
  • Save rlieberman/d4a3c828b303d911b4ff to your computer and use it in GitHub Desktop.
Save rlieberman/d4a3c828b303d911b4ff to your computer and use it in GitHub Desktop.
Hexagram h1;
void setup () {
size (600, 600);
h1 =new Hexagram (200, 200, 10);
}
void draw () {
background (255);
h1.display();
}
class Hexagram {
//pivot point is the top left corner of the whole hexagram
float pivotX;
float pivotY;
float lineWeight;
//broken or unbroken values stored for each line in the constructor
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, int (random(0,2)));
}
}
}
//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, int broken) {
//line styling
if (broken = 0) {
line (lineStartX, lineStartY, lineStartX+len, lineStartY);
}
if (broken = 1) {
//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