-- Inchiki Takansetsu -- Last updated: <2017/11/02 21:35:49 +0900> function love.load() -- init -- set filter love.graphics.setDefaultFilter("nearest", "nearest") scr_w = 640 scr_h = 480 canvas = love.graphics.newCanvas(scr_w, scr_h) -- get window width and height wdw_w = love.graphics.getWidth() wdw_h = love.graphics.getHeight() scr_scale = math.min((wdw_w / scr_w), (wdw_h / scr_h)) scr_ofsx = (wdw_w - (scr_w * scr_scale)) / 2 scr_ofsy = (wdw_h - (scr_h * scr_scale)) / 2 -- load image bgimg = love.graphics.newImage("bg_640x480.png") img = love.graphics.newImage("ufo.png") img_w = img:getWidth() img_h = img:getHeight() -- work nmax = 64 bx = scr_w / 2 by = 0 startdeg = 0 poslist = {} for i=1,nmax do poslist[i] = {x=0, y=0} end -- framerate steady min_dt = 1 / 60 next_time = love.timer.getTime() end function love.update(dt) -- update next_time = next_time + min_dt -- get mouse position local mx, my = love.mouse.getPosition() mx = (mx - scr_ofsx) / scr_scale my = (my - scr_ofsy) / scr_scale local dw = mx - bx local dh = my - by local deg = startdeg local h = 100 for i=1,nmax do local ii = i - 1 local x = bx + (dw * ii / nmax) - (img_w / 2) local y = by + (dh * ii / nmax) - (img_h / 2) -- local hh = h * ii / nmax local hh = h x = x + hh * math.sin(math.rad(deg)) poslist[i].x = x poslist[i].y = y deg = deg + 8 end startdeg = startdeg + 360 * dt end function love.draw() -- set canvas love.graphics.setCanvas(canvas) -- draw BG love.graphics.setColor(255, 255, 255) love.graphics.draw(bgimg, 0, 0) love.graphics.setColor(255, 255, 255) -- draw objs for i=1,nmax do local x = poslist[i].x local y = poslist[i].y love.graphics.draw(img, x, y) end -- unset canvas love.graphics.setCanvas() -- draw canvas to window love.graphics.setColor(255, 255, 255) love.graphics.draw(canvas, scr_ofsx, scr_ofsy, 0, scr_scale, scr_scale) love.graphics.print("FPS: "..tostring(love.timer.getFPS()), 10, 10) love.graphics.print("env: "..tostring(love.system.getOS()), 10, 40) if love.system.getOS() == "Windows" then -- wait local cur_time = love.timer.getTime() if next_time <= cur_time then next_time = cur_time else love.timer.sleep(next_time - cur_time) end end end function love.keypressed(key, isrepeat) -- ESC to exit if key == "escape" then love.event.quit() end end