[tekui-devel] tekui: Added drawrgb function and plasma example

hg-notify at neoscientists.org hg-notify at neoscientists.org
Tue Feb 5 02:46:01 CET 2008


details:   http://hg.teklib.org/tekui/rev/8e266bb9a2bf
changeset: 350:8e266bb9a2bf
user:      Timm S. Mueller <tmueller at neoscientists.org>
date:      Sat Feb 02 21:43:24 2008 +0100
description:
Added drawrgb function and plasma example

diffs (truncated from 238 to 100 lines):

diff -r 22aea1491da4 -r 8e266bb9a2bf tek/app/plasma.lua
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tek/app/plasma.lua	Sat Feb 02 21:43:24 2008 +0100
@@ -0,0 +1,128 @@
+#!/usr/bin/env lua
+
+local visual = require "tek.lib.visual"
+
+local COS = math.cos
+local SIN = math.sin
+local PI = math.pi
+local MIN = math.min
+local MAX = math.max
+local FLOOR = math.floor
+
+local WIDTH = 160
+local HEIGHT = 120
+local PIXWIDTH = 4
+local PIXHEIGHT = 4
+
+local WW = WIDTH * PIXWIDTH
+local WH = HEIGHT * PIXHEIGHT
+
+--
+--	open window
+--
+
+local v = visual.open("Plasma", WW, WH, WW, WH, WW, WH)
+v:setinput("close", "cookedkey", "interval")
+
+--
+--	init
+--
+
+local screen = { }
+local palette = { }
+local palindex = 0
+
+function addgradient(sr, sg, sb, dr, dg, db, num)
+	dr = (dr - sr) / (num - 1)
+	dg = (dg - sg) / (num - 1)
+	db = (db - sb) / (num - 1)
+	for i = 0, num - 1 do
+		palette[palindex] = FLOOR(sr) * 65536 + FLOOR(sg) * 256 + FLOOR(sb)
+		palindex = palindex + 1
+		sr = sr + dr
+		sg = sg + dg
+		sb = sb + db
+	end
+end
+
+addgradient(23,36,86,		  209,219,155, 	64)
+addgradient(209,219,155,	79,33,57, 		64)
+addgradient(79,33,57,		  209,130,255, 	64)
+addgradient(209,130,255, 	45,30,1,		  64)
+
+local sintab = { }
+for i = 0, 1023 do
+	sintab[i] = SIN(i / 1024 * PI * 2)
+end
+
+
+--
+--	effect
+--
+
+local xp1, xp2, xp3 = 0, 0, 0
+local yp1, yp2, yp3 = 0, 0, 0
+
+function effect()
+
+	local palettescale = #palette / 12
+	local yc1, yc2, yc3 = yp1, yp2, yp3
+	local i = 0
+
+	for y = 0, HEIGHT - 1 do
+
+		local xc1, xc2, xc3 = xp1, xp2, xp3
+		local ysin = sintab[yc1] + sintab[yc2] + sintab[yc3]
+
+		for x = 0, WIDTH - 1 do
+
+			local cv = sintab[xc1] + sintab[xc2] + sintab[xc3] + ysin
+			cv = FLOOR((cv + 6) * palettescale)
+			screen[i] = palette[cv]
+			i = i + 1
+
+			xc1 = (xc1 + 14) % 1024
+			xc2 = (xc2 + 11) % 1024
+			xc3 = (xc3 + 1009) % 1024
+
+		end
+
+		yc1 = (yc1 + 17) % 1024
+		yc2 = (yc2 + 1011) % 1024
+		yc3 = (yc3 + 10) % 1024
+
+	end
+
+	yp1 = (yp1 + 15) % 1024


More information about the tekui-devel mailing list