50 Line Challenge

The challenge is as the name implies, You have 50 lines of Code to make something. There are some rules though:

  1. Dependencies can be used, but the Main File + The dependancy must equal 50 lines all together.
  2. Must be original, No Copying and Pasting old projects(Inspirations and loosely based are allowed)
  3. Must be written in Codea/Lua
  4. Post your entries on this thread
  5. Have Fun!!!
    EDIT Comments do not count as lines

Well I bet I can do it in 1 line xD

Can http be used ? >:)

function setup()
print("A word a day, keeps the spelling teacher away!")
texta = ""
end

function draw()
showKeyboard()
texta = keyboardBuffer()
text(texta,WIDTH/2,HEIGHT/2)
end

function keyboard(k)
if k == RETURN then

openURL('http://www.wordhippo.com/what-is/another-word-for/' ..texta.. '.html')
end
end

Boom. Do I win?

https://github.com/stravant/LuaMinify
:smiley:

Here’s my entry :')

http://pastebin.com/Zj3kxXF0

Yup, there’s the flaw I was talking about @stevon8ter .

What flaw? My code is flawless :')

What did I win ? :smiley:

jk peops, I’ll try to come up with a real idea soon

I was just going to have a single http.request and a loadstring :stuck_out_tongue:

Ok here you go, it needs a while to start up and doesn’t use the best methods because of the limited lines of code, tho I still got 7 lines left… I’ll try to finish the rest of the program with those lines, tho it won’t be easy

function setup()
    displayMode(FULLSCREEN)
    fontSize(12)
    data = {packs = {"Documents", "Dropbox", "Cargo Bot", "Planet Cute", "Platformer Art", "Small World", "Space Art", "SpaceCute", "Tyrian Remastered"}, pos = vec2(WIDTH/2, HEIGHT/2), packselect = image(WIDTH, 121), selected = 1, selectpos = vec2(WIDTH/2,HEIGHT/2 - 121), packks = {}, imgs = {}}
    for i = 1, #data.packs do
        setContext(data.packselect)
        if readImage(data.packs[i] .. ':Icon') then
            sprite(data.packs[i] .. ':Icon', (i-1)*105 + 55, 121-55, 100, 100)
        else
            sprite("Cargo Bot:Crate Blue 1", (i-1)*105 + 55, 121-55, 100, 100)
        end
        text(data.packs[i], (i-1)*105 + 55, 121 - 55 - 60)
        data.packks[i] = {}
        for e = 1, math.ceil(#spriteList(data.packs[i])/9) do
            data.packks[i][e] = image(9*105, 121)
        end
        for e = 1, #spriteList(data.packs[i]) do
            setContext(data.packks[i][math.ceil(e/9)])
            a = readImage(data.packs[i] .. ':' .. spriteList(data.packs[i])[e])
            if a then
            sprite(a, (e-1)%9*105 + 55, 121-55, 100, 100)
            text(spriteList(data.packs[i])[e], (e-1)%9*105 + 55, 121 - 55 - 60)
            end
        end
    end
    setContext()
end
function draw()
    background(255, 255, 255, 255)
    sprite(data.packselect, data.pos.x, data.pos.y)
    for i = 1, #data.packks[data.selected] do
        sprite(data.packks[data.selected][i], data.selectpos.x + (i-1)*(9*105), data.selectpos.y)
    end
end
function touched(t)
    for i = 1, #data.packs do
        if t.x <= data.pos.x - WIDTH/2 + i*105 and t.x >= data.pos.x - WIDTH/2 + (i-1)*105 + 5 and t.y <= data.pos.y + 55.5 and t.y >= data.pos.y - 44.5 then
            data.selected = i
            data.selectpos = vec2(WIDTH/2, HEIGHT/2 - 121)
        end
    end
    data.selectpos.x = data.selectpos.x + t.deltaX
end

@Prynok, yours doesn’t work because openURL needs a http:// in the address.

Here is mine (I used exactly 50 lines):

function setup()
    print("A word a day, keeps the spelling teacher away!\
\
Powered by WordHippo.")
    
    wordSynonyms = {}
    
    parameter.text("WORD", "Word", function() WORD = string.lower(WORD) end)
    parameter.action("Find Synonyms", loadSynonyms)
    parameter.action("See The Website", openSynonymsPage)
end

function openSynonymsPage()
    openURL('http://www.wordhippo.com/what-is/another-word-for/' .. WORD .. '.html', true)
end

function loadSynonyms()
    local gotData = function(data, status, headers)
        wordSynonyms = {}
        
        for word in data:gmatch('.html">(.-)</a>') do
            table.insert(wordSynonyms, word)
        end
        
        local fix = nil
        if #wordSynonyms == 1 then 
            fix = "No synonyms found."
        end
        for id, word in ipairs(wordSynonyms) do
            if word == "Meaning of the word " .. WORD then
                wordSynonyms[id] = fix
            end
        end
    end
    
    http.request("http://www.wordhippo.com/what-is/another-word-for/" .. WORD .. ".html", gotData)
end

function draw()
    background(0)
    fontSize(20) fill(255)
    
    local cols = 3
    for id, word in ipairs(wordSynonyms) do
        local row = math.ceil(id / cols)
        local col = math.ceil(id - ((row - 1) * cols))
        local y = HEIGHT - (fontSize()*2 * row)
        local x = WIDTH * (col / 4)
        
        text(word, x, y)
    end
end

@JakAttack Oops! Fixed.

Thinking I did so much trouble getting my code under 50 lines to see so much space left in your program xd
I couldn’t think of a better idea :s

Here’s my 50 line entry. (Cheating a bit by sticking multiple statements on one line at times).

A game where you drag the balloons to keep them below the line. High score is how long you lasted.

function setup()
    balloons = {}; interacting = {}; spawnInterval = 5; ended = false
    displayMode(FULLSCREEN); state = "Keep the balloons below the line!"
end

function draw()
    local mr = math.random
    noStroke(); background(60, 60, 87, 255)
    for k,b in pairs(balloons) do
        b.pos = vec2(b.init + math.sin(b.pos.y * 0.035) * 30, b.pos.y + b.speed)
        b.speed = b.speed + 0.003
        if b.pos.y > (HEIGHT - 250) and not ended then 
            ended=true; state="You lasted: ".. math.floor(ElapsedTime) .." seconds" 
        end
        math.randomseed(b.init)
        fill(185+mr(80),50+mr(40),50+mr(40))
        ellipse(b.pos.x, b.pos.y, 100)
    end
    for k,b in pairs(interacting) do
        fill(255) ellipse(b.pos.x,b.pos.y,105) end
    if spawnInterval * #balloons < ElapsedTime then
        local xp = mr(WIDTH - 100) + 50
        table.insert( balloons, { pos=vec2(xp, -50), init=xp, speed=1 } )        
    end
    fill(255); fontSize(40); text(state,WIDTH/2,HEIGHT - 100)
    strokeWidth(5); line(0,HEIGHT - 200,WIDTH, HEIGHT - 200)
end

function touched(touch)
    if touch.state == BEGAN then
        local closest = nil; local closestDist = math.huge
        for k,b in pairs(balloons) do
            if b.pos:distSqr(vec2(touch.x,touch.y)) < closestDist then
                closestDist = b.pos:distSqr(vec2(touch.x,touch.y))
                closest = { k, b }
            end
        end
        if closest then 
            interacting[touch.id] = closest[2] 
            balloons[closest[1]] = nil
        end
    elseif touch.state == MOVING then
        local b = interacting[touch.id]
        b.pos.y = b.pos.y + touch.deltaY
        b.pos.x = b.init + math.sin(b.pos.y * 0.035) * 30
    elseif touch.state == ENDED or touch.state == CANCELLED then
        table.insert(balloons, interacting[touch.id])
        interacting[touch.id] = nil
    end
end

```

@Simeon, that’s amazing with such few lines :o tho I quickly see you left 3 lines open :wink:

but here’s a version that doesn’t include multiple statements on 1 line, sorry I just had to do it xD

still Simeon’s code tho, just changed the balloons to be heart-shaped
and some other things as defining multiple vars in 1 statement (not in multiple statements as simeon did) and I had to remove some ‘locals’

function setup()
    balloons, interacting, spawnInterval, ended, state = {}, {}, 5, false, "Keep the balloons below the line!"
    displayMode(FULLSCREEN)
end
function draw()
    noStroke()
    background(60, 60, 87, 255)
    for k,b in pairs(balloons) do
        b.pos = vec2(b.init + math.sin(b.pos.y * 0.035) * 30, b.pos.y + b.speed)
        b.speed = b.speed + 0.003
        if b.pos.y > (HEIGHT - 250) and not ended then
            ended = true
            state="You lasted: ".. math.floor(ElapsedTime) .." seconds" 
        end
        sprite("Planet Cute:Heart", b.pos.x, b.pos.y, 100, 150)
    end
    for k,b in pairs(interacting) do
        sprite("SpaceCute:Health Heart", b.pos.x, b.pos.y, 100, 100)
    end
    if spawnInterval * #balloons < ElapsedTime then
        table.insert( balloons, { pos=vec2(math.random(WIDTH - 100) + 50, -50), init=math.random(WIDTH - 100) + 50, speed=1 } )        
    end
    fill(255)
    fontSize(40)
    text(state,WIDTH/2,HEIGHT - 100)
    strokeWidth(5)
    line(0,HEIGHT - 200,WIDTH, HEIGHT - 200)
end
function touched(touch)
    if touch.state == BEGAN then
        closest, closestDist = nil, math.huge
        for k,b in pairs(balloons) do
            if b.pos:distSqr(vec2(touch.x,touch.y)) < closestDist then
                closestDist = b.pos:distSqr(vec2(touch.x,touch.y))
                closest = { k, b }
            end
        end
        if closest then 
            interacting[touch.id] = closest[2] 
            balloons[closest[1]] = nil
        end
    elseif touch.state == MOVING then
        local b = interacting[touch.id]
        b.pos.y = b.pos.y + touch.deltaY
        b.pos.x = b.init + math.sin(b.pos.y * 0.035) * 30
    elseif touch.state == ENDED or touch.state == CANCELLED then
        table.insert(balloons, interacting[touch.id])
        interacting[touch.id] = nil
    end
end

Here’s my entry. The code has horrible variable names for no other reason than me being too lazy to type longer ones.

displayMode(FULLSCREEN)   
function setup()
    man, blobs = {r = 0, d = 100, steer = 0, t = 0, rad = 10, score = 0}, {}
    ellipseMode(CENTER)
    fontSize(20)
end
function draw()
    background(0, 0, 0, 255)    
    text("SCORE: " .. man.score .. " " .. #blobs, WIDTH/2, HEIGHT - 20)  
    man.r = man.r + man.steer * DeltaTime * math.pi * 1.25
    local j = math.random() * 2
    local manPos = vec2(WIDTH/2 + math.cos(man.r) * (man.d+j), HEIGHT/2 + math.sin(man.r) * (man.d+j))
    fill(255, 0, 204, 255)
    ellipse(manPos.x, manPos.y, man.rad * 2)
    man.t = man.t - DeltaTime
    if man.t <= 0 then
        local d = math.sqrt(WIDTH/2*WIDTH/2 + HEIGHT/2*HEIGHT/2)
        table.insert(blobs, {r = math.random() * 2 * math.pi, d = d, rad = math.random(5, 40)})
        man.t = math.max(3 - ElapsedTime * 0.05, 0.2)
    end    
    fill((noise(1000+ElapsedTime/10)+1.5)*128, (noise(500+ElapsedTime/100)+1.5)*255, (noise(ElapsedTime/10)+1.5)*128, 255)
    ellipse(WIDTH/2, HEIGHT/2, math.abs(math.sin(ElapsedTime * 5)) * 5) 
    local dead = {}
    for k,blob in pairs(blobs) do
        local blobPos = vec2(WIDTH/2 + math.cos(blob.r) * blob.d, HEIGHT/2 + math.sin(blob.r) * blob.d)
        ellipse(blobPos.x, blobPos.y, blob.rad * 2)
        if blob.d >= 0 then blob.d = blob.d - DeltaTime * (200 - blob.rad * 2) * math.max(math.min(ElapsedTime/20, 3), 1)
            if manPos:dist(blobPos) < man.rad+blob.rad then
                draw = function() 
                    background(0, 0, 0, 255)
                    text("GAME OVER: "..man.score, WIDTH/2, HEIGHT/2) 
                end
            end
        elseif blob.rad > 0 then blob.rad = blob.rad - DeltaTime * 100 
        elseif not blob.dead then man.score = man.score + 1; blob.dead = true; table.insert(dead, k) end
    end
    for i = #dead,1,-1 do table.remove(blobs, dead[i]) end
end
function touched(touch)
    if touch.x < WIDTH/2 and touch.state == BEGAN then
        man.steer = man.steer + 1
    elseif touch.x < WIDTH/2 and touch.state == ENDED then
            man.steer = man.steer - 1
    elseif touch.x >= WIDTH/2 and touch.state == BEGAN then 
            man.steer = man.steer - 1
    elseif touch.x >= WIDTH/2 and touch.state == ENDED then
            man.steer = man.steer + 1
    end
end

```

Heey if we can do our for loops and if statements etc, in one full line, then I can make my code even smaller and maybe implement a full working sprite selector :stuck_out_tongue: instead of just the sprite browser, but idk if that’s allowed @codeanoob …?

@John that’s amazing in just 50 lines :o
And then to know you got a fully working game + nice game over screen, also, I think you can reduce it by at least 4 lines :wink:

Here’s my submission. I’m taking “one line” as what will fit on one line in portrait orientation (smallest width) without wrapping to another line. To play this game, tap the number you want to move to the blank square. Object is to get the numbers in order, left to right, top to bottom, with the blank square in the lower right corner.


displayMode(FULLSCREEN) supportedOrientations(PORTRAIT_ANY)
function setup()
    count,size,done,ntab,otab=0,150,false,{},{}
    tab = { {2,5,},{1,3,6,},{2,4,7,},{3,8,},{1,6,9,},{2,5,7,10,},
    {3,6,8,11,},{4,7,12,},{5,10,13,},{6,9,11,14,},{7,10,12,15,},
    {8,11,16,},{9,14,},{10,13,15,},{11,14,16,},{12,15,} }    
    create16() end
function create16()    -- create starting puzzle
    for z = 1,16 do ntab[z]=0 rnd = randomNbr() ntab[z]=rnd otab[z]=rnd
    if rnd == 16 then n=z end end ntab[n]="" otab[n]="" end
function randomNbr()
    while 1 do a = math.random(1,16)
    for z = 1,16 do if ntab[z] == 0 then return(a) end if ntab[z] == a then break 
    end end end end
function draw()
    background(40,40,50) offset=0 rectMode(CENTER) text("REPLAY",190,800) 
    text("NEW",600,800) 
    for y=4,1,-1 do for x=1,4 do offset = offset + 1
    fill(200,0,0) rect(x*size,y*size,size,size)
    fill(255) fontSize(60) text(ntab[offset],x*size,y*size) end end
    if done then str=string.format("Complete   %3d",count) 
        text(str,WIDTH/2,HEIGHT-100) else     
        str=string.format("Number of moves   %3d",count) 
        text(str,WIDTH/2,HEIGHT-50) end end
function touched(t)
    if t.state==BEGAN then
    if t.x>100 and t.x<300 and t.y>750 and t.y<850 then
    for z=1,16 do ntab[z]=otab[z] end count=0 done=false end
    if t.x>500 and t.x<700 and t.y>750 and t.y<850 then setup() end
    if not done then z=0 for y=4,1,-1 do for x=1,4 do z = z + 1
    if t.x > x*size-35 and t.x < x*size+35 then
    if t.y > y*size-35 and t.y < y*size+35 then checkblank(z) 
    end end end end end end end
function complete()    -- check for a completed game
    count = count + 1 for z = 1,15 do if ntab[z] ~= z then return 
    end end done=true end
function checkblank(pos)    -- check for the blank space 
    for z = 1,#tab[pos] do val = tab[pos][z]if ntab[val] == "" then 
    ntab[val] = ntab[pos] 
    ntab[pos] = "" complete() return end end end

omg guys stop being so good all entries other than mine just powned me so hard :o

Nice idea. Wanted to do a line animation. Draw several lines on the screen and animate between the line segments. Wanted to mess around with buffers, but didn’t get it working, but anyway :slight_smile:

function setup()
    displayMode(FULLSCREEN)
    m, ps = mesh(), {}
end

function draw()
    background(0, 0, 0, 255)
    m:clear()
    for i,v in ipairs(ps) do
        m:addRect(v.x, v.y, v.d, 2, v.a)
    end
    m:draw()
end

function touched(touch)
    p = vec2(touch.x, touch.y)
    if touch.state == BEGAN then
        sp, i = p, 1
    elseif touch.state == ENDED or (sp-p):len() > 10 then
        addline(sp, p)
        sp = p
    end
    if touch.state == ENDED then
        for x=i,#ps do 
            tween(.5, ps[x], {d=0}, tween.easing.quadInOut)
        end
    end
end

function addline(a,b)
    local v = b - a
    local p = a + v*.5
    p = {x=p.x, y=p.y,d=v:len(),a=-v:angleBetween(vec2(1,0))}
    if ps[i] then
        tween(.6, ps[i], p, tween.easing.quadInOut)
    else
        table.insert(ps, p)
    end
    i = i + 1
end