Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Bitmap
- def draw_line(x1,y1,x2,y2,color = Color.new(255,255,255))
- jarak_x = (x2-x1).abs
- jarak_y = (y2-y1).abs
- if jarak_y == 0 || jarak_x == 0
- draw_horz(x1,y1,jarak_x,color) if jarak_y == 0
- draw_vert(x1,y1,jarak_y,color) if jarak_x == 0
- return
- end
- maximum = [jarak_x,jarak_y].max
- rasio_x = jarak_x / maximum.to_f
- rasio_y = jarak_y / maximum.to_f
- real_x = x1.to_f
- real_y = y1.to_f
- for i in 0..maximum
- fill_rect(x1,y1,1,1,color)
- real_x += rasio_x
- real_y += rasio_y
- x1 = real_x.round
- y1 = real_y.round
- end
- end
- def draw_horz(x,y,width,color = Color.new(255,255,255))
- fill_rect(x,y,width,1,color)
- end
- def draw_vert(x,y,height,color = Color.new(255,255,255))
- fill_rect(x,y,1,height,color)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment