Version av: one bugfix, support for LÖVE 11.5


All of yesterday's changes included a new bug: touches sometimes moved the scrollbar when they shouldn't. You can read all about the gory details at https://git.sr.ht/~akkartik/carousel.love/commit/42cc608d06821fcefad5b0d25c5583a... I hope bugfix changes will have fewer bugs over time :/

LÖVE also came out with a new release 11.5 today. This version has been tested with it and all seems well.

Your program for the day is a new feature for yesterday's tree fractal that adds some interactivity:

Iters = 7
Zoom = 10
X0 = Safe_width*3/4
Y0 = Safe_height-10
N = Safe_height/2/Iters/Zoom
Left = -0.3
Right = 0.7
function car.draw()
  x,y = X0,Y0
  Angle = -pi/2
  Stack = {}
  color(1,0,1, 0.4)
  s = '0'
  for _ = 1,Iters do
    s = lsys(s)
  end
  --print(s)
  draw_lsys(s)
  draw_sliders()
end
function draw_lsys(s)
  for i=1,#s do
    local c = s:sub(i,i)
    if c == '0' or c == '1' then
      forward()
    elseif c == '[' then
      push()
    elseif c == ']' then
      pop()
    end
  end
end
function forward()
  local x2 = x + N*cos(Angle)
  local y2 = y + N*sin(Angle)
  line(x,y, x2, y2)
  --print('|', x,y, x2,y2)
  x, y = x2, y2
end
function push()
  table.insert(Stack, {x, y, Angle})
  Angle = Angle+Left
  --print('[', x,y, Angle)
end
function pop()
  x,y, Angle = unpack(Stack[#Stack])
  table.remove(Stack)
  Angle = Angle+Right
  --print(']', x,y, Angle)
end
function lsys(s)
  local result = {}
  for i=1,#s do
    local c = s:sub(i,i)
    if c == '1' then
      table.insert(result, '11')
    elseif c == '0' then
      table.insert(result, '1[0]0')
    else
      table.insert(result, c)
    end
  end
  return table.concat(result)
end
function draw_sliders()
  Iters_slider = {
    x0 = 50, y0 = Safe_width/2,
    x1 = 150,
    w=20, h=20,
    lo = 1, hi = 12,
    value = Iters,
  }
  draw_slider(Iters_slider)
end
function car.mouse_press(x,y, b)
  if on_slider(Iters_slider, x,y) then
    Iters_slider_selected = true
    return
  end
  Iters_slider_selected = nil
  --X0,Y0 = x,y
  Left = -x/Safe_width
  Right = y/Safe_height
end
function car.mouse_release(x,y, b)
  Iters_slider_selected = nil
end
function car.update(dt)
  if not Show_code and Iters_slider_selected then
   Iters = slider_value(Iters_slider, App.mouse_x())
  end
end

Files

carousel-av.love 108 kB
Dec 04, 2023
carousel-av-safe.love 108 kB
Dec 04, 2023

Get Lua Carousel

Leave a comment

Log in with itch.io to leave a comment.