Skip to content

Instantly share code, notes, and snippets.

@tkob
Created August 2, 2014 10:02
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 tkob/a2b4d9c4aacfeb082891 to your computer and use it in GitHub Desktop.
Save tkob/a2b4d9c4aacfeb082891 to your computer and use it in GitHub Desktop.
import org.gicentre.handy.*;
import java.awt.Font;
import java.awt.font.FontRenderContext;
import java.awt.image.BufferedImage;
import java.awt.geom.PathIterator;
PathIterator createOutline(String name, int size, String text, float x, float y) {
FontRenderContext frc =
new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB)
.createGraphics()
.getFontRenderContext();
Font font = new Font(name, Font.PLAIN, size);
PathIterator iter = font.createGlyphVector(frc, text)
.getOutline(x, y)
.getPathIterator(null);
return iter;
}
HandyRenderer h;
void setup() {
size(640, 60);
smooth();
h = new HandyRenderer(this);
noLoop();
}
void draw() {
background(0xffffff);
noFill();
//drawNormally();
//draw2();
//draw3();
drawCurveClosed();
draw4();
//drawHandy();
}
void drawNormally() {
noFill();
PathIterator iter = createOutline("Segoe UI", 50, "wonderful cool something", 10, 40);
float coords[] = new float[6];
while (!iter.isDone()) {
int type = iter.currentSegment(coords);
switch (type) {
case PathIterator.SEG_MOVETO: // beginning of new path
beginShape();
vertex(coords[0], coords[1]);
break;
case PathIterator.SEG_LINETO:
vertex(coords[0], coords[1]);
break;
case PathIterator.SEG_CLOSE: // back to last MOVETO point.
endShape();
break;
case PathIterator.SEG_QUADTO:
quadraticVertex(coords[0], coords[1], coords[2], coords[3]);
break;
case PathIterator.SEG_CUBICTO:
bezierVertex(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]);
break;
default:
throw new RuntimeException("should not reach here");
}
iter.next();
}
}
void draw2() {
noFill();
PathIterator iter = createOutline("Segoe UI", 50, "wonderful cool something", 10, 40);
float coords[] = new float[6];
beginShape();
while (!iter.isDone()) {
int type = iter.currentSegment(coords);
switch (type) {
case PathIterator.SEG_MOVETO:
vertex(coords[0], coords[1]);
break;
case PathIterator.SEG_LINETO:
vertex(coords[0], coords[1]);
break;
case PathIterator.SEG_CLOSE:
break;
case PathIterator.SEG_QUADTO:
quadraticVertex(coords[0], coords[1], coords[2], coords[3]);
break;
case PathIterator.SEG_CUBICTO:
bezierVertex(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]);
break;
default:
throw new RuntimeException("should not reach here");
}
iter.next();
}
endShape();
}
void draw3() {
noFill();
stroke(#ff4a5d);
PathIterator iter = createOutline("Segoe UI", 50, "wonderful cool something", 10, 40);
float coords[] = new float[6];
beginShape();
boolean init = true;
while (!iter.isDone()) {
int type = iter.currentSegment(coords);
switch (type) {
case PathIterator.SEG_MOVETO:
if (init) vertex(coords[0], coords[1]);
init = false;
break;
case PathIterator.SEG_LINETO:
case PathIterator.SEG_CLOSE:
break;
case PathIterator.SEG_QUADTO:
quadraticVertex(coords[0], coords[1], coords[2], coords[3]);
break;
case PathIterator.SEG_CUBICTO:
bezierVertex(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]);
break;
default:
throw new RuntimeException("should not reach here");
}
iter.next();
}
endShape();
}
void draw4() {
noFill();
stroke(#6144b0);
PathIterator iter = createOutline("Segoe UI", 50, "wonderful cool something", 10, 40);
float coords[] = new float[6];
beginShape();
boolean init = true;
while (!iter.isDone()) {
int type = iter.currentSegment(coords);
switch (type) {
case PathIterator.SEG_MOVETO:
if (init) vertex(coords[0], coords[1]);
init = false;
break;
case PathIterator.SEG_LINETO:
vertex(coords[0], coords[1]);
break;
case PathIterator.SEG_CLOSE:
case PathIterator.SEG_QUADTO:
case PathIterator.SEG_CUBICTO:
break;
default:
throw new RuntimeException("should not reach here");
}
iter.next();
}
endShape();
}
void drawHandy() {
noFill();
stroke(#6144b0);
PathIterator iter = createOutline("Segoe UI", 50, "wonderful cool something", 10, 40);
float coords[] = new float[6];
h.beginShape();
boolean init = true;
while (!iter.isDone()) {
int type = iter.currentSegment(coords);
switch (type) {
case PathIterator.SEG_MOVETO:
if (init) h.vertex(coords[0], coords[1]);
init = false;
break;
case PathIterator.SEG_LINETO:
h.vertex(coords[0], coords[1]);
break;
case PathIterator.SEG_CLOSE:
case PathIterator.SEG_QUADTO:
case PathIterator.SEG_CUBICTO:
break;
default:
throw new RuntimeException("should not reach here");
}
iter.next();
}
h.endShape();
}
void drawCurveClosed() {
fill(#ff4a5d);
stroke(#ff4a5d);
PathIterator iter = createOutline("Segoe UI", 50, "wonderful cool something", 10, 40);
float coords[] = new float[6];
while (!iter.isDone()) {
int type = iter.currentSegment(coords);
switch (type) {
case PathIterator.SEG_MOVETO: // beginning of new path
beginShape();
vertex(coords[0], coords[1]);
break;
case PathIterator.SEG_LINETO:
//vertex(coords[0], coords[1]);
break;
case PathIterator.SEG_CLOSE: // back to last MOVETO point.
endShape();
break;
case PathIterator.SEG_QUADTO:
quadraticVertex(coords[0], coords[1], coords[2], coords[3]);
break;
case PathIterator.SEG_CUBICTO:
bezierVertex(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]);
break;
default:
throw new RuntimeException("should not reach here");
}
iter.next();
}
}
void mousePressed() {
selectInput("Select a file:", "fileSelected");
}
void fileSelected(File file) throws IOException {
if (file == null) return;
save(file.getCanonicalPath());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment