Save-Point

Full Version: Save-Point
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Board Message
Sorry, you do not have permission to access this resource.
Save-Point - draw_polygon problem

Save-Point

Full Version: draw_polygon problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello there guys,

It's been years since I stopped using RMXP, but with mkxp-z I revived some old projects and I'm back developing stuff.

However I got stuck with some old methods from MACL (do you guys still remember that?)

I'm having some trouble using the Bitmap's method "draw_polygon":

Code:
#-------------------------------------------------------------------------
 # * Name      : Draw Polygon
 #   Info      : Draws a Polygon
 #   Author    : Caesar (Rewrote By Trickster)
 #   Call Info : Array vertices - Points of the polygon
 #               Integer width - Thickness of the lines
 #               Color color - color to draw it in
 #               Boolean filled - false outline true filled
 #               Integer step - fill steps
 #   Comments  : Example of vertices setup [[30, 80], [80, 80], [30, 60]]
 #-------------------------------------------------------------------------
 def draw_polygon(vertices, stroke = 1, color = Color.new(255, 255, 255),
   filled = false, step = 1)
   # Return if no width or not enough points
   return if stroke <= 0 or vertices.size <= 2
   # Get Count
   count = vertices.size
   # Get Points
   x1, y1, x2, y2 = vertices[-1] + vertices[0]
   # Draw Line
   draw_line(x1, y1, x2, y2, stroke, color)
   # Shade if filled
   shade_section(cx, cy, x1, y1, x2, y2, stroke, step, color) if filled
   # Run Through with next
   vertices.each_with_next do |start, point|
     # Get Points
     x1, y1, x2, y2 = start + point
     # Draw Line
     draw_line(x1, y1, x2, y2, stroke, color)
     # Shade if filled
     shade_section(cx, cy, x1, y1, x2, y2, stroke, step, color) if filled
   end
 end

It works just fine, unless I mark the filled boolean as true. It causes some problem to me since cx and cy doesn't seem to exist in the method "shade_section". I tried to fix it, but I couldn't manage to solve it so far. Check the method shade_section below:

Code:
 #-------------------------------------------------------------------------
 # * Name      : Shade Section
 #   Info      : Shades a section from (cx,cy), (x1,y1), (x2,y2)
 #   Author    : Trickster
 #   Call Info : Six to Nine Arguments
 #               Integer cx, cy, x1, y1, x2, y2 - Points
 #               Integer Thick - Line Thickness
 #               Integer Step - how many lines to draw (lower = higher accuracy)
 #               Color color - color to shade in
 #-------------------------------------------------------------------------
 def shade_section(cx, cy, x1, y1, x2, y2, thick = 1, step = 1,
     color = Color.new(255, 255, 255))
   # Reverse all parameters sent if 2 x is less than the first x
   x1, x2, y1, y2 = x2, x1, y2, y1 if x2 < x1    
   # Get Slope
   slope = (y2 - y1).to_f / (x2 - x1)
   # If Slope is infinite
   if slope.infinite?
     y1.step(y2, step) {|y| draw_line(cx, cy, x1, y, thick, color)}
   # If Slope is zero
   elsif slope.zero?
     x1.step(x2, step) {|x| draw_line(cx, cy, x, y1, thick, color)}
   elsif not slope.nan?
     # Get Y intercept
     yint = y1 - slope * x1
     x1.step(x2, step) {|x| draw_line(cx, cy, x, slope * x + yint, thick, color)}
   end
 end
end

Any help would be appreciated. I just wanna draw color filled polygons :(
If you guys may need MACL, I'll attach the version I currently got. Thanks in advance!
Yes, the issue is the shade selection method.  I do not see any sign where the cx and cy values are even generated.  Without those, the shade_selection feature is moot.