Skip to content

Instantly share code, notes, and snippets.

@rlieberman
Created October 21, 2014 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlieberman/e7b477f846e680fa9bc8 to your computer and use it in GitHub Desktop.
Save rlieberman/e7b477f846e680fa9bc8 to your computer and use it in GitHub Desktop.
Hexagram h1;
void setup () {
size (600, 400);
h1 =new Hexagram (220, 150, 10);
}
void draw () {
background (0);
h1.display();
}
void mousePressed() {
h1.change();
}
class Hexagram {
//3 variables for drawing a hexagram: pivot X, pivot Y and line weight
//pivot point is the top left corner of the whole hexagram
//hexagram has: a pivot X, a pivot Y, a line weight, and a set of 0's and 1's that determine the configuration
//randomizer array is part of the data of the object, it is a list of values, 1 for each line
float pivotX;
float pivotY;
float lineWeight;
int[] randomizer = new int[6];
float spacing;
Hexagram (float temppivotX, float temppivotY, float templineWeight) {
pivotX = temppivotX;
pivotY = temppivotY;
lineWeight = templineWeight;
spacing = lineWeight*2;
//LOOP: for every row of the hexagram, pick a 0 or 1 to determine if it's broken or unbroken
//put this in the constructor -- it's the setup of the object
//if it's in draw the changes will animate
for (int i = 0; i < randomizer.length; i++) {
randomizer[i] = int(random(0, 2));
}
}
void myline (float lineStartX, float lineStartY, float lineLength, int broken) {
//myline is a function for drawing a SINGLE line that is either broken or unbroken
//this then gets passed into the display function to make an entire hexagram
//line styling\
if (broken == 0) {
line (lineStartX, lineStartY, lineStartX+lineLength, lineStartY);
}
if (broken == 1) {
//first line
line (lineStartX, lineStartY, lineStartX+lineLength/2 - spacing, lineStartY);
//second line
line (lineStartX+lineLength/2 +spacing, lineStartY, lineStartX+lineLength, lineStartY);
}
}
void change() {
//change the hexagram configuration when you click the mouse using the randomizer array
for (int i = 0; i < randomizer.length; i++) {
randomizer[i] = int(random(0, 2));
}
}
void display (){
//display the line -- includes all styling
float lineLength = (lineWeight*6) + (spacing*4);
//draw the hexagram using variables!!!!
strokeCap (SQUARE);
stroke (255);
strokeWeight (lineWeight);
//setting the configuration of broken and unbroken lines randomly
for (int i = 0; i < 6; i++) {
myline(pivotX, pivotY+i*spacing, lineLength, randomizer[i]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment