fractals/animations examples updates - gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2010年09月19日 17:32:46 +0200
committerFrancesco Abbate <francesco.bbt@gmail.com>2010年09月19日 17:32:46 +0200
commit1aaf01518a0c6bfe971e55dd53b6772f3d0276f7 (patch)
tree37d398bfa445a9b25a6eac5a8800cd9754a8dea3
parentf01979f1b5acf2fae8a056563588e00cb5243649 (diff)
downloadgsl-shell-1aaf01518a0c6bfe971e55dd53b6772f3d0276f7.tar.gz
fractals/animations examples updates
Diffstat
-rw-r--r--examples/anim.lua 117
-rw-r--r--examples/fractals.lua 37
2 files changed, 93 insertions, 61 deletions
diff --git a/examples/anim.lua b/examples/anim.lua
index b93ddb51..cbe0432a 100644
--- a/examples/anim.lua
+++ b/examples/anim.lua
@@ -1,79 +1,82 @@
-function circle(x0, y0, R, N)
- local f = function(j) return x0+R*cos(2*pi*j/N), y0+R*sin(2*pi*j/N) end
- local ln = ipath(sequence(f, 0, N))
- ln:close()
- return ln
-end
-
function demo1()
- local c = window('white')
- local fig = circle(0, 0, 0.6, 5)
- c:setview(-1, -1, 1, 1)
- local N= 1000
- for j=0, N do
- c:clear()
- c:draw(fig, 'yellow', {}, {{'rotate', angle= 2*pi*j/N}})
- c:stroke(fig, 'black', {}, {{'rotate', angle= 2*pi*j/N}})
- c:refresh()
- end
-end
-
-function demo2()
local x1 = 25
local p = plot('Inviluppo')
+ p.sync = false
p:addline(fxline(|x| exp(-0.1*x), 0, x1), 'blue')
p:addline(fxline(|x| -exp(-0.1*x), 0, x1), 'blue')
+ p:pushlayer()
p:show()
for j=0, 256 do
local w = 4*exp((j-256)/256)
p:clear()
local ln = fxline(|x| exp(-0.1*x)*cos(w*x), 0, x1)
- p:stroke(ln, 'red')
- p:refresh()
+ p:addline(ln, 'red')
+ p:flush()
end
end
-function demo3()
- local x1 = 25
- local p = plot('rotating sine')
-
- local e = ellipse(pi, 0, pi/2, pi/4)
-
- p:addline(ellipse(0,0, 2*pi, 2*pi), 'black')
--- p:addline(square(0,0, 4*pi), 'black')
- p.units = false
- p:show()
-
- local N = 512
- for j=0, N do
- local angle = j*2*pi/N
- p:clear()
- local ln = fxline(sin, 0, 2*pi)
- p:stroke(ln, 'red', {}, {{'rotate', angle= angle}})
- p:stroke(ln, 'blue', {}, {{'rotate', angle= angle + pi/2}})
- p:stroke(ln, 'green', {}, {{'rotate', angle= angle + pi}})
- p:stroke(ln, 'yellow', {}, {{'rotate', angle= angle + 3*pi/2}})
-
- p:stroke(e, 'red', {}, {{'rotate', angle= angle}})
+function star(r)
+ local a, ae = 54*pi/180, 72*pi/180
+ local li, hi = r*cos(a), r*sin(a)
+ local he = li*tan(ae)
+ local xv, yv = 0, - hi - he
+ local xb, yb = - li, - hi
+ local p = path(xv, yv)
+ p:line_to(xb, yb)
+ for k=1, 4 do
+ local th = 2*pi*k/5
+ p:line_to(xv*cos(th) + yv*sin(th), yv*cos(th) - xv*sin(th))
+ p:line_to(xb*cos(th) + yb*sin(th), yb*cos(th) - xb*sin(th))
+ end
+ p:close()
+ return p
+end
- p:refresh()
+function demo2()
+ local plt = canvas('Pre3D')
+ plt.units = false
+ plt:show()
+ local a = 15.0
+ plt:limits(-a, -a, a, a)
+ local r = rng()
+ for k = 1, 50 do
+ local x, y = (2*r:get()-1)*a, (2*r:get()-1)*a
+ local d = rnd.gaussian(r, 0.015*a) + 0.03*a
+ local s = star(d)
+ plt:add(s, rgb(0.9, 0.9, 0.9), {}, {{'translate', x=x, y=y}})
+ plt:addline(s, rgb(0.6, 0.6, 0.6), {}, {{'translate', x=x, y=y}})
+ end
+ plt:pushlayer()
+ local N, R, nc = 128, 5.0, 15
+ for k = 0, N * nc do
+ local r = R * cos(pi*k/N)^2
+ local th = 2*pi*(k/(N*nc*10))
+ local s= star(r)
+ plt:clear()
+ plt:add(s, rgba(1, 1, 0, 0.7), {}, {{'rotate', angle=th}})
+ plt:addline(s, rgb(0.5, 0.5, 0), {}, {{'rotate', angle=th}})
+ plt:flush()
end
end
-function demo4()
- local f = |t| exp(-0.1*t) * cos(t)
- local x0, x1 = 0, 6*pi
- local p = fxplot(f, x0, x1)
+function demo3()
+ local f = |x| exp(-0.1*x) * cos(x)
+ local p = plot 'y = f(x)'
+ local x0, x1 = 0, 10*pi
+ p.sync = false
+ p:pushlayer()
+ p:show()
+
+ local cc = fxline(f, x0, x1, k)
local N = 256
- for j=0, N do
- local x = x0 + j*(x1-x0)/256
- local ln = fxline(f, x0, x)
- ln:line_to(x, 0)
- ln:line_to(0, 0)
- ln:close()
+ for k= 1, N do
+ local x = x0 + k * (x1-x0) / N
+ local ca = fxline(f, x0, x, k)
+ ca:line_to(x, 0); ca:line_to(0, 0); ca:close()
p:clear()
- p:draw(ln, 'yellow')
- p:refresh()
+ p:add(ca, rgba(1,1,0,0.6))
+ p:addline(cc)
+ p:flush()
end
end
diff --git a/examples/fractals.lua b/examples/fractals.lua
index c760ef21..be0fdf17 100644
--- a/examples/fractals.lua
+++ b/examples/fractals.lua
@@ -67,12 +67,34 @@ end
demo2 = function(n) return levyc(n and n or 6) end
+function get_box_gener()
+ local pbox = {}
+
+ local function get(ll)
+ local b = pbox[ll]
+ if not b then
+ b = rect(0, 0, ll, ll)
+ pbox[ll] = b
+ end
+ return b
+ end
+
+ local function count()
+ local c = 0
+ for k, v in pairs(pbox) do c = c+1 end
+ return c
+ end
+ return get, count
+end
+
function demo3()
local rdsd = sqrt(2)/2
local cf
+ local get_box, box_count = get_box_gener()
+
local function pitag_tree(pl, x, y, th, ll, depth)
- local box = rect(0, 0, ll, ll)
+ local box = get_box(ll)
local col = cf(depth)
pl:add(box, col, {}, {{'translate', x= x, y= y}, {'rotate', angle= th}})
if depth > 0 then
@@ -90,6 +112,8 @@ function demo3()
pl.units = false
pitag_tree(pl, 0, 0, 0, 1, depth)
pl:show()
+
+ print('number of used rectangles:', box_count())
return pl
end
@@ -167,9 +191,11 @@ function demo3teri(n)
n = n and n or 10
local col, coln
+ local get_box, box_count = get_box_gener()
+
local function pitag_tree(pl, x, y, th, ll, depth)
if depth == 0 then
- local box = rect(0, 0, ll, ll)
+ local box = get_box(ll)
local tr = {{'translate', x= x, y= y}, {'rotate', angle= th}}
pl:add(box, col, {}, tr)
pl:add(box, coln, {{'stroke', width= 2.5*ll}}, tr)
@@ -187,12 +213,15 @@ function demo3teri(n)
local pl = plot()
pl.units = false
+ pl.sync = false
+ pl:show()
- for k=n, 0, -1 do
+ for k=0, n do
col, coln = cfgen(k/n), cfgen((k+1)/n)
pitag_tree(pl, 0, 0, 0, 1, k)
+ pl:flush()
end
- pl:show()
+ print('number of used rectangles:', box_count())
return pl
end
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月16日 15:59:36 +0000

AltStyle によって変換されたページ (->オリジナル) /