Skip to content

Instantly share code, notes, and snippets.

@ajstarks
Created June 3, 2018 14:00
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 ajstarks/c0675b3fdfccd95f685097dd27987715 to your computer and use it in GitHub Desktop.
Save ajstarks/c0675b3fdfccd95f685097dd27987715 to your computer and use it in GitHub Desktop.
Generating the Gophercises certificate
package main
import (
"github.com/ajstarks/deck/generate"
"os"
"time"
)
type certdata struct {
student string
instructor string
date time.Time
}
const (
color1 = "rgb(122,84,102)"
color2 = "rgb(102,61,79)"
mid = 50.0
linelen = 30.0
top = 75.0
midy = 50.0
infoy = midy - 30
imy = 20.0
ll = 5.0
rl = ll + 60.0
ly = 18.0
)
func headfoot(deck *generate.Deck, hy, fy float64) {
xc := []float64{0, 100, 0}
yc := []float64{100, 100, hy}
// header
deck.Polygon(xc, yc, color1)
xc[2] = 100
deck.Polygon(xc, yc, color2)
// footer
xc[2] = 0
yc[0] = 0
yc[1] = 0
yc[2] = fy
deck.Polygon(xc, yc, color2)
xc[2] = 100
deck.Polygon(xc, yc, color1)
}
func makecert(deck *generate.Deck, data []certdata) {
for _, d := range data {
deck.StartSlide()
headfoot(deck, 90, 10)
body(deck, d)
deck.EndSlide()
}
}
func body(deck *generate.Deck, d certdata) {
deck.TextMid(mid, top, "Certificate of Completion", "serif", 6, "black")
deck.TextMid(mid, top-15, "This certificate is awarded to", "sans", 3, "black")
deck.TextMid(mid, midy, d.student, "serif", 4, color1)
deck.TextMid(mid, midy-10, "For successfully completing all twenty exercises in the\nGophercises Go programming course.", "sans", 3, "black")
deck.TextMid(20, infoy, d.date.Format("Jan _2, 2006"), "serif", 3, "gray")
deck.TextMid(20, infoy-5, "Date", "sans", 2, "gray")
deck.TextMid(80, infoy-5, "Instructor", "sans", 2, "gray")
deck.TextMid(80, midy-30, d.instructor, "serif", 3, "gray")
deck.Line(ll, ly, ll+linelen, ly, 0.1, "gray")
deck.Line(rl, ly, rl+linelen, ly, 0.1, "gray")
deck.Image(mid, imy, 125, 130, "gophercises_jumping.png", "https://gophercises.com/")
}
func main() {
today := time.Now()
data := []certdata{
{"Jon Calhoun", "Jonathan Calhoun", today},
{"Anthony Starks", "Jonathan Calhoun", today},
}
deck := generate.NewSlides(os.Stdout, 0, 0)
deck.StartDeck()
makecert(deck, data)
deck.EndDeck()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment