The Synchronous Blog

A blog about reactive programming languages.

Some graphical examples

with 3 comments

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.

Follows the source code:

for i=1, 15
do
    local r = screen:add(
        Rect {
            _fill = {r=255,g=200,b=100},
            x = screen.dx()/2 + S(math.random(-15,15)),
        })

    local v = 1 + r.y^1.3/(screen.y()+screen.dy())
    r.y = S(math.random(1,15)*v)

    local dim = 1 + r.y/5
    r.dx = dim
    r.dy = 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.

Follows the source code:

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

radius = 50
size   = 20

for i=1, 3
do
    screen:add(
        Rect {
            _fill = {r=255,g=0,b=0},
            x  = (mouse.x + radius * sin(secs+C*i)) - size/2,
            dx = size,
                y  = (mouse.y + radius * cos(secs+C*i)) - size/2,
                dy = size,
        })
end
Advertisements

Written by francisco

August 21, 2008 at 4:54 pm

Posted in Examples

Tagged with , ,

3 Responses

Subscribe to comments with RSS.

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

    Eve

    Anxious Girl

    September 10, 2008 at 2:34 pm

  2. […] language. LuaGravity provides constructs based on them, which I consider even more useful than the functional […]

  3. […] all made implicitly. Much less verbosity. The reactive variables of LuaGravity (shown here and here) override Lua’s default behavior for […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: