Project1
标题:
怎么用RGSS画线
[打印本页]
作者:
zh99998
时间:
2008-9-6 18:49
标题:
怎么用RGSS画线
RT [LINE]1,#dddddd[/LINE]
版务信息:本贴由楼主自主结贴~
作者:
八云紫
时间:
2008-9-6 18:52
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
复制代码
这里有一个,不过没用过~~ [LINE]1,#dddddd[/LINE]
系统信息:本贴由楼主认可为正确答案,66RPG感谢您的热情解答~
作者:
zh99998
时间:
2008-9-6 18:53
thx
作者:
雪流星
时间:
2008-9-6 18:54
阿
叁考我那个绘制几何图形的脚本
作者:
龙轩
时间:
2008-9-6 20:49
提示:
作者被禁止或删除 内容自动屏蔽
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1