История изменений
Исправление LINUX-ORG-RU, (текущая версия) :
mkdir pika && cd pika && touch main.lua
копипаста кода love .
из pika
каталога
local image = nil;
local previ = nil;
local pose = {x=0,y=0};
local scal = 0;
local sx = 0;
local sy = 0;
-- настроить окно
function love.load()
love.window.setTitle('Перетащи png картинку в это окошечко')
love.window.setMode(800,600,{resizable=true});
end
-- получить файл
function love.filedropped(file)
--love.filesystem.load("main.lua")()
local filename = file:getFilename();
local file_ext = filename:match("%.%w+$")
if file_ext == '.png' then
image = love.image.newImageData(file);
end
end
-- обработать файл
function love.update()
if image and previ ~= image then
local width, height = image:getDimensions();
for y = 1, height do
for x = 1, width do
local r, g, b, a = image:getPixel(x-1, y-1);
r,g,b,a = image_gray_to_color(r,g,b,a);
image:setPixel( x-1, y-1, r, g, b, a );
end
end
image = love.graphics.newImage(image);
previ = image;
local w,h = love.window.getMode()
sx,sy = w/image:getWidth(),h/image:getHeight();
pose.x = 0;
pose.y = 0;
scal = 0;
end
end
-- перемещение
function love.mousemoved(x,y,dx,dy)
if love.mouse.isDown(1) then
if dx ~= 0 then pose.x = pose.x + dx; end
if dy ~= 0 then pose.y = pose.y + dy; end
end
end
-- масштабирование
function love.wheelmoved(x,y)
scal = scal + y * 0.1;
end
-- преобразовать серый в цвета
function image_gray_to_color(r,g,b,a)
-- прикодим цвета каналов к единому значению
local fullgray = (r*0.33) + (g*0.33) + (b*0.33);
r = 0 + fullgray;
g = 0;
b = 1 - fullgray;
return r, g, b, a;
end
-- отрисовать результат
function love.draw()
if image then
love.graphics.draw(image,pose.x,pose.y,0,sx+scal,sy+scal);
end
end
Ненужно, но хуже не будет :D
Исходная версия LINUX-ORG-RU, :
mkdir pika && cd pika && touch main.lua
копипаста кода love .
из pika
каталога
local image = nil;
local previ = nil;
local pose = {x=0,y=0};
local scal = 0;
local sx = 0;
local sy = 0;
-- настроить окно
function love.load()
love.window.setTitle('Перетащи png картинку в это окошечко')
love.window.setMode(800,600,{resizable=true});
end
-- получить файл
function love.filedropped(file)
--love.filesystem.load("main.lua")()
local filename = file:getFilename();
local file_ext = filename:match("%.%w+$")
if file_ext == '.png' then
image = love.image.newImageData(file);
end
end
-- обработать файл
function love.update()
if image and previ ~= image then
local width, height = image:getDimensions();
for y = 1, height do
for x = 1, width do
local r, g, b, a = image:getPixel(x-1, y-1);
r,g,b,a = image_gray_to_color(r,g,b,a);
image:setPixel( x-1, y-1, r, g, b, a );
end
end
image = love.graphics.newImage(image);
previ = image;
local w,h = love.window.getMode()
sx,sy = w/image:getWidth(),h/image:getHeight();
pose.x = 0;
pose.y = 0;
scal = 0;
end
end
-- перемещение
function love.mousemoved(x,y,dx,dy)
if love.mouse.isDown(1) then
if dx ~= 0 then pose.x = pose.x + dx; end
if dy ~= 0 then pose.y = pose.y + dy; end
end
end
-- масштабирование
function love.wheelmoved(x,y)
scal = scal + y * 0.1;
end
-- преобразовать серый в цвета
function image_gray_to_color(r,g,b,a)
-- прикодим цвета каналов к единому значению
local fullgray = (r*0.33) + (g*0.3) + (b*0.33);
r = 0 + fullgray;
g = 0;
b = 1 - fullgray;
return r, g, b, a;
end
-- отрисовать результат
function love.draw()
if image then
love.graphics.draw(image,pose.x,pose.y,0,sx+scal,sy+scal);
end
end
Ненужно, но хуже не будет :D