From ab301401c71effb0a009776be3417756df89c6dd Mon Sep 17 00:00:00 2001
From: Theta Nil <20186755+thetanil@users.noreply.github.com>
Date: Wed, 3 Aug 2022 08:21:41 -0400
Subject: [PATCH] Add gensvg demo to redbean (#524)
gensvg demo and mk for it
---
tool/net/demo/gensvg.lua | 77 ++++++++++++++++++++++++++++++++++++++++
tool/net/net.mk | 2 ++
2 files changed, 79 insertions(+)
create mode 100644 tool/net/demo/gensvg.lua
diff --git a/tool/net/demo/gensvg.lua b/tool/net/demo/gensvg.lua
new file mode 100644
index 00000000000..f9dd73b9a5e
--- /dev/null
+++ b/tool/net/demo/gensvg.lua
@@ -0,0 +1,77 @@
+local top = [[
+
+
+
+
+
+
+
+
+
+
+
+
+]]
+
+local bottom = [[
+ Show The Code
+
+
+]]
+
+local nrows = 10
+local ncols = 10
+local sqsize = 20
+local seed = math.random()
+local sat = 80
+local light = 70
+
+local function rect(x, y, w, h, rx)
+ local style = string.format('class="shadow" fill="hsla(%s, %s%%, %s%%, %s)"',
+ seed * 360 - 180, sat, light,
+ math.random(100) / 100.0)
+ return string.format(
+ '', x, y,
+ w, h, math.random(5, 12), style)
+end
+
+local function writeBlock(i, j)
+ if math.random() < 0.45 then return end
+ local cellsize = (math.random() > 0.25) and sqsize or math.random(1,4) * sqsize
+ Write('')
+ Write(rect(i * sqsize - sqsize, j * sqsize - sqsize, cellsize, cellsize))
+ Write('')
+end
+
+local function render()
+ nrows = nrows * 3
+ ncols = ncols * 3
+ local xsize = nrows * sqsize
+ local ysize = ncols * sqsize
+ local style = string.format('style="background-color: hsl(%s,%s%%,%s%%);"',
+ seed * 360, sat, light)
+ Write('')
+end
+
+Write(top)
+Write("Let's Generate Some SVG
")
+Write("If you don't like it, maybe refresh?
")
+render()
+Write('')
+Write(bottom)
\ No newline at end of file
diff --git a/tool/net/net.mk b/tool/net/net.mk
index 8bf5448bd7d..8b029b55df0 100644
--- a/tool/net/net.mk
+++ b/tool/net/net.mk
@@ -191,6 +191,7 @@ o/$(MODE)/tool/net/demo/binarytrees.lua.zip.o \
o/$(MODE)/tool/net/demo/crashreport.lua.zip.o \
o/$(MODE)/tool/net/demo/closedsource.lua.zip.o \
o/$(MODE)/tool/net/demo/printpayload.lua.zip.o \
+o/$(MODE)/tool/net/demo/gensvg.lua.zip.o \
o/$(MODE)/tool/net/demo/redbean-form.lua.zip.o \
o/$(MODE)/tool/net/demo/redbean-xhr.lua.zip.o \
o/$(MODE)/tool/net/redbean.png.zip.o \
@@ -245,6 +246,7 @@ o/$(MODE)/tool/net/redbean-demo.com.dbg: \
o/$(MODE)/tool/net/demo/crashreport.lua.zip.o \
o/$(MODE)/tool/net/demo/closedsource.lua.zip.o \
o/$(MODE)/tool/net/demo/printpayload.lua.zip.o \
+ o/$(MODE)/tool/net/demo/gensvg.lua.zip.o \
o/$(MODE)/tool/net/demo/redbean-form.lua.zip.o \
o/$(MODE)/tool/net/demo/redbean-xhr.lua.zip.o \
o/$(MODE)/tool/.zip.o \