主题:用vb进行画图
lang12
[专家分:0] 发布于 2010-03-21 22:01:00
本人想学习用vb进行画图,刚刚开始 ,还没头绪,请大家帮帮忙,举个例子,如何用vb画出一个金钢石图形,就是画出一个圆,然后在圆上定点一些点(设为12个),然后每个点两两相连接,怎么实现,请各位帮帮忙
最后更新于:2010-03-31 22:42:00
回复列表 (共7个回复)
沙发
老大徒伤悲 [专家分:29120] 发布于 2010-03-25 08:34:00
首先请你确定“画出一个圆,然后在圆上定点一些点(设为12个),然后每个点两两相连接”就是你所谓的金刚石。
板凳
lang12 [专家分:0] 发布于 2010-03-27 14:02:00
Private Sub Form_Activate()
Dim a, b, r, n, t, x(15), y(15), i, j
a = 0
b = 0
r = 2
n = 12
t = 6.283185 / n
Me.Circle (a, b), r
For i = 1 To n
x(i) = a + r * Cos(i * t)
y(i) = b + r * Sin(i * t)
i = i + 1
Next i
For i = 1 To n - 2
For j = i + 1 To n - 1
Me.Line (x(i), y(i))-(x(j), y(j))
j = j + 1
Next j
i = i + 1
Next i
End Sub
Private Sub Form_Load()
Me.Scale (-4, 4)-(4, -4)
End Sub
以上是我自己试写的代码,但是与在TC环境里所得结果不一,我们上课的时候老师是教在C里实现,我是想用VB来实现,但是没有成功,目前还没有找出问题所在!
3 楼
老大徒伤悲 [专家分:29120] 发布于 2010-03-28 10:02:00
a = 0
b = 0
r = 2
Me.Circle (a, b), r
只会在左上角会出四分之一个圆,而且其半径几乎是0(1440为一英寸,你想想半径2有多大?)
4 楼
老大徒伤悲 [专家分:29120] 发布于 2010-03-28 10:02:00
奥没有看到,你自定义了窗体坐标。
5 楼
老大徒伤悲 [专家分:29120] 发布于 2010-03-28 10:17:00
Private Sub Form_Activate()
Dim a As Single, b As Single, r As Single, t As Single
Dim n As Integer, i As Integer, j As Integer
Dim x() As Single, y() As Single
a = 0
b = 0
r = 2
n = 12
t = 6.283185 / n
Me.Circle (a, b), r '这里画的是正圆,不因窗口长宽比例而改变
ReDim x(n), y(n)
For i = 1 To n
x(i) = a + r * Cos(i * t) '这里的数据虽然是正圆,但实际效果受窗体长宽比例影响
y(i) = b + r * Sin(i * t)
Next i
For i = 1 To n - 1
For j = i + 1 To n
Line (x(i), y(i))-(x(j), y(j))
Next j
Next i
End Sub
Private Sub Form_Load()
Scale (-4, 4)-(4, -4)
End Sub
6 楼
lang12 [专家分:0] 发布于 2010-03-31 22:47:00
看到你的回帖很高兴,我把你的代码复制到VB里运行了, 结果我放在我的提问里了,与我们课上要求的还有点不一样,我所说的金钢石图案其实就是在圆上取n个点,然后两两相连,最后出来的只是里面那部分!!非常感谢!!多多交流!
7 楼
lang12 [专家分:0] 发布于 2010-04-01 18:56:00
我今天又试了一下,结果已经达到预期的目的了,代码修改后如下:
Private Sub Form_Activate()
Dim a As Single, b As Single, r As Single, t As Single
Dim n As Integer, i As Integer, j As Integer
Dim x() As Single, y() As Single
a = 10000
b = 6000
r = 4000
n = 21
t = 6.283185 / n
Me.Circle (a, b), r '这里画的是正圆,不因窗口长宽比例而改变
ReDim x(n), y(n)
For i = 1 To n
x(i) = a + r * Cos(i * t) '这里的数据虽然是正圆,但实际效果受窗体长宽比例影响
y(i) = b + r * Sin(i * t)
Next i
For i = 1 To n - 1
For j = i + 1 To n
Line (x(i), y(i))-(x(j), y(j))
Next j
Next i
End Sub
Private Sub Form_Resize()
Me.WindowState = 2
End Sub
多谢你的指点哈!
我来回复