RMRK is retiring.
Server is paid up for the rest of 2026, but the forum may go after that. See here for more information. Please archive or save anything you would like to keep before 2027.
Main Menu
  • Welcome to The RPG Maker Resource Kit.

Bitmap Flipping

Started by miget man12, December 12, 2009, 05:46:03 AM

0 Members and 1 Guest are viewing this topic.

miget man12

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



# 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




  • Miget man12

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
[spoiler=My Scripts]Simple Footsteps Script
More-That-Usually Graphical Title Screen
Background Messages
Simple To Use Fogs
[/spoiler][spoiler=BIG]A mini-biography-ish thing of meI am learning to script with Ruby/RGSS2, I think I'm getting pretty good at it :)
Oh yeah, and I know Latin, that count's for something, doesn't it?
This is amazing, can you raed it?
QuoteOlny 55% of plepoe can raed this.
I cdnuolt blveiee taht I cluod aulaclty uesdnatnrd waht I was rdanieg. The phaonmneal pweor of the hmuan mnid, aoccdrnig to a rscheearch at Cmabrigde Uinervtisy, it dseno't mtaetr in waht oerdr the ltteres in a wrod are, the olny iproamtnt tihng is taht the frsit and lsat ltteer be in the rghit pclae. The rset can be a taotl mses and you can sitll raed it whotuit a pboerlm. Tihs is bcuseae the huamn mnid deos not raed ervey lteter by istlef, but the wrod as a wlohe. Azanmig huh? yaeh and I awlyas tghuhot slpeling was ipmorantt! Spelling is important!! :D
fi yuo cna raed tihs, palce it in yuor siantugre.
The Best Ruby Guide I've Found: Why's (poignant) guide to ruby