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