Method: GraphHelper#draw_dotted_line
- Defined in:
- lib/graph_helper.rb
#draw_dotted_line(x1, y1, x2, y2, dot_size, r, g, b, graph_function = false) ⇒ Object
This function will draw an aliased dotted line between points (x1,y1) and (x2,y2). Parameter #5 is used to specify the dot size ( 2 will draw 1 point every 2 points ) The last 3 parameters are used to set the line color.
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'lib/graph_helper.rb', line 326 def draw_dotted_line(x1,y1,x2,y2,dot_size,r,g,b,graph_function=false) b, g, r = validate_color(b, g, r) distance = Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)) x_step = (x2-x1) / distance y_step = (y2-y1) / distance dot_index = 0 i = 0 start_offset = 0 while(i<=distance) x = i * x_step + x1 y = i * y_step + y1 if ( dot_index <= dot_size) if ( (x >= @g_area_x1 && x <= @g_area_x2 && y >= @g_area_y1 && y <= @g_area_y2) || !graph_function ) if (@line_width == 1 ) draw_antialias_pixel(x,y,r,g,b) else start_offset = 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= j+1 end end end end dot_index = dot_index+1 dot_index = 0 if (dot_index == dot_size * 2) i= i+1 end end |