赞 | 1 |
VIP | 20 |
好人卡 | 8 |
积分 | 3 |
经验 | 6181 |
最后登录 | 2022-8-5 |
在线时间 | 271 小时 |
Lv2.观梦者 神隐的主犯
- 梦石
- 0
- 星屑
- 299
- 在线时间
- 271 小时
- 注册时间
- 2008-2-22
- 帖子
- 7691
|
- class Bitmap
- #--------------------------------------------------------------------------
- # ● 描绘直线
- # x1,y1,x2,y2: 直线两端的坐标
- # width: 宽度
- # color: 颜色
- #--------------------------------------------------------------------------
- def drawline(x1, y1, x2, y2, width, color)
- x1 = x1.to_f
- y1 = y1.to_f
- x2 = x2.to_f
- y2 = y2.to_f
- width = width.to_f
- k = (y2 - y1) / (x2 - x1)
- if k.abs > 1
- drawline_x(x1, y1, x2, y2, width, color)
- else
- drawline_y(x1, y1, x2, y2, width, color)
- end
- end
- def drawline_x(x1, y1, x2, y2, width, color)
- l = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 * width / (y1 - y2)
- length = l.abs * 2
- k = (x2 - x1) / (y2 - y1) #x=ky+b
- b = x1 - k * y1
- if l > 0
- for ty in y2.to_i..y1.to_i
- tx = ty * k + b
- fill_rect(tx - l, ty, length, 1, color)
- end
- else
- for ty in y1.to_i..y2.to_i
- tx = ty * k + b
- fill_rect(tx + l, ty, length, 1, color)
- end
- end
- end
- def drawline_y(x1, y1, x2, y2, width, color)
- l = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 * width / (x1 - x2)
- height = l.abs * 2
- k = (y2 - y1) / (x2 - x1) #y=kx+b
- b = y1 - k * x1
- if l > 0
- for tx in x2.to_i..x1.to_i
- ty = tx * k + b
- fill_rect(tx, ty - l, 1, height, color)
- end
- else
- for tx in x1.to_i..x2.to_i
- ty = tx * k + b
- fill_rect(tx, ty + l, 1, height, color)
- end
- end
- end
- end
复制代码
这里有一个,不过没用过~~ 系统信息:本贴由楼主认可为正确答案,66RPG感谢您的热情解答~ |
|