Skip to content

Instantly share code, notes, and snippets.

@julians
Created June 30, 2011 17:40
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 julians/1056750 to your computer and use it in GitHub Desktop.
Save julians/1056750 to your computer and use it in GitHub Desktop.
3D-Buchstabe mit geomerative
// Hier wird bloß ein Buchstabe gezeichnet,
// man kann aber auch relativ einfach ganze Wörter zeichnen,
// steht alles größtenteils in den Beispielen von geomerative
import processing.opengl.*;
import geomerative.*;
RFont font;
RShape shape;
RPoint[][] points;
RMesh mesh;
float spin = 0.0;
char c = 'Q';
float thickness = 20;
int fontSize = 192;
void setup()
{
size(600, 400, OPENGL);
colorMode(HSB, 360, 100, 100);
smooth();
noStroke();
RG.init(this);
// verschiedene Optionen, die TrueType-Outlines in einen Pfad umzuwandeln.
// Je genauer die Umwandlung, desto langsamer der Sketch (bei vielen Buchstaben)
// In der Dokumentation steht beschrieben, was was macht
//RCommand.setSegmentator(RCommand.ADAPTATIVE);
//RCommand.setSegmentAngle(HALF_PI/10);
RCommand.setSegmentator(RCommand.UNIFORMSTEP);
RCommand.setSegmentStep(10);
// Schrift einlesen
// (Da muss man halt irgendeine TrueType-Schrift in den data-Ordner kopieren.)
font = new RFont("lucon.ttf", fontSize, RFont.CENTER);
font.setAlign(RFont.CENTER);
font.setSize(fontSize);
// Schrift in Punkte umwandeln. Das nur ein Mal tun und nicht jedes Mal,
// wenn man die Schrift zeichnen muss, weil’s sonst um einiges langsamer ist.
shape = font.toShape(c);
mesh = shape.toMesh();
points = shape.getPointsInPaths();
}
void draw()
{
// Das hier setzt nur Lichter und dreht den Sketch
background(360, 0, 50);
lights();
spin -= 0.025;
pushMatrix();
translate(width/2,height/2+fontSize/2, 0);
rotateX(PI/9);
rotateY(PI/5 + spin);
fill(360, 100, 100);
// Die Punkte durchgehen und die Seiten des Buchstabens zeichnen
for (int i = 0; i < points.length; i++) {
beginShape(QUAD_STRIP);
for (int ii = 0; ii < points[i].length; ii++)
{
vertex(points[i][ii].x, points[i][ii].y, 0);
vertex(points[i][ii].x, points[i][ii].y, thickness);
}
endShape(CLOSE);
}
// Vorderseite zeichnen
mesh.draw();
// Genau um die Dicke des Buchstabens zurückgehen
translate(0, 0, thickness);
// Rückseite zeichnen
mesh.draw();
popMatrix();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment