Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Logotron 3000

SimeonSimeon Admin Mod
edited March 2015 in Code Sharing Posts: 5,383

I was playing around in Codea tonight and decided to make this simple game logo generator. Feel free to use it however you like. Note that the code is a bit hacked together, as I didn't really have an idea in mind of what I wanted before starting.

Example output

https://imgur.com/N9Go8qe

You can customise colour palette and font.

--# Main
-- Logotron
displayMode(STANDARD)

function setup()
    local bounds = vec2(600, 300)
    logoImg = nil

    fontSize(96)

    local generate = function()
        logoImg = genLogo(bounds)
    end

    parameter.text("NAME", "Title Here", generate)

    parameter.integer("PALETTE", 1, 7, 1, generate)

    parameter.integer("FONT", 1, 9, 1, generate)

    parameter.action("Regenerate", generate)
end

function genLogo(bounds)
    local pal = {
        palettes.winter,
        palettes.earthy,
        palettes.fiery,
        palettes.space,
        palettes.darkness,
        palettes.dusty,
        palettes.sky,
    }

    local fonts = {
    ("AmericanTypewriter-Bold"),
    ("ArialRoundedMTBold"),
    ("Futura-Medium"),
    ("Futura-CondensedExtraBold"),
    ("Courier-Bold"),
    ("HelveticaNeue-Light"),
    ("Noteworthy-Bold"),
    ("SourceSansPro-Bold"),
    ("Vegur-Bold"),
    }

    local pidx = PALETTE or 1
    local fidx = FONT or 1

    local img = image(bounds:unpack())

    font(fonts[fidx])

    setContext(img)

    renderString(NAME, bounds, pal[pidx])

    setContext()

    return img
end

function draw()
    -- This sets a dark background color 
    background(85, 85, 108, 255)

    -- This sets the line thickness
    strokeWidth(5)

    -- Do your drawing here
    sprite(logoImg, WIDTH/2, HEIGHT/2)
end

function renderCircles(count, origin, bounds)
    local ls = bounds.x // 5
    local us = bounds.x // 2

    for i = 1, count do
        local rad = math.random(ls, us)
        local pos = vec2(math.random(math.floor(bounds.x)),
                         math.random(math.floor(bounds.y)))

        pos = pos + origin
        ellipse(pos.x, pos.y, rad) 
    end
end

function renderString(str, bounds, scheme)
    pushStyle()

    textAlign(CENTER)

    local w,h = textSize(str)
    local xoffset = bounds.x/2 - w/3
    local ycenter = bounds.y/2

    str:gsub(".", function(c)

        w = textSize(c)

        if c == " " then
            w = w * 1.35
        else
            w = w * 0.85
        end

        local s = (math.random() * 0.25) + 0.75
        local pos = vec2(xoffset, ycenter + math.random(-5, 5))

        pushMatrix()

        translate(pos:unpack())
        scale(s)
        rotate(math.random() * 10 - 5)
        translate(-pos:unpack())

        blendMode(NORMAL)
        fill(scheme[4])
        text(c, 3, -5)

        fill(scheme[3])
        text(c, -2, 2)

        fill(scheme[1])
        text(c, 0, 0)

        blendMode(MULTIPLY)
        fill(scheme[2])
        renderCircles(20, -vec2(w, h)/2, vec2(w, h))

        popMatrix()

        xoffset = xoffset + w * s
    end)
    popStyle()
end

--# Palettes
palettes = {}

palettes.winter = {
    color(241, 243, 243, 255),
    color(169, 219, 223, 255),
    color(59, 130, 169, 255),
    color(38, 80, 83, 255),
}

palettes.earthy = {
    color(83, 218, 43, 255),
    color(28, 160, 25, 255),
    color(155, 79, 50, 255),
    color(63, 40, 40, 255),
}

palettes.fiery = {
    color(251, 92, 0, 255),
    color(222, 182, 130, 255),
    color(116, 43, 31, 255),
    color(71, 30, 30, 255),
}

palettes.space = {
    color(52, 41, 103, 255),
    color(203, 200, 223, 255),
    color(148, 139, 205, 255),
    color(156, 54, 201, 255),
}

palettes.darkness = {
    color(0, 0, 0, 255),
    color(42, 85, 72, 255),
    color(58, 101, 129, 255),
    color(163, 183, 192, 255),
}

palettes.dusty = {
    color(255, 255, 255, 255),
    color(222, 201, 175, 255),
    color(249, 194, 13, 255),
    color(57, 69, 30, 255),
}

palettes.sky = {
    color(93, 163, 230, 255),
    color(216, 222, 230, 255),
    color(154, 192, 223, 255),
    color(30, 45, 118, 255),
}

Comments

  • Posts: 688

    @Simeon - that's cool :)
    I can see a use for that if expanded a little - maybe add a degree of randomness, add a background ellipse, export to photo's / dropbox

  • Posts: 1,747

    @Simeon,

    Neat little package - I can see this routine on many future intro pages.

    Bri_G

    :D

  • SimeonSimeon Admin Mod
    Posts: 5,383

    Thanks, I figured it might be helpful for people doing quick prototypes and needing something slightly better looking than plain text.

  • Posts: 289

    @Simeon,
    Superb,i love the code so much that

  • Posts: 289

    i wanna show str without special effect,how to adjust the value of w to make chars' blank normal?

Sign In or Register to comment.