[rgss] #-------------------------------------------------------------------------
# * 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
#-------------------------------------------------------------------------
# * 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
[/rgss]
cx and cy are undefined, so it doesn't work. Does anyone know how it should figure them out? (Or what they're even for?)
# * 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
#-------------------------------------------------------------------------
# * 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
[/rgss]
cx and cy are undefined, so it doesn't work. Does anyone know how it should figure them out? (Or what they're even for?)