iPhone App Directory
RPG Maker VX
 
Gallery Members Search Calendar Help


Welcome Guest ( Log In | Register )

Collapse

>Announcement

Keep an eye out for the upcoming 3rd Quarter Contest!
 
Reply to this topicStart new topic
> Bitmap Flipping~, (scripters' tool)
Miget man12
post Dec 12 2009, 05:22 PM
Post #1


Lulz.
Group Icon


Type: Coder
Alignment: Unaligned




Bitmap Flipping v1.0
by Miget man12



Introduction
I was making this script for a script I was making for my game and I figured I may as well post it here happy.gif

Features
- Flip bitmaps up-down
- Flip bitmaps left-right

How to Use
1. Paste in editor
2. Call -
CODE
bitmap.flip_lr # to flip bitmaps left-right
bitmap.flip_ud # to flip bitmaps up-down


Script

Spoiler:
CODE
# 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


FAQ

Q: What is this used for?
A: Again, really only useful for ruby-experienced makers smile.gif

Credit and Thanks
- Miget man12


~Miget man12

This post has been edited by Miget man12: Dec 12 2009, 06:54 PM


--------------------
Spoiler:
I 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?
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!
fi yuo cna raed tihs, palce it in yuor siantugre.


I'm a lot more active here: http://www.rpgrevolution.com/forums/index.php

Go to the top of the page
 
+Quote Post
   
Omegas7
post Dec 12 2009, 06:27 PM
Post #2


stai sprecando il tuo tempo
Group Icon


Type: Coder
Alignment: Chaotic Evil




Thanks for the nice script wink.gif. The Sprite class had a nice property called "Mirror" I always used for flipping images too smile.gif.

Anyway, I tested yer script and found a minor problem:

I used a simple picture for my testing purposes...
Attached File  test.PNG ( 1.49K ) Number of downloads: 11


I used the flip_lr method with the bitmap...
Attached File  bug.PNG ( 2.76K ) Number of downloads: 34


I used this call script, maybe it was my fault:
CODE
sprite = Sprite_Base.new
sprite.bitmap = Cache.picture('test')
sprite.bitmap.flip_lr





As you can see, not everything is flipped.
I haven't tested the flip_ud, but probably the same problem might be present.

~~~~~

But a nice script it is, thanks laugh.gif .

This post has been edited by Omegas7: Dec 12 2009, 06:29 PM


--------------------
Chooo Chooo
Go to the top of the page
 
+Quote Post
   
Miget man12
post Dec 12 2009, 06:53 PM
Post #3


Lulz.
Group Icon


Type: Coder
Alignment: Unaligned




I feel smart biggrin.gif
yeah, stupid error on my part - here's the fix:
Spoiler:
CODE
# 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


~Miget man12


--------------------
Spoiler:
I 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?
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!
fi yuo cna raed tihs, palce it in yuor siantugre.


I'm a lot more active here: http://www.rpgrevolution.com/forums/index.php

Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 23rd July 2014 - 12:46 AM

RPGMakerVX.net is an Privacy Policy, Legal.