Search Apps Documentation Source Content File Folder Download Copy Actions Download

home.gno

4.60 Kb ยท 195 lines
  1package home
  2
  3import (
  4	"chain/banker"
  5	"chain/runtime"
  6	"strconv"
  7
  8	"gno.land/p/demo/svg"
  9	"gno.land/p/leon/svgbtn"
 10	"gno.land/p/moul/md"
 11	"gno.land/p/nt/ufmt"
 12
 13	"gno.land/r/demo/art/gnoface"
 14	"gno.land/r/demo/art/millipede"
 15	"gno.land/r/demo/mirror"
 16	"gno.land/r/leon/config"
 17	"gno.land/r/leon/hor"
 18)
 19
 20var (
 21	pfp        string // link to profile picture
 22	pfpCaption string // profile picture caption
 23	abtMe      [2]string
 24)
 25
 26func Render(path string) string {
 27	out := "# Leon's Homepage\n\n"
 28
 29	if path == "buttons" {
 30		return renderButtonPage()
 31	}
 32
 33	out += renderAboutMe()
 34	out += renderArt()
 35	out += config.Banner()
 36	out += "\n\n"
 37	out += svgbtn.Button(
 38		1200,
 39		50,
 40		gnomeBodyColors[int(runtime.ChainHeight()+1)%len(gnomeBodyColors)],
 41		"#ffffff",
 42		"Support my work!",
 43		"/r/leon/home$help&func=Donate&.send=1000000ugnot",
 44	)
 45
 46	return out
 47}
 48
 49func init() {
 50	hor.Register(cross, "Leon's Home Realm", "")
 51	mirror.Register(cross, runtime.CurrentRealm().PkgPath(), Render)
 52
 53	pfp = "https://i.imgflip.com/91vskx.jpg"
 54	pfpCaption = "[My favourite painting & pfp](https://en.wikipedia.org/wiki/Wanderer_above_the_Sea_of_Fog)"
 55	abtMe = [2]string{
 56		`### About me
 57Hi, I'm Leon, a DevRel Engineer at gno.land. I am a tech enthusiast, 
 58life-long learner, and sharer of knowledge.`,
 59		`### Contributions
 60My contributions to Gno.land can mainly be found 
 61[on GitHub](https://github.com/gnolang/gno/issues?q=sort:updated-desc+author:leohhhn), and on [the chain](/u/leon).
 62
 63TODO import r/gh`,
 64	}
 65}
 66
 67func UpdatePFP(cur realm, url, caption string) {
 68	if !config.IsAuthorized(runtime.PreviousRealm().Address()) {
 69		panic(config.ErrUnauthorized)
 70	}
 71
 72	pfp = url
 73	pfpCaption = caption
 74}
 75
 76func UpdateAboutMe(cur realm, col1, col2 string) {
 77	if !config.IsAuthorized(runtime.PreviousRealm().Address()) {
 78		panic(config.ErrUnauthorized)
 79	}
 80
 81	abtMe[0] = col1
 82	abtMe[1] = col2
 83}
 84
 85func Donate(_ realm) string {
 86	sent := banker.OriginSend()
 87	if len(sent) == 0 {
 88		return ":c"
 89	}
 90
 91	banker.NewBanker(banker.BankerTypeOriginSend).SendCoins(
 92		runtime.CurrentRealm().Address(),
 93		config.OwnableMain.Owner(),
 94		sent,
 95	) // wish this was prettier :)
 96
 97	return "Thanks for donating " + sent.String() + " <3"
 98}
 99
100func renderAboutMe() string {
101	return md.Columns([]string{
102		ufmt.Sprintf("![my profile pic](%s)\n\n%s\n", pfp, pfpCaption),
103		abtMe[0],
104		abtMe[1],
105	}, false)
106}
107
108func renderArt() string {
109	out := "# Gno Art\n"
110
111	out += md.Columns([]string{
112		gnoface.Render(strconv.Itoa(int(runtime.ChainHeight()))),
113		renderMillipede(),
114		"SVG Gnome\n" + RenderSVGGnome(),
115	}, false)
116
117	out += "This art is dynamic; it will change with every new block.\n\n"
118
119	return out
120}
121
122func renderMillipede() string {
123	out := "Millipede\n\n"
124	out += "```\n" + millipede.Draw(int(runtime.ChainHeight())%10+1) + "```\n"
125	return out
126}
127
128func renderBlogPosts() string {
129	out := ""
130	// out += "## Leon's Blog Posts"
131
132	// todo fetch blog posts authored by @leohhhn
133	// and render them
134	return out
135}
136
137func RenderSVGGnome() string { // exported for your pleasure :)
138	c := svg.NewCanvas(430, 430).WithViewBox(13, 25, 75, 75)
139
140	// Body: blue triangle
141	body := svg.NewPolygon("50,50 30,100 70,100", gnomeBodyColors[int(runtime.ChainHeight())%len(gnomeBodyColors)])
142
143	// Head: peach circle (overlaps body)
144	head := svg.NewCircle(50, 60, 10, "#FAD7B6")
145
146	// Hat: red triangle on top of head
147	hat := svg.NewPolygon("50,30 35,55 65,55", "#E53935")
148
149	// Eyes: two small black dots
150	leftEye := svg.NewCircle(46, 59, 1, "#000")
151	rightEye := svg.NewCircle(54, 59, 1, "#000")
152
153	// Beard: small white triangle under head
154	beard := svg.NewPolygon("50,85 42,63 58,63", "#FFF")
155
156	// Layering order matters (bottom to top)
157	c.Append(body, head, beard, hat, leftEye, rightEye)
158
159	return c.Render("svg gnome")
160}
161
162func renderButtonPage() string {
163	out := "# Buttons Demo\n\n"
164
165	out += md.ColumnsN([]string{
166		svgbtn.PrimaryButton(140, 45, "Click Me", "/r/leon/home:click") + "\n\n",
167		svgbtn.DangerButton(140, 45, "Delete", "/delete") + "\n\n",
168		svgbtn.SuccessButton(140, 45, "Go Home", "/r/leon/home") + "\n\n",
169		svgbtn.SmallButton(100, 45, "Edit", "/edit") + "\n\n",
170		svgbtn.WideButton(200, 40, "Big Action", "/big") + "\n\n",
171		svgbtn.TextButton(100, 30, "More Info", "/r/leon/home:info") + "\n\n",
172		svgbtn.IconButton(100, 40, "Config", "/r/leon/config") + "\n\n",
173	}, 3, true)
174
175	return out
176}
177
178var gnomeBodyColors = []string{
179	"#4CAF50", // Green
180	"#2196F3", // Blue
181	"#9C27B0", // Purple
182	"#FF5722", // Orange
183	"#795548", // Brown
184	"#607D8B", // Grayish Blue
185	"#E91E63", // Pink
186	"#FFC107", // Amber
187	"#00BCD4", // Cyan
188	"#8BC34A", // Light Green
189	"#FF9800", // Deep Orange
190	"#3F51B5", // Indigo
191	"#673AB7", // Deep Purple
192	"#009688", // Teal
193	"#F44336", // Red
194	"#CDDC39", // Lime
195}