TheoAllen

Devtool - Color Experiment

Jul 1st, 2013
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.00 KB | None | 0 0
  1. # =============================================================================
  2. # TheoAllen - Color Experiment
  3. # Version : 1.0
  4. # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
  5. # (English Documentation)
  6. # =============================================================================
  7. =begin
  8.  
  9.   Just a simple script to experiment color
  10.  
  11. =end
  12. # =============================================================================
  13. # Little configuration
  14. # =============================================================================
  15. module THEO
  16.   module COLOR
  17.    
  18.     SAMPLE_WIDTH  = Graphics.width
  19.   # Width of the window
  20.   # Graphics.width stand for width of the screen
  21.    
  22.     SAMPLE_TEXT   = "Sample Text"
  23.   # String for sample text
  24.  
  25.     EXPERIMENT    = true
  26.   # Set true if you want to experiment the color
  27.  
  28.     INITIAL_COLOR =  [255,   255,  255]
  29.   # Initial color in [red, green, blue]
  30.    
  31.   end
  32. end
  33. # =============================================================================
  34. # Rest of script
  35. # =============================================================================
  36. class Color_Experiment < Scene_Base
  37.  
  38.   def start
  39.     super
  40.     create_bg_sprite
  41.     create_rgb_window
  42.     create_window_samples
  43.     create_help
  44.     create_color_list
  45.   end
  46.  
  47.   def create_bg_sprite
  48.     @bg_sprite = Sprite.new
  49.     @bg_sprite.bitmap = Cache.parallax("BlueSky")
  50.     @bg_sprite.viewport = @viewport
  51.   end
  52.  
  53.   def create_rgb_window
  54.     @window_rgb = Window_RGBColor.new
  55.     @window_rgb.viewport = @viewport
  56.   end
  57.  
  58.   def create_window_samples
  59.     @samples = []
  60.     for i in 1..3
  61.       x = Graphics.width/2 - THEO::COLOR::SAMPLE_WIDTH/2
  62.       y = 48 * (i-1)
  63.       sample = Window_SampleColor.new(x,y,i)
  64.       sample.viewport = @viewport
  65.       sample.refresh(@window_rgb.color)
  66.       @samples.push(sample)
  67.     end
  68.     @window_rgb.sample_windows = @samples
  69.   end
  70.  
  71.   def create_help
  72.     @help_window = Window_ColorExHelp.new
  73.     @help_window.viewport = @viewport
  74.   end
  75.  
  76.   def create_color_list
  77.     @color_list = []
  78.     color = ["RED","GREEN","BLUE"]
  79.     for i in 0..2
  80.       x = (Graphics.width/3) * i
  81.       colorlist = Window_ColorList.new(x,Graphics.height - 48*3,color[i],i)
  82.       colorlist.viewport = @viewport
  83.       @color_list.push(colorlist)
  84.     end
  85.   end
  86.  
  87. end
  88.  
  89. class Window_ColorList < Window_Base
  90.  
  91.   def initialize(x,y,text,id)
  92.     super(x,y,Graphics.width/3,fitting_height(1))
  93.     color_args = [0,0,0,255]
  94.     color_args[id] = [255,255,255][id]
  95.     change_color(Color.new(*color_args))
  96.     draw_text(0,0,contents.width,line_height,text,1)
  97.   end
  98.  
  99. end
  100.  
  101. class Window_RGBColor < Window_HorzCommand
  102.   attr_writer :sample_windows
  103.  
  104.   def initialize
  105.     @color = THEO::COLOR::INITIAL_COLOR.clone
  106.     super(0,Graphics.height - 48*2)
  107.   end
  108.  
  109.   def col_max
  110.     return 3
  111.   end
  112.  
  113.   def color_list
  114.     @color
  115.   end
  116.  
  117.   def color
  118.     Color.new(*@color)
  119.   end
  120.  
  121.   def window_width
  122.     Graphics.width
  123.   end
  124.  
  125.   def update
  126.     super
  127.     increase if Input.repeat?(:UP)
  128.     decrease if Input.repeat?(:DOWN)
  129.     ten_increase if Input.press?(:SHIFT) && Input.repeat?(:UP)
  130.     ten_decrease if Input.press?(:SHIFT) && Input.repeat?(:DOWN)
  131.   end
  132.  
  133.   def make_command_list
  134.     add_command(@color[0],:red)
  135.     add_command(@color[1],:green)
  136.     add_command(@color[2],:blue)
  137.   end
  138.  
  139.   def increase
  140.     @color[index] += 1 unless max?
  141.     refresh
  142.   end
  143.  
  144.   def decrease
  145.     @color[index] -= 1 unless min?
  146.     refresh
  147.   end
  148.  
  149.   def ten_increase
  150.     @color[index] = [@color[index]+10,255].min
  151.     refresh
  152.   end
  153.  
  154.   def ten_decrease
  155.     @color[index] = [@color[index]-10,0].max
  156.     refresh
  157.   end
  158.  
  159.   def max?
  160.     @color[index] >= 255
  161.   end
  162.  
  163.   def min?
  164.     @color[index] <= 0
  165.   end
  166.  
  167.   def refresh
  168.     super
  169.     @sample_windows.each {|window| window.refresh(color)} if @sample_windows
  170.   end
  171.  
  172. end
  173.  
  174. class Window_SampleColor < Window_Base
  175.  
  176.   def initialize(x,y,type)
  177.     super(x,y,THEO::COLOR::SAMPLE_WIDTH,fitting_height(1))
  178.     @type = type
  179.     case @type
  180.     when 1
  181.       self.opacity = 255
  182.     when 2,3
  183.       self.opacity = 0
  184.     end
  185.   end
  186.  
  187.   def refresh(color)
  188.     contents.clear
  189.     change_color(color)
  190.     if @type == 2
  191.       color2 = Color.new(0,0,0,128)
  192.       color1 = Color.new(0,0,0,0)
  193.       contents.gradient_fill_rect(0,0,contents.width/2,contents.height,
  194.         color1, color2)
  195.       contents.gradient_fill_rect(contents.width/2,0,contents.width/2,
  196.         contents.height,color2, color1)
  197.     end
  198.     draw_text(0,0,contents.width,line_height,THEO::COLOR::SAMPLE_TEXT,1)
  199.   end
  200.  
  201. end
  202.  
  203. class Window_ColorExHelp < Window_Base
  204.  
  205.   def initialize
  206.     super(0,Graphics.height-48,Graphics.width,fitting_height(1))
  207.     text = "Press up / down to change the value. Press shift for more"
  208.     draw_text(0,0,contents.width,line_height,text,1)
  209.   end
  210.  
  211. end
  212.  
  213. if THEO::COLOR::EXPERIMENT
  214.   class << SceneManager
  215.    
  216.     def first_scene_class
  217.       Color_Experiment
  218.     end
  219.    
  220.   end
  221. end
Advertisement
Add Comment
Please, Sign In to add comment