RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Bitmap Flipping

0 Members and 1 Guest are viewing this topic.

**
Rep:
Level 84
Koalas are awesome
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


  • 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
« Last Edit: December 12, 2009, 07:48:48 PM by miget man12 »
Spoiler for 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?
Quote
Olny 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