Thursday, August 21, 2008

Some graphical examples

The following are two graphical applications written in LuaGravity with respective videos and source codes.




The first example shows some flying rectangles whose size and speed increase as they get closer to the screen base.



Here's the source code:

for i=1, 15
do
local r = root:_add(
Rect()
._fill {r=255,g=200,b=100}
.x { pc=0, dim=true }
.y { p2=0, dim=true }()
)

r.x.pc = root.x.pc + INT(math.random(-15,15))

local y2 = r.y.p2

local v = 1 + y2^1.3/root.y.p2
r.y.p2 = INT(math.random(1,15)*v)

local dim = 1 + y2/5
r.x.dim = dim
r.y.dim = dim
end





The second example shows the mouse cursor surrounded by orbiting rectangles.
The orbit radius may be changed explicitly.
It's based on an example found in the FrTime distribution.




Here's the source code:

local secs = INT(1)
local sin = L(math.sin)
local cos = L(math.cos)
local C = 2/3 * math.pi

radius = 50

for i=1, 3
do
root:_add(
Rect()
._fill {r=255,g=0,b=0}
.x { dim=20, pc=(mouse.x + radius * sin(secs+C*i)) }
.y { dim=20, pc=(mouse.y + radius * cos(secs+C*i)) }()
)
end

1 comment:

  1. Parece até fácil fazer, do jeito que vc esta escrevendo..:)

    Eve

    ReplyDelete