Bitmap Gradient for Bars

0 Members and 1 Guest are viewing this topic.

*
Full Metal Mod - He will pillage your women!
Rep:
Level 93
The RGSS Dude
Using a method I found on Dubealex to create a gradient, I created a method that allows you to create a gradient bar using 1 or more colors.

If using 1 color, it will obviously be a solid color.

But if you use 2 or more, it will automaticly calculate the width and gradient for each section creating a gradient using all the colors you supplied in order.

Code: [Select]
class Bitmap
def grade(x,y,width,height,start,finish)
for i in 0..width
r = start.red * (width - i) / width + finish.red * i / width
g = start.green * (width - i) / width + finish.green * i / width
b = start.blue * (width - i) / width + finish.blue * i / width
a = start.alpha * (width - i) / width + finish.alpha * i / width
fill_rect(x + i,y,1,height,Color.new(r, g, b, a))
end
end
def draw_gradient(x,y,width,height,colors)
gradient_width = ((width * 1.0) / (colors.size - 1))
    if colors.size == 1
      grade(x,y,width,height,colors[0],colors[0])
      return
    end
for i in 0..(colors.size - 2)
x_var = (x + (i * gradient_width))
grade(x_var,y,gradient_width,height,colors[i],colors[i + 1])
end
end
end

I created a simple hp bar using the above script as an example -

[code]class Window_Base < Window
« Last Edit: April 06, 2006, 12:50:14 AM by Tsunokiette »
"The wonderful thing about Tiggers
Is Tiggers are wonderful things
Their tops are made out of rubber
Their bottoms are made out of springs

They’re bouncy, trouncy, flouncy, pouncy
Fun, fun, fun, fun, fun!
But the most wonderful thing about Tiggers
Is I’m the only one, I’m the only one."

********
EXA
Rep:
Level 92
Pikachu on a toilet
Project of the Month winner for April 2007
Lol, remembers me of the scripts in my game.
:mrgreen: Shaft: "Of course it does. The gradient addition in your game IS Dubealex
Get King of Booze for Android, for iOS, for OUYA or for Windows!
Visit our website.
You can also love/hate us on Facebook or the game itself.


Get DropBox, the best free file syncing service there is!

*
Full Metal Mod - He will pillage your women!
Rep:
Level 93
The RGSS Dude
lol, to tell you the truth, it's taking me so long to work on the other scripts I'm working on, (I keep changing them), that I felt like I wasn't really producing anything.

Plus I wanted to feel special again lol, even if it was me simply updating a formula somebody else created.
"The wonderful thing about Tiggers
Is Tiggers are wonderful things
Their tops are made out of rubber
Their bottoms are made out of springs

They’re bouncy, trouncy, flouncy, pouncy
Fun, fun, fun, fun, fun!
But the most wonderful thing about Tiggers
Is I’m the only one, I’m the only one."

********
EXA
Rep:
Level 92
Pikachu on a toilet
Project of the Month winner for April 2007
Get King of Booze for Android, for iOS, for OUYA or for Windows!
Visit our website.
You can also love/hate us on Facebook or the game itself.


Get DropBox, the best free file syncing service there is!

**
Rep: +0/-0Level 88
Righteous Crusaders
According to your siggy you're an SDK user, right?  So is this SDK or non-SDK?

*
? ? ? ? ? ? ? ? ? The nice kind of alien~
Rep:
Level 92
Martian - Occasionally kind
It works without SDK.

**
Rep: +0/-0Level 88
Righteous Crusaders
Oh, okay.  Awesome job, Tsunokiette.

*
Rep:
Level 97
Definitely better than Hitler.
2014 Best IRC Chatterbox2014 Best Musician2013 King of RMRK2013 Best Musician2013 Best Use of Avatar and Signature Space2013 Funniest MemberFor the great victory in the Breakfast War.2012 Best Musician2012 Best UsernameFor frequent good quality Wiki writing [citation needed]2011 Funniest Member2011 Best MusicianMost entertaining member on the IRC2010 Most Missed Member
Moved to database to make Tsuno feel special.  :-D
:tinysmile:

********
Rep:
Level 96
2011 Most Missed Member2010 Zero To Hero
This is exactly what I need for an event I am making. Where does it get inserted into the script database?