lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,

Stuart P.Bentley wrote:
[Club ann snipped]

(Also, why hasn't anybody implemented the Lua logo as a Lua script using a library like CanvasDraw yet?)

I have following code for Cairo (copied from CairoPad):
--8<--------------------------------------------------------------------
local cr = ...; -- Paint context
local M_PI = math.pi

-- FIXME: coords, sizes should not be const!

local xc = 125
local yc = 125
local r  = 50

-- canvas
cairo.save (cr);
do
    cairo.set_source_rgb (cr, 1.0, 1.0, 1.0);
    cairo.paint (cr);
end
cairo.restore (cr);

-- planet
cairo.save (cr);
do
    cairo.set_source_rgb (cr, 0.0, 0.0, 0.5);
    cairo.set_line_width (cr, 2.0);
    cairo.arc (cr, xc, yc, r, 0.0, 2*M_PI);
    cairo.fill_preserve (cr);
    cairo.stroke (cr);
end
cairo.restore (cr);

-- hole
cairo.save (cr);
do
    cairo.set_source_rgb (cr, 1.0, 1.0, 1.0);
    cairo.set_line_width (cr, 2.0);
    cairo.arc (cr, xc+20, yc-20, r/4, 0.0, 2*M_PI);
    cairo.fill_preserve (cr);
    cairo.stroke (cr);
end
cairo.restore (cr);

-- orbit
cairo.save (cr);
do
    local dashes = {5.0,  --/* ink */
                    3.0,  --/* skip */
                    5.0,  --/* ink */
                    3.0,  --/* skip*/
                   };
    local ndash = #dashes;
    local offset = -50.0;

    cairo.set_dash (cr, dashes, ndash, offset);
    cairo.set_source_rgb (cr, 0.5, 0.5, 0.5);
    cairo.set_line_width (cr, 2.0);
    cairo.arc (cr, xc, yc, r+20, 0.0, 2*M_PI);
    cairo.stroke (cr);
    cairo.set_dash (cr, {}, 0, 0);
end
cairo.restore (cr);

-- moon
cairo.save (cr);
do
    cairo.set_source_rgb (cr, 0.0, 0.0, 0.5);
    cairo.set_line_width (cr, 2.0);
    cairo.arc (cr, xc+20+30, yc-20-30, r/4, 0.0, 2*M_PI);
    cairo.fill_preserve (cr);
    cairo.stroke (cr);
end
cairo.restore (cr);

-- label
cairo.save (cr);
do
    cairo.set_source_rgb (cr, 1.0, 1.0, 1.0);
cairo.select_font_face (cr, "Helvetica", CAIRO.FONT_SLANT_NORMAL, CAIRO.FONT_WEIGHT_NORMAL);
    cairo.set_font_size (cr, 40.0);
    cairo.move_to (cr, xc-35, yc+25);
    cairo.show_text (cr, "Lua");
end
cairo.restore (cr);
--8<--------------------------------------------------------------------


--
Regards,
Hakki Dogusan