Method: GraphHelper#draw_line
- Defined in:
- lib/graph_helper.rb
#draw_line(x1, y1, x2, y2, r, g, b, graph_function = false) ⇒ Object
This function will draw an aliased line between points (x1,y1) and (x2,y2). The last 3 parameters are used to set the line color. The last optional parameter is used for internal calls made by graphing function.If set to true, only portions of line inside the graph area will be drawn.
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/graph_helper.rb', line 267 def draw_line(x1,y1,x2,y2,r,g,b,graph_function=false) if ( @line_dot_size > 1 ) draw_dotted_line(x1,y1,x2,y2,@line_dot_size,r,g,b,graph_function) else b, g, r = validate_color(b, g, r) distance = Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)) rescue 0 if ( distance == 0 ) return -1 else x_step = (x2-x1) / distance y_step = (y2-y1) / distance i =0 while i<=distance x = i * x_step + x1 y = i * y_step + y1 if((x >= @g_area_x1.to_f && x <= @g_area_x2.to_f && y >= @g_area_y1.to_f && y <= @g_area_y2.to_f) || !graph_function ) if ( @line_width == 1 ) draw_antialias_pixel(x,y,r,g,b) else start_offset = -(@line_width/2) end_offset = (@line_width/2) j = start_offset while j<=end_offset draw_antialias_pixel(x+j,y+j,r,g,b) j+=1 end end end i =i+1 end end end end |