some larger examples using shared abbreviations

akkartik
Nov 23, 2023, 5:55 PM
XIFRMKAL7DXDOTXAAYZRBUTDQWUUYNS2AIDZSWZ2BDMIUVSXCEAQC

Dependencies

  • [2] MRI3JAQI better line-wrap onboarding screens
  • [3] OOSUBWKX subject people to a tutorial
  • [4] MJ6KKFVT give example panes a name

Change contents

  • replacement in 0078-Example_panes at line 131
    [3.3363][2.1493:1581]()
    'points, line = g.points, g.line',
    'rectangle, polygon = g.rectangle, g.polygon',
    [3.3363]
    [2.1581]
    'pt, line = g.points, g.line',
    'rect, poly = g.rectangle, g.polygon',
  • replacement in 0078-Example_panes at line 134
    [2.1637][3.3495:3551](),[3.3495][3.3495:3551]()
    'color, bgColor = g.setColor, g.setBackgroundColor',
    [2.1637]
    [2.1638]
    'color = g.setColor',
    'min, max = math.min, math.max',
    'abs, rand = math.abs, math.random',
  • edit in 0078-Example_panes at line 139
    [2.1705]
    [3.3784]
    },
    },
    {
    name='circ',
    lines={
    '-- a snazzy circle',
    'cx, cy, N = 30, 100, 100',
    'function dist2(x1,y1, x2,y2)',
    ' return (x2-x1)^2 + (y2-y1)^2',
    'end',
    '',
    'function car.draw()',
    ' for x=cx-N,cx+N do',
    ' for y=cy-N,cy+N do',
    ' if dist2(cx,cy, x,y) < N*N then',
    ' color(abs(x-cx)/N, abs(y-cy)/N, 0.5)',
    ' pt(x,y)',
    'end end end end',
    '',
    'function car.mousepressed(x,y, b)',
    ' cx,cy = x,y',
    'end',
    },
    },
    {
    name='pacman',
    lines={
    '-- pacman',
    'function init_balls()',
    ' balls = {}',
    ' for x=50,love.graphics.getWidth()-1,50 do',
    ' for y=30,love.graphics.getHeight()-1,50 do',
    ' table.insert(balls, {x=x, y=y, show = true})',
    'end end end',
    'init_balls()',
    '',
    'function eat_ball()',
    ' for _,b in ipairs(balls) do',
    ' if b.x == x and b.y == y then',
    ' b.show = false',
    'end end end',
    '',
    'x, y = 30, 30',
    'dx = 5',
    'dang = 0 -- change in mouth angle',
    '',
    'function car.draw()',
    ' love.graphics.setColor(0.8, 0.8, 0)',
    " love.graphics.arc('fill', x,y, 20, dang + 0.5, dang + 2*math.pi - 0.5)",
    ' for _,b in ipairs(balls) do',
    ' if b.show then',
    " love.graphics.circle('fill', b.x, b.y, 10)",
    'end end end',
    '',
    'function car.update(dt)',
    ' x = x+dx',
    ' eat_ball()',
    ' if x > love.graphics.getWidth() then',
    ' y, dx = y+50, -5',
    ' dang = math.pi',
    ' elseif x < 0 then',
    ' y, dx = y+50, 5',
    ' dang = 0',
    ' end',
    ' if y > love.graphics.getHeight() then',
    ' y = 30',
    ' init_balls()',
    ' end',
    'end',
    },
    },
    {
    name='trails',
    lines={
    '-- sweep trails with your finger',
    '-- (fingers on a phone or tablet)',
    'W,H = g.getDimensions()',
    'T = 0.1 -- seconds',
    'U = 0',
    '',
    'trails = {}',
    '',
    'function car.draw()',
    ' for _,trail in pairs(trails) do',
    ' color(trail.r, trail.g,trail.b)',
    ' for _,c in ipairs(trail) do',
    " circ('fill', c.x,c.y, c.r)",
    'end end end',
    '',
    'function car.update(dt)',
    ' U = U + dt',
    ' if U < T then return end',
    ' U = U - T',
    ' local touches = love.touch.getTouches()',
    ' for _,id in ipairs(touches) do',
    ' local x,y = love.touch.getPosition(id)',
    ' if trails[id] then',
    ' table.insert(trails[id], 1, {x=x, y=y, r=100})',
    'end end',
    ' for id,trail in pairs(trails) do',
    ' for i=#trail,1,-1 do',
    ' local c = trail[i]',
    ' c.r = c.r - 10',
    ' if c.r <= 0 then table.remove(trail, i) end',
    ' end',
    ' if #trail == 0 then trails[id] = nil end',
    ' end',
    'end',
    '',
    'function car.touchpressed(id, x,y, ...)',
    ' trails[id] = {r=rand(), g=rand(), b=rand()}',
    'end',