Skip to content

Instantly share code, notes, and snippets.

@CSchoel
Created January 27, 2015 13:09
Show Gist options
  • Save CSchoel/c41fe59865fbf3162bc7 to your computer and use it in GitHub Desktop.
Save CSchoel/c41fe59865fbf3162bc7 to your computer and use it in GitHub Desktop.
Generates the THM logo by faculty and location numbers.
//Autor: Christopher Schölzel
color THMGreen = color(128,186,36);
color THMGray = color(74,92,102);
float boxHeight = 15; //größe einer einzelnen Box im Fenster
int fachbereich = 6; //Fachbereichsnummer
int standort = 1; //Standortnummer
void setup() {
size(500,200);
noLoop();
background(255);
}
//wandelt dezimalzahl in binärzahl mit angegebener anzahl ziffern an
int[] dez2bin(int dez, int digits) {
int[] bin = new int[digits];
int tmp = dez;
for(int i = digits-1; i >= 0; i--) {
bin[i] = tmp % 2;
tmp /= 2;
}
return bin;
}
//zeichnet binärziffern als säule von Boxen
void drawDigits(int[] digits, float x, float y) {
y += boxHeight*1.5*(4-digits.length);
for(int digit : digits) {
fill(digit == 1 ? THMGreen : THMGray);
rect(x,y,boxHeight,boxHeight);
y += boxHeight*1.5;
}
}
void draw() {
noStroke();
int[] fb1 = dez2bin(fachbereich/10,4);
int[] fb2 = dez2bin(fachbereich%10,4);
int[] std = dez2bin(standort,3);
float topY = boxHeight*4;
float currentX = boxHeight*4;
float totalHeight = boxHeight*5.5;
float bottomY = topY+totalHeight;
//Boxen
drawDigits(std,currentX,topY);
currentX += boxHeight*1.5;
drawDigits(fb1,currentX,topY);
currentX += boxHeight*1.5;
drawDigits(fb2,currentX,topY);
stroke(THMGray);
strokeWeight(2);
currentX += boxHeight*3;
//Linie
line(currentX,bottomY,currentX,topY);
currentX += boxHeight*2;
noStroke();
fill(THMGreen);
//T
rect(currentX,topY,boxHeight*4,boxHeight);
currentX += boxHeight*1.5;
rect(currentX,topY,boxHeight,totalHeight);
currentX += boxHeight*3.5;
//H
rect(currentX,topY,boxHeight,totalHeight);
rect(currentX,bottomY-boxHeight*3.5,boxHeight*4,boxHeight);
currentX += boxHeight*3;
rect(currentX,topY,boxHeight,totalHeight);
currentX += boxHeight*2;
//M
rect(currentX,topY,boxHeight,totalHeight);
quad(
currentX+boxHeight,topY,
currentX,topY,
currentX+boxHeight*2,bottomY-boxHeight,
currentX+boxHeight*3,bottomY-boxHeight
);
quad(
currentX+boxHeight*5,topY,
currentX+boxHeight*4,topY,
currentX+boxHeight*2,bottomY-boxHeight,
currentX+boxHeight*3,bottomY-boxHeight
);
currentX += boxHeight*4;
rect(currentX,topY,boxHeight,totalHeight);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment