PDA

View Full Version : Vẽ đồ thị trong VB



ducquyen1102
27-08-2009, 21:32
Mình đang muốn viết một đoạn chương trình vẽ đồ thị hàm số trong VB. Cụ thể đó là: Vẽ đồ thị của hàm bậc 3 trong một khoảng xác định.
Nếu có bạn nào biết thì giúp mình nha
thank

Quiet_Sea
09-09-2009, 14:21
VB hỗ trợ khá nhiều hàm phục vụ cho đồ họa ví dụ: Vẽ đừng thẳng, điểm, vòng tròn. Dừi đây là một số minh họa:
' Draw a line from Location(50,50) to Location(3000,3000) using default colour
Line (50, 50)-(3000, 3000)
'Draw a line from Location(3400,3600) to Location (4200,3100) in Green
Line Step(400, 600)-Step(800, -500), vbGreen
' Draw a line from Location(50,100) to Location(3000,3200) in Magenta
Line (50, 100)-(3000, 3200), vbMagenta
Private Sub CmdCircleLine_Click()
' Draw a circle centered at 2000,1500 with radius equal 800
Circle (2000, 1500), 800
' Draw a vertical line from center
Line (2000, 1500)-Step(0, 800)
' Draw a horizontal line from center
Line (2000, 1500)-Step(800, 0)
Private Sub CmdEllipse_Click()
Circle (1400, 3000), 800, vbMagenta, , , 2
Circle (1400, 3000), 800, vbBlue, , , 0.5
End Sub

Private Sub CmdPie_Click()
FillStyle = 0 ' Fill inside any closed shaped
FillColor = vbYellow
' Draw a Pie Slice from 90deg to 45deg in Yellow

Circle (3000, 4000), 800, , -Rads(90), -Rads(45)

' Position the graphic cursor to Print some text
CurrentX = 2800: CurrentY = 4400
Print "87.5%"
FillColor = vbBlue
' Draw a Pie Slice from 45deg to 90deg in Blue
Circle (3050, 3900), 800, , -Rads(45), -Rads(90)
' Position the graphic cursor to Print some text
CurrentX = 3400: CurrentY = 3000
Print "12.5%"
FillStyle = 1 ' No fill
End Sub
----------
Còn chuyện vẽ như thế nào thì tùy vào bài toán cụ thể mà ta viết code cho phù hợp.
Chúc bạn thành công.