home.gno

3.32 Kb ยท 149 lines
  1package home
  2
  3import (
  4	"std"
  5	"strconv"
  6
  7	"gno.land/p/demo/svg"
  8	"gno.land/p/demo/ufmt"
  9	"gno.land/p/moul/md"
 10
 11	"gno.land/r/demo/art/gnoface"
 12	"gno.land/r/demo/art/millipede"
 13	"gno.land/r/demo/mirror"
 14	"gno.land/r/leon/config"
 15	"gno.land/r/leon/hor"
 16)
 17
 18var (
 19	pfp        string // link to profile picture
 20	pfpCaption string // profile picture caption
 21	abtMe      [2]string
 22)
 23
 24func Render(_ string) string {
 25	out := "# Leon's Homepage\n\n"
 26
 27	out += renderAboutMe()
 28	out += renderArt()
 29	out += config.Banner()
 30
 31	return out
 32}
 33
 34func init() {
 35	hor.Register(cross, "Leon's Home Realm", "")
 36	mirror.Register(std.CurrentRealm().PkgPath(), Render)
 37
 38	pfp = "https://i.imgflip.com/91vskx.jpg"
 39	pfpCaption = "[My favourite painting & pfp](https://en.wikipedia.org/wiki/Wanderer_above_the_Sea_of_Fog)"
 40	abtMe = [2]string{
 41		`### About me
 42Hi, I'm Leon, a DevRel Engineer at gno.land. I am a tech enthusiast, 
 43life-long learner, and sharer of knowledge.`,
 44		`### Contributions
 45My contributions to gno.land can mainly be found 
 46[here](https://github.com/gnolang/gno/issues?q=sort:updated-desc+author:leohhhn).
 47
 48TODO import r/gh`,
 49	}
 50}
 51
 52func UpdatePFP(cur realm, url, caption string) {
 53	if !config.IsAuthorized(std.PreviousRealm().Address()) {
 54		panic(config.ErrUnauthorized)
 55	}
 56
 57	pfp = url
 58	pfpCaption = caption
 59}
 60
 61func UpdateAboutMe(cur realm, col1, col2 string) {
 62	if !config.IsAuthorized(std.PreviousRealm().Address()) {
 63		panic(config.ErrUnauthorized)
 64	}
 65
 66	abtMe[0] = col1
 67	abtMe[1] = col2
 68}
 69
 70func renderAboutMe() string {
 71	return md.Columns([]string{
 72		ufmt.Sprintf("![my profile pic](%s)\n\n%s\n", pfp, pfpCaption),
 73		abtMe[0],
 74		abtMe[1],
 75	})
 76}
 77
 78func renderArt() string {
 79	out := "# Gno Art\n"
 80
 81	out += md.Columns([]string{
 82		gnoface.Render(strconv.Itoa(int(std.ChainHeight()))),
 83		renderMillipede(),
 84		"SVG Gnome\n" + RenderSVGGnome(),
 85	})
 86
 87	out += "This art is dynamic; it will change with every new block.\n\n"
 88
 89	return out
 90}
 91
 92func renderMillipede() string {
 93	out := "Millipede\n\n"
 94	out += "```\n" + millipede.Draw(int(std.ChainHeight())%10+1) + "```\n"
 95	return out
 96}
 97
 98func renderBlogPosts() string {
 99	out := ""
100	// out += "## Leon's Blog Posts"
101
102	// todo fetch blog posts authored by @leohhhn
103	// and render them
104	return out
105}
106
107func RenderSVGGnome() string { // exported for your pleasure :)
108	c := svg.NewCanvas(430, 430).WithViewBox(13, 25, 75, 75)
109
110	// Body: blue triangle
111	body := svg.NewPolygon("50,50 30,100 70,100", gnomeBodyColors[int(std.ChainHeight())%len(gnomeBodyColors)])
112
113	// Head: peach circle (overlaps body)
114	head := svg.NewCircle(50, 60, 10, "#FAD7B6")
115
116	// Hat: red triangle on top of head
117	hat := svg.NewPolygon("50,30 35,55 65,55", "#E53935")
118
119	// Eyes: two small black dots
120	leftEye := svg.NewCircle(46, 59, 1, "#000")
121	rightEye := svg.NewCircle(54, 59, 1, "#000")
122
123	// Beard: small white triangle under head
124	beard := svg.NewPolygon("50,85 42,63 58,63", "#FFF")
125
126	// Layering order matters (bottom to top)
127	c.Append(body, head, beard, hat, leftEye, rightEye)
128
129	return c.Render("svg gnome")
130}
131
132var gnomeBodyColors = []string{
133	"#4CAF50", // Green
134	"#2196F3", // Blue
135	"#9C27B0", // Purple
136	"#FF5722", // Orange
137	"#795548", // Brown
138	"#607D8B", // Grayish Blue
139	"#E91E63", // Pink
140	"#FFC107", // Amber
141	"#00BCD4", // Cyan
142	"#8BC34A", // Light Green
143	"#FF9800", // Deep Orange
144	"#3F51B5", // Indigo
145	"#673AB7", // Deep Purple
146	"#009688", // Teal
147	"#F44336", // Red
148	"#CDDC39", // Lime
149}