-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jonathan Feinberg
committed
Jun 21, 2015
0 parents
commit 88b2ac1
Showing
4 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
helloworld.png | ||
|
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package main | ||
|
||
import ( | ||
"image" | ||
"image/color" | ||
"log" | ||
"math" | ||
|
||
"github.com/jdf/filmore" | ||
"github.com/llgcode/draw2d" | ||
) | ||
|
||
const ( | ||
fontSize = 64 | ||
width = 700 | ||
height = 380 | ||
|
||
fontPath = "BebasNeue Bold.ttf" | ||
//fontPath = "alpha_echo.ttf" | ||
) | ||
|
||
var ( | ||
text = []string{"Absinthe", "Makes", "The heart", "Grow flounder"} | ||
) | ||
|
||
func main() { | ||
font, err := filmore.NewFontFromFile(fontPath, fontSize) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
// Initialize the graphic context on an RGBA image | ||
img := image.NewRGBA(image.Rect(0, 0, width, height)) | ||
gc := draw2d.NewGraphicContext(img) | ||
|
||
// Draw a rounded rectangle using default colors | ||
draw2d.RoundRect(gc, 5, 5, width-5, height-5, 10, 10) | ||
gc.FillStroke() | ||
|
||
gc.SetStrokeColor(image.Black) | ||
gc.SetFillColor(color.RGBA{0, 255, 0, 255}) | ||
|
||
// Warp function | ||
f := func(x, y float64) (nx, ny float64) { | ||
xMag := x / 30 | ||
mid := height / 2.0 | ||
yMag := 1.25 * math.Abs(y-mid) / mid | ||
nx = x + xMag*yMag*math.Cos(x/25.0) | ||
ny = y + xMag*yMag*math.Sin(x/20.0) | ||
return | ||
} | ||
|
||
doPath := func(p filmore.TextPath) { | ||
for _, op := range p.PathOps { | ||
tx, ty := f(op.X(), op.Y()) | ||
switch op := op.(type) { | ||
case filmore.MoveTo: | ||
gc.MoveTo(tx, ty) | ||
case filmore.LineTo: | ||
gc.LineTo(tx, ty) | ||
case filmore.QuadCurveTo: | ||
tcx, tcy := f(op.ControlX(), op.ControlY()) | ||
gc.QuadCurveTo(tx, ty, tcx, tcy) | ||
} | ||
} | ||
} | ||
|
||
spacing := fontSize * 1.3 | ||
y := 12 + spacing | ||
for _, s := range text { | ||
p := font.CreateTextPath(s, 20, y) | ||
doPath(p) | ||
gc.Fill() | ||
doPath(p) | ||
gc.Stroke() | ||
y += spacing | ||
} | ||
// Save to png | ||
draw2d.SaveToPngFile("helloworld.png", img) | ||
} |