TokOut's collection

@TokOut - it takes more than a few minutes to learn physics

You need to practise a lot more (and write less on the forum)

-- load needed modules
local http = require("socket.http")
local ltn12 = require("ltn12")

-- a simplified http.get function
function http.get(u)
  local t = {}
  local respt = request{
    url = u,
    sink = ltn12.sink.table(t)
  }
  return table.concat(t), respt.headers, respt.code
end

Can someone explain me how to make this without errors?

Here is my new project in short form (no ACESS to creating files etc.). I hope you like it.

function setup()
    displayMode(FULLSCREEN)
    column = {"Primary", "String", "Num"}
    row = {{1, "Text...", 4793}, {2, "More text...", 1602}, {3, "Only a lot of text here....", 6901}}
    sR = 50
    parameter.text("String", "Text")
    parameter.integer("Num", 0, 9999, 0)
    parameter.action("Add", action)
    parameter.action("Clear database", function() row = {} end)
end

function draw()
    background(167, 167, 167, 255)
    strokeWidth(5)
    stroke(0, 0, 0, 255)
    fill(0, 0, 0, 255)
    fontSize(20)
    font("ArialMT")
    local a = nil
    
    for c,cData in ipairs(column) do
        for r,rData in ipairs(row) do
            line(20, 20, 20, HEIGHT-20)
            line(20, 20, WIDTH-20, 20)
            line(WIDTH-20, 20, WIDTH-20, HEIGHT-20)
            line(20, HEIGHT-20, WIDTH-20, HEIGHT-20)
            line(100, 20, 100, HEIGHT-20)
            line(20, HEIGHT-(20+sR*r), WIDTH-20, HEIGHT-(20+sR*r))
            line(650, 20, 650, HEIGHT-20)
            
            a,_ = textSize(rData[1])
            text(rData[1], 25+a/2, HEIGHT-(sR*r))
            a,_ = textSize(rData[2])
            text(rData[2], 105+a/2, HEIGHT-(sR*r))
            a,_ = textSize(rData[3])
            text(rData[3], 655+a/2, HEIGHT-(sR*r))
        end
    end
end

function action()
    print(String .. "\
" .. Num)
    local id = #row + 1
    table.insert(row, {id, String, Num})
end

Another version of same code, if you want to show a message, when there are no rows.

function setup()
    displayMode(FULLSCREEN)
    column = {"Primary", "String", "Num"}
    row = {{1, "Text...", 4793}, {2, "More text...", 1602}, {3, "Only a lot of text here....", 6901}}
    sR = 50
    parameter.text("String", "Text")
    parameter.integer("Num", 0, 9999, 0)
    parameter.action("Add", action)
    parameter.action("Clear database", function() row = {} end)
end

function draw()
    background(167, 167, 167, 255)
    strokeWidth(5)
    stroke(0, 0, 0, 255)
    fill(0, 0, 0, 255)
    fontSize(20)
    font("ArialMT")
    local a = nil
    
    for c,cData in ipairs(column) do
        line(20, 20, 20, HEIGHT-20)
        line(20, 20, WIDTH-20, 20)
        line(WIDTH-20, 20, WIDTH-20, HEIGHT-20)
        line(20, HEIGHT-20, WIDTH-20, HEIGHT-20)
        for r,rData in ipairs(row) do
            line(100, 20, 100, HEIGHT-20)
            line(20, HEIGHT-(20+sR*r), WIDTH-20, HEIGHT-(20+sR*r))
            line(650, 20, 650, HEIGHT-20)
            
            a,_ = textSize(rData[1])
            text(rData[1], 25+a/2, HEIGHT-(sR*r))
            a,_ = textSize(rData[2])
            text(rData[2], 105+a/2, HEIGHT-(sR*r))
            a,_ = textSize(rData[3])
            text(rData[3], 655+a/2, HEIGHT-(sR*r))
        end
    end
    
    if #row == 0 then
        text("No rows!", WIDTH/2, HEIGHT/2)
    end
end

function action()
    print(String .. "\
" .. Num)
    local id = #row + 1
    table.insert(row, {id, String, Num})
end

If being serious, I didn’t know why there are no lines drawing when there are 0 rows. But then I searched a bit (I didn’t even search in the Internet.) and found my answer

Please rate my small painting:

function setup()
    drawings = {}
    Help = " In this example you see how to create a simple paint."..
    "\
 Paint Type 1 is a rect, 2 is an ellipse" ..
    "\
 Paint Size and Color make it only beatiful."
    ChangeLog = [[<=> Version 0.1 <=>
• Possible to draw ellipses and rects.
• Can specify color and size
• You can undo and clear drawings.
    
Known bug: Undo deletes only one paint.
    ]]
    parameter.watch("Help")
    parameter.color("PaintColor", 255)
    parameter.integer("PaintSize", 0, 250, 10)
    parameter.integer("PaintType", 1, 2, 1)
    parameter.action("Clear Drawing", function() drawings = {} end)
    parameter.action("Undo", undo)
    parameter.watch("ChangeLog")
end

function draw()
    background(0, 0, 0, 255)
    for _,v in ipairs(drawings) do
        v:draw()
    end
end

function touched(t)
    if t.state == ENDED then else
        table.insert(drawings, paint(PaintColor, PaintSize, vec2(t.x, t.y), PaintType))
    end
end

-- Functions
function undo()
    if #drawings > 0 then
        table.remove(drawings, #drawings)
    end
end

-- Paint Operation
paint = class()

function paint:init(col, size, pos, typ)
    self.c = col
    self.s = size
    self.p = pos
    self.t = typ
end

function paint:draw()
    fill(self.c)
    if self.t == 1 then
        rectMode(CENTER)
        rect(self.p.x, self.p.y, self.s, self.s)
    elseif self.t == 2 then
        ellipseMode(CENTER)
        ellipse(self.p.x, self.p.y, self.s, self.s)
    end
end

Say me what I can do better?

One thing you can do is use setContext and draw to a table of images. Each time you touch the screen, draw something, then lift your finger, what you just drew can go into the next image. That way you’re not filling up one table with all of your draw info. Also by having a table of images, you can go back and delete any image instead of a single item. You can set up a parameter slider that will let you view each image by itself and another Boolean parameter to delete any image. So basically you have a table of images that are drawn one after the other. If you have questions about this, I already have something like what I described.

@TokOut Here’s a stripped down version of what I was talking about. To see what this does, draw letters or numbers and then use the pos slider to see each individual image. Use the delete slider to delete an image.

EDIT: The problem with this is it uses a lot of memory to save the images. A different version would be to save the drawings table instead of the image. That version uses a lot less memory. It was a simple change to do that.

function setup()
    tab={}
    drawings={}
    showParams()
end

function showParams()
    parameter.clear()
    parameter.integer("pos",0,#tab,0)
    parameter.boolean("delete",false)
end

function draw()
    background(0)
    fill(255)
    if pos>0 then   -- show individual images
        sprite(tab[pos],WIDTH/2,HEIGHT/2)   
        if delete then  -- delete image
            table.remove(tab,pos)
            showParams()
        end
    else
        if save then    -- save current image
            save=false
            img=image(WIDTH,HEIGHT)
            setContext(img)
            for a,b in pairs(drawings) do
                ellipse(b.x,b.y,5)
            end
            setContext()
            table.insert(tab,img)
            showParams()
            drawings={}
        end
        for a,b in pairs(tab) do    -- show all images
            sprite(b,WIDTH/2,HEIGHT/2)
        end
        for a,b in pairs(drawings) do   -- show current drawing
            ellipse(b.x,b.y,5)
        end    
    end
    if delete then  -- always turn delete off
        delete=false
    end
end

function touched(t)
    if pos>0 then   -- only allow drawings when pos = 0
        return
    end
    if t.state==BEGAN then
        drawings={}
        table.insert(drawings,vec2(t.x,t.y))
    end
    if t.state==MOVING then
        table.insert(drawings,vec2(t.x,t.y))
    end
    if t.state==ENDED then
        save=true
    end
end

Thank you.

Made a new game game, say what you think, please: https://raw.githubusercontent.com/TokOut/InOneClass/master/Bumping-Bombs.lua
Going to add an installer now.

Bumping bombs

n = 0
displayMode(FULLSCREEN)

local function success(data)
    if data:find("%-%-%# Main") then
        data = data.."--# "
        for name, file in data:gmatch("(%w+)\
(.-)\
%-%-%# ") do
            saveProjectTab(name, file)
            print(n .." tabs saved.")
            n = n + 1
        end
    else
        saveProjectTab("Main", data)
    end
    load(data)()
    restart()
end

local function failure(error)
    print("Error", error)
end

http.request("https://raw.githubusercontent.com/TokOut/InOneClass/master/Bumping-Bombs.lua", success, failure)

Hope you enjoy

Game crashes Codea.

For me it doesn’t :wink:

-- Beauty

function setup()
    displayMode(FULLSCREEN)
    TRIS = {}
    for n = 1, 30 do
        table.insert(TRIS, Triangle())
    end
end

function draw()
    background(0)
    for a, b in ipairs(TRIS) do
        b:draw()
    end
end

Point = class()

function Point:init()
    self.pos = math.random(0, 2*(WIDTH+HEIGHT))
    self.speed = math.random(10, 50)
end

function Point:update()
    self.pos = self.pos + self.speed
end

function Point:vector()
    ::back::
    
    if self.pos <= HEIGHT then
        return vec2(0, self.pos)
    elseif self.pos <= WIDTH+HEIGHT then
        return vec2(self.pos-HEIGHT, HEIGHT)
    elseif self.pos <= WIDTH+2*HEIGHT then
        return vec2(WIDTH, WIDTH+2*HEIGHT-self.pos)
    elseif self.pos < 2*(WIDTH+HEIGHT) then
        return vec2(2*(WIDTH+HEIGHT)-self.pos, 0)
    else
        self.pos = self.pos - 2*(WIDTH+HEIGHT)
        goto back
    end
    
    assert(false, "Impossible appearence")
end

Color = class()

function Color:init()
    self.col = math.random(1, 1530) -- 1530 = 255 * 6 times
    self.speed = math.random(5, 25)
end

function Color:update()
    self.col = self.col + self.speed
end

function Color:color() color(255, 0, 178, 255)
    ::top::
    
    if self.col <= 255 then
        return color(255, self.col, 0, 255)
    elseif self.col <= 510 then
        return color(510-self.col, 255, 0, 255)
    elseif self.col <= 765 then
        return color(0, 255, self.col-510, 255)
    elseif self.col <= 1020 then
        return color(0, 1020-self.col, 255)
    elseif self.col <= 1275 then
        return color(self.col-1020, 0, 255)
    elseif self.col <= 1530 then
        return color(255, 0, 1530-self.col)
    else
        self.col = self.col - 1530
        goto top
    end
end

Triangle = class()

function Triangle:init()
    self.points = {Point(), Point(), Point()}
    self.colors = {Color(), Color(), Color()}
    
    self.tri = mesh()
    self.tri.colors = {self.colors[1]:color(), self.colors[2]:color(), self.colors[3]:color()}
    self.tri.vertices = {self.points[1]:vector(), self.points[2]:vector(), self.points[3]:vector()}
end

function Triangle:draw()
    self.tri:draw()
    self.tri.vertices = {self.points[1]:vector(), self.points[2]:vector(), self.points[3]:vector()}
    self.tri.colors = {self.colors[1]:color(), self.colors[2]:color(), self.colors[3]:color()}
    for a, b in ipairs(self.points) do
        b:update()
    end
    for a, b in ipairs(self.colors) do
        b:update()
    end
end

Makes you dizzy after awhile. Nice effect.

@dave1707 I tried :joy: