The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => VX Scripts Database => Topic started by: miget man12 on December 12, 2009, 05:46:03 AM

Title: Bitmap Flipping
Post by: miget man12 on December 12, 2009, 05:46:03 AM
Bitmap Flipping
Version: 1.0
Author: Miget man12
Date: December 11, 2009

Version History


  • Version 1.0 12.11.2009 First version

Planned Future Versions

  • n/a

Description


I'm using this for another script I'm making and I figured I may as well post it ^_^ It flips bitmaps.

Features

  • Flip bitmaps up to down
  • Flip bitmaps left to right

Instructions

Paste in editor. THIS IS A SCRIPTER'S TOOL!

Script


Code: [Select]
# Credits to Miget man12!
# To flip a bitmap left to right, call:
#  bitmap.flip_lr
# To flip a bitmap up to down, call:
#  bitmap.flip_ud
class Bitmap
  def flip_lr # Flip Left/Right
    stored_red = Table.new(self.width,self.height)
    stored_grn = Table.new(self.width,self.height)
    stored_blu = Table.new(self.width,self.height)
    stored_alp = Table.new(self.width,self.height)
    for y in 0..(self.height)
      for x in 0..(self.width)
        stored_red[x,y]=self.get_pixel(x,y).red
        stored_grn[x,y]=self.get_pixel(x,y).green
        stored_blu[x,y]=self.get_pixel(x,y).blue
        stored_alp[x,y]=self.get_pixel(x,y).alpha
      end
    end
    for y in 0..(self.height-1)
      for x in 0..(self.width-1)
        next if stored_red[self.width-x,y].nil? or stored_grn[self.width-x,y].nil? or stored_blu[self.width-x,y].nil? or stored_alp[self.width-x,y].nil?
        self.set_pixel(x,y,Color.new(stored_red[self.width-x,y],stored_grn[self.width-x,y],stored_blu[self.width-x,y],stored_alp[self.width-x,y]))
      end
    end
  end
  def flip_ud # Flip Up/Down
    stored_red = Table.new(self.width,self.height)
    stored_grn = Table.new(self.width,self.height)
    stored_blu = Table.new(self.width,self.height)
    stored_alp = Table.new(self.width,self.height)
    for y in 0..(self.height)
      for x in 0..(self.width)
        stored_red[x,y]=self.get_pixel(x,y).red
        stored_grn[x,y]=self.get_pixel(x,y).green
        stored_blu[x,y]=self.get_pixel(x,y).blue
        stored_alp[x,y]=self.get_pixel(x,y).alpha
      end
    end
    for y in 0..(self.height)
      for x in 0..(self.width)
        next if stored_red[x,y].nil? or stored_grn[x,self.height-y].nil? or stored_blu[x,self.height-y].nil? or stored_alp[x,self.height-y].nil?
        self.set_pixel(x,y,Color.new(stored_red[x,self.height-y],stored_grn[x,self.height-y],stored_blu[x,self.height-y],stored_alp[x,self.height-y]))
      end
    end
  end
end

Credit



Support


I'd very much prefer contact on this topic ;)

Known Compatibility Issues

I can't fathom any sort of compatibility issues this could have.

Author's Notes


Useless for non-scripters really :D

~Miget man12