Horizontal Image Reverse

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Horizontal Image Reverse

Post by BlackBulletIV »

Just thought I'd share my horizontal image reversing program I made. I've included a flaming horse image in it, so all you have to do is run the .love file. (But you can also specify your own image via the terminal) Here's the code:

Code: Select all

function love.load(args)
  data = love.image.newImageData(args[2] or 'flaming_horse.jpg')
  half = {}
  
  for x = 0, data:getWidth() / 2 - 1 do
    half[x] = {}
    
    for y = 0, data:getHeight() - 1 do
      r, g, b, a = data:getPixel(x, y)
      half[x][y] = { r, g, b, a }
    end
  end

  data:mapPixel(function(x, y, r, g, b, a)
    if x < data:getWidth() / 2 then
      return data:getPixel(data:getWidth() - x - 1, y)
    else
      return unpack(half[data:getWidth() - x - 1][y])
    end
  end)
  
  img = love.graphics.newImage(data)
  img2 = love.graphics.newImage(args[2] or 'flaming_horse.jpg')
end

function love.draw()
  love.graphics.draw(img)
  love.graphics.draw(img2, 270)
end
Attachments
image_reverse.love
(21.84 KiB) Downloaded 104 times
User avatar
crow
Party member
Posts: 186
Joined: Thu Feb 24, 2011 11:47 pm
Location: UK
Contact:

Re: Horizontal Image Reverse

Post by crow »

nice :)
Sir Kittenface
Möko IDE Codename (Erös) Returns Soon

I am dyslexic so if any of my replys confusing please just ask me to reword it as this will make things a lot easier for all parties lol.
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Horizontal Image Reverse

Post by BlackBulletIV »

Thanks :)
User avatar
headchant
Party member
Posts: 105
Joined: Fri Sep 03, 2010 12:39 pm
Contact:

Re: Horizontal Image Reverse

Post by headchant »

That's nice! Maybe I didn't get it but whats wrong with the negative scale on x axis (edit: as not described in the wiki)?

something like this:

Code: Select all

function love.draw()
	love.graphics.draw(img, 100, 100)
	love.graphics.draw(img, 600, 100,0,-1,1)
end
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Horizontal Image Reverse

Post by BlackBulletIV »

Thanks. I honestly forgot about a negative scale, however I didn't do this for any purpose... apart from the desire to do some image manipulation. The main thing you could use this for, is reversing images for saving them, rather than displaying them.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest