精华内容
下载资源
问答
  • Vb画圆并组合成规则图形,主要练习使用CIRCLE方法绘制图案,画出一些有规则的图案,在本实例中,规则已编写好,你只需在窗体上点击一下鼠标,图形就会绘制完成并显示,最终结果如上图所示。
  • vb画线画点画圆

    2013-05-20 09:46:41
    使用vb画线画点画圆,里面有程序代码。可供参考
  • Vb编写的画圆形的源代码,可画任意半径的圆形,直接可运行
  • 圆的画法(VB6.0代码编写) QQ223857666勾月
  • vb 切换红绿灯代码

    2013-01-21 19:51:06
    vb 语言设计对红绿灯进行切换的代码,希望对大家学习vb 有一定的帮助
  • CAD二次开发初次设计,做了一下基于VB的开发,这样就可以把程序完全独立于CAD软件。
  • 新手小白求教大家一个VB问题,看看能否实现如图所示的渐变同心圆。 ![图片说明](https://img-ask.csdn.net/upload/201703/09/1489031442_378972.jpg) 谢谢了
  • 摘要:VB源码,控件组件,控件数组,几何图形 VB使用控件数组划直线,画矩形,画圆等,VB源码实现,代码简单,有参考性,对入门者友好。
  • VB.NET 贪吃蛇 (画圆)

    千次阅读 2016-12-15 19:13:12
    VB.NET 贪吃蛇小游戏效果图如下 所有代码一共300行多一点,非常简单,下面依次介绍一下1.设计思路这个游戏(1)呢,得有个地图(2),有条蛇(3),有个蛋(4),所以一共设计了4个类,然后通过类之间的交互,在Form上的...

    VB.NET 贪吃蛇小游戏

    效果图如下
    这里写图片描述

    所有代码一共300行多一点,非常简单,下面依次介绍一下

    1.设计思路

    这个游戏(1)呢,得有个地图(2),有条蛇(3),有个蛋(4),所以一共设计了4个类,然后通过类之间的交互,在Form上的PictureBox上形成游戏效果。为什么还要弄个游戏类呢,因为这样新开一局游戏就非常简单了啊,直接new一个游戏类就可以了

    窗体设计图如下:
    这里写图片描述

    中间的是picturebox控件,起名为picshow

    2.地图类代码 Class Map

    Public Class Map
    
        Public width As Integer
        Public height As Integer
        Public cellWidth As Integer
        Public cellHeight As Integer
        Public Sub New(ByVal width As Integer, ByVal height As Integer, ByVal cellWidth As Integer, ByVal cellHeight As Integer)
            Me.width = width
            Me.height = height
            Me.cellWidth = cellWidth
            Me.cellHeight = cellHeight
        End Sub
    
    End Class
    

    地图的长宽,还有地图单位长宽,蛇每次移动一个单位的长或者宽

    3.蛇代码 Class Snake

    Public Class Snake
        Class SnakeBody
            Public x As Integer
            Public y As Integer
            Public r As Integer '半径
            Public c As Color   '颜色
            Public Sub New(ByVal x%, ByVal y%, ByVal r%, ByVal c As Color)
                Me.x = x
                Me.y = y
                Me.r = r
                Me.c = c
            End Sub
        End Class
    
        Public head As SnakeBody
        Public body() As SnakeBody
        Public bodyNum As Integer
        Public Sub New(ByVal x%, ByVal y%, ByVal r%, ByVal c As Color)
            head = New SnakeBody(x, y, r, c)
        End Sub
        Public Sub Move(ByVal Direction As Char, ByVal cellWidth As Integer, ByVal cellHeight As Integer)
            'body移动
            Dim i As Integer
            If bodyNum >= 2 Then
                For i = bodyNum - 1 To 1 Step -1
                    body(i).x = body(i - 1).x
                    body(i).y = body(i - 1).y
                Next
            End If
            If bodyNum >= 1 Then
                body(0).x = head.x
                body(0).y = head.y
            End If
    
            'head 移动
            Select Case Direction
                Case "w"c
                    head.y -= cellHeight
                Case "s"c
                    head.y += cellHeight
                Case "a"c
                    head.x -= cellWidth
                Case "d"c
                    head.x += cellWidth
            End Select
        End Sub
    
    
    End Class
    

    Snake类里面有一个Snakebody类,Snake分为一个head和不限量个body

    4蛋类,Class Egg

    Public Class Egg
    
        Public x As Integer
        Public y As Integer
        Public r As Integer '半径
        Public c As Color '颜色
        Public rand As Random
        Public Sub New()
            rand = New Random()
        End Sub
        Public Sub RandInfo(ByVal width As Integer, ByVal height As Integer)
            '将自己的坐标随机设定在地图内,随机一个半径和颜色
            r = rand.Next(5, 20)
            x = rand.Next(r, width - r)
            y = rand.Next(r, height - r)
            '随机10种颜色
            Dim cr As Integer
            cr = rand.Next(10)
            Select Case cr
                Case 0
                    c = Color.Red
                Case 1
                    c = Color.Orange
                Case 2
                    c = Color.Yellow
                Case 3
                    c = Color.Green
                Case 4
                    c = Color.Beige
                Case 5
                    c = Color.Blue
                Case 6
                    c = Color.Peru
                Case 7
                    c = Color.Pink
                Case 8
                    c = Color.SkyBlue
                Case 9
                    c = Color.Salmon
            End Select
        End Sub
    
    End Class
    

    蛋有坐标,颜色,半径等参数,还有一个RandInfo函数,当蛇吃到蛋以后会调用这个函数,重置这个蛋的参数。蛋的半径决定了吃了这个蛋会得多少分。

    5. Game类 Class Game

    一个游戏,应该包含一个地图、一条蛇、一个蛋,嗯

    还加了一个简单的保存游戏时间和分数的功能。

    通过Direction来控制方向,按w、a、s、d会改变Direction

    Public Class Game
        Public mySnake As Snake
        Public myMap As Map
        Public myEgg As Egg
        Public Score As Integer  
        Public Direction As Char = "w"c '一出来往上走
        Public lk As Integer = 10  '窗体周围留空大小
    
        Public Sub New(ByVal width As Integer, ByVal height As Integer, ByVal cellWidth As Integer, ByVal cellHeight As Integer)
            myMap = New Map(width, height, cellWidth, cellHeight)
            mySnake = New Snake(myMap.width \ 2, myMap.height \ 2, myMap.cellWidth, Color.Black)
            myEgg = New Egg()
            myEgg.RandInfo(myMap.width, myMap.height)
        End Sub
    
        Public Function JudgeDie() As Boolean
            '超出map范围返回True,没超出 检测是否撞了自己
            If mySnake.head.x - mySnake.head.r < 0 Or mySnake.head.x + mySnake.head.r > myMap.width Or
               mySnake.head.y - mySnake.head.r < 0 Or mySnake.head.y + mySnake.head.r > myMap.height Then
                Return True
            ElseIf mySnake.bodyNum > 2 Then '从body(2)开始检测是否与head撞了
                Dim i As Integer
                For i = 2 To mySnake.bodyNum - 1
                    Dim d As Single
                    d = (mySnake.head.x - mySnake.body(i).x) ^ 2 + (mySnake.head.y - mySnake.body(i).y) ^ 2
                    d = Math.Sqrt(d)
                    Dim r1, r2 As Integer
                    r1 = mySnake.head.r
                    r2 = mySnake.body(i).r
                    If (d < r1 + r2) Then 'head 与body 撞了
                        Return True
                    End If
                Next
                Return False
            Else
                Return False
            End If
        End Function
    
        Public Function JudgeScore() As Boolean '是否吃到蛋需要加分
            '检查蛇头和蛋的距离
            Dim d As Single
            d = (mySnake.head.x - myEgg.x) ^ 2 + (mySnake.head.y - myEgg.y) ^ 2
            d = Math.Sqrt(d)
            Dim r1, r2 As Integer
            r1 = mySnake.head.r
            r2 = myEgg.r
            If (d < r1 + r2) Then ' eat egg
                'inc score
                Score += myEgg.r
                'inc snakebody
                Dim x, y As Integer
                Select Case Direction
                    Case "w"
                        x = mySnake.head.x
                        y = mySnake.head.y - myEgg.r
                    Case "s"
                        x = mySnake.head.x
                        y = mySnake.head.y + myEgg.r
                    Case "a"
                        x = mySnake.head.x + myEgg.r
                        y = mySnake.head.y
                    Case "d"
                        x = mySnake.head.x - myEgg.r
                        y = mySnake.head.y
                End Select
                ReDim Preserve mySnake.body(mySnake.bodyNum + 1)
                mySnake.body(mySnake.bodyNum) = New Snake.SnakeBody(x, y, mySnake.head.r, myEgg.c)
                mySnake.bodyNum += 1
                'randinfo egg
                myGame.myEgg.RandInfo(myMap.width, myMap.height)
    
                Return True
            End If
            Return False
        End Function
    
        Public Sub WriteToFile()
            Dim path As String = Application.StartupPath & "\record.txt"
            If (Not IO.File.Exists(path)) Then
                Dim sw As IO.StreamWriter = IO.File.CreateText(path)
                Using (sw)
                    sw.WriteLine(Now() & " " & "Score= " & Score)
                End Using
                MessageBox.Show("创建记录文件")
                Exit Sub
            End If
            Dim sw1 = IO.File.AppendText(path)
            Using (sw1)
                sw1.WriteLine(Now() & " " & "Score= " & Score)
            End Using
        End Sub
    
        Public Sub ReadFile()
            Dim path As String = Application.StartupPath & "\record.txt"
            If (Not IO.File.Exists(path)) Then
                MessageBox.Show("记录文件不存在")
                Exit Sub
            End If
            Dim txt As String = IO.File.ReadAllText(path)
            MessageBox.Show(txt)
        End Sub
    End Class
    

    6.模块和窗体代码

    模块代码,给一个Game类就可以了

    Module Module1
        Public myGame As Game
    End Module
    

    窗体代码

    Option Explicit On
    
    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            myGame = New Game(500, 500, 10, 10)
            PicShow.Width = myGame.myMap.width + 1
            PicShow.Height = myGame.myMap.height + 1 '为什么都+1,把+1去掉后运行一下看看就知道了
            PicShow.Left = myGame.lk
            PicShow.Top = 3 * myGame.lk
            Me.Width = PicShow.Width + 4 * myGame.lk
            Me.Height = PicShow.Height + 8 * myGame.lk
            Timer1.Enabled = False
        End Sub
        Private Sub PicShow_Paint(sender As Object, e As PaintEventArgs) Handles PicShow.Paint
    
            'Paint the grid
            Dim x, y, i As Integer
            Dim sw, sh, w, h As Integer
            sw = myGame.myMap.cellWidth
            sh = myGame.myMap.cellHeight
            w = myGame.myMap.width
            h = myGame.myMap.height
            x = w \ sw
            y = h \ sh
            Dim mygraphics As Graphics
            mygraphics = e.Graphics
            For i = 0 To x Step x 
                mygraphics.DrawLine(Pens.Black, i * sw, 0, i * sw, h)
            Next
            For i = 0 To y Step y
                mygraphics.DrawLine(Pens.Black, 0, i * sh, w, i * sh)
            Next
    
            'paint the snake head
            Dim mybrush As New SolidBrush(myGame.mySnake.head.c)
            Dim r As Integer
            x = myGame.mySnake.head.x
            y = myGame.mySnake.head.y
            r = myGame.mySnake.head.r
            Dim rect As Rectangle = New Rectangle(x - r, y - r, 2 * r, 2 * r)
            myGraphics.DrawEllipse(Pens.Black, rect)
            myGraphics.FillEllipse(mybrush, rect)
            mybrush = Nothing
            'paint the snake body
            If (myGame.mySnake.bodyNum > 0) Then
                For i = 0 To myGame.mySnake.bodyNum - 1
                    x = myGame.mySnake.body(i).x
                    y = myGame.mySnake.body(i).y
                    r = myGame.mySnake.body(i).r
                    Dim mybrush1 As New SolidBrush(myGame.mySnake.body(i).c)
                    Dim mypen As New Pen(myGame.mySnake.body(i).c)
                    myGraphics.DrawEllipse(mypen, x - r, y - r, 2 * r, 2 * r)
                    myGraphics.FillEllipse(mybrush1, x - r, y - r, 2 * r, 2 * r)
                Next
            End If
            'paint the egg
            x = myGame.myEgg.x
            y = myGame.myEgg.y
            r = myGame.myEgg.r
            Dim mybrush2 As New SolidBrush(myGame.myEgg.c)
            Dim mypen2 As New Pen(myGame.myEgg.c)
            myGraphics.DrawEllipse(mypen2, x - r, y - r, 2 * r, 2 * r)
            myGraphics.FillEllipse(mybrush2, x - r, y - r, 2 * r, 2 * r)
    
        End Sub
    
        Private Sub MnuStart_Click(sender As Object, e As EventArgs) Handles MnuStart.Click
            Select Case MnuStart.Text
                Case "开始游戏(Enter)"
                    myGame = New Game(500, 500, 10, 10)
                    Dim gr As Graphics
                    gr = PicShow.CreateGraphics()
                    Dim mybrush As New SolidBrush(myGame.mySnake.head.c)
                    Dim x, y, r As Integer
                    x = myGame.mySnake.head.x
                    y = myGame.mySnake.head.y
                    r = myGame.mySnake.head.r
                    Dim rect As Rectangle = New Rectangle(x - r, y - r, 2 * r, 2 * r)
                    gr.DrawEllipse(Pens.Black, rect)
                    gr.FillEllipse(mybrush, rect)
                    Timer1.Enabled = True
                    MnuStart.Text = "暂停游戏(Enter)"
                Case "暂停游戏(Enter)"
                    Timer1.Enabled = False
                    MnuStart.Text = "继续游戏(Enter)"
                Case "继续游戏(Enter)"
                    Timer1.Enabled = True
                    MnuStart.Text = "暂停游戏(Enter)"
            End Select
        End Sub
    
        Private Sub MnuQuit_Click(sender As Object, e As EventArgs) Handles MnuQuit.Click
            End
        End Sub
    
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
            Dim sw, sh As Integer
            sw = myGame.myMap.cellWidth
            sh = myGame.myMap.cellHeight
            myGame.mySnake.Move(myGame.Direction, sw, sh)
            PicShow.Refresh()
            '撞墙死亡检测
            If myGame.JudgeDie Then
                Timer1.Enabled = False
                MessageBox.Show("撞死了!您的分数为: " & myGame.Score, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
                myGame.WriteToFile()
                MnuStart.Text = "开始游戏(Enter)"
                MnuScore.Text = "分数: 0"
                Exit Sub
            End If
            '吃蛋检测
            If myGame.JudgeScore Then
                MnuScore.Text = "分数: " & myGame.Score
                Exit Sub
            End If
    
        End Sub
    
    
        Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
            Select Case e.KeyCode
                Case Keys.W
                    If (myGame.Direction = "s"c) Then Exit Sub
                    myGame.Direction = "w"c
                Case Keys.S
                    If (myGame.Direction = "w"c) Then Exit Sub
                    myGame.Direction = "s"c
                Case Keys.A
                    If (myGame.Direction = "d"c) Then Exit Sub
                    myGame.Direction = "a"c
                Case Keys.D
                    If (myGame.Direction = "a"c) Then Exit Sub
                    myGame.Direction = "d"c
                Case Keys.Enter
                    MnuStart_Click(sender, e)
            End Select
        End Sub
    
        Private Sub MnuRecord_Click(sender As Object, e As EventArgs) Handles MnuRecord.Click
            myGame.ReadFile()
        End Sub
    
        Private Sub 帮助ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 帮助ToolStripMenuItem.Click
            Dim msg As String
            msg = "游戏方法:" & vbCrLf
            msg &= "使用w,a,s,d来控制方向" & vbCrLf
            msg &= "按回车键 开始/暂停"
            MessageBox.Show(msg, "帮助")
        End Sub
    End Class
    

    结束

    刚转入VB.NET几天,这是第一个VB.NET的小游戏!还是蛮开心的0 0

    展开全文
  • 打开VB6.0程序,新建一个窗体。应用command画出一个按钮,将command的caption属性改为“开始运动”;插入一个timer,将其interval属性改为1000,enabled属性改为FALSE。用shape控件画出一个圆。 Dim g As Boolean ...

    绘制圆形并运动的程序代码

    打开VB6.0程序,新建一个窗体。应用command画出一个按钮,将command的caption属性改为“开始运动”;插入一个timer,将其interval属性改为1000,enabled属性改为FALSE。用shape控件画出一个圆。

    Dim g As Boolean

    Dim x As Long

    Private Sub Command1_Click()

    Timer1.Enabled = True

    End Sub

    Private Sub Form_Load()

    g = True

    x = Shape1.Left

    End Sub

    Private Sub Timer1_Timer()

    If g Then

    x = x - 300

    Else

    x = x + 300

    End If

    If x < 0 Or x >(Me.ScaleWidth - Shape1.Width) Then

    g = Not g

    End If

    Shape1.Move x

    End Sub

    在窗体中使用了一个按钮、一个计时器,并且用shape控件绘制了一个圆

    展开全文
  • VB使用控件数组划直线,画矩形,画圆等,基于VB6.0开发的,代码简单,有参考性,对入门者比较友好,欢迎大家参考。
  • vb.net简单画图实现,画圆,画矩形,画直线,画笔,裁剪等基本画图功能
  • VB中用多边形逼近法画圆,而且可用鼠标拖动,来自本人的计算机图形学实习作业,欢迎下载。
  • VB 控件数组画图.rar

    2019-07-10 09:37:47
    VB 控件数组画图,每次输出新图形,前面的清除,可以画直线、矩形、圆。具体的代码操作,请看如下:  Private Sub Form_Load()  Picture1.Scale (0, 0)-(10, 10) '设置坐标系  End Sub  Private Sub Command1_...
  • VB实现多边形逼近法画圆,可设置误差等
  • 同心圆

    2018-04-28 16:57:00
    import turtle turtle.circle(100) turtle.up() turtle.goto(0,50) turtle.down() turtle.circle(50) turtle.up() turtle.goto(0,-50) turtle.down() turtle.circle(150) ...turt...
    import turtle
    turtle.circle(100)
    
    turtle.up()
    turtle.goto(0,50)
    turtle.down()
    
    turtle.circle(50)
    
    
    turtle.up()
    turtle.goto(0,-50)
    turtle.down()
    
    turtle.circle(150)
    
    turtle.up()
    turtle.goto(0,-100)
    turtle.down()
    
    turtle.circle(200)
    
    turtle.down

     

    转载于:https://www.cnblogs.com/shijiediyiwen/p/8968714.html

    展开全文
  • 又一个VB.NET Draw绘图实例,可以画圆、直线、椭圆等图形,也可以直接在文字标签输出到图像上,演示了DrawLine、DrawEllipse、DrawRectangle、DrawCurve、DrawLines、DrawString、DrawsForm等。以下是简单的画圆、画...
  • VB6围棋:窗体画线和画圆的应用

    千次阅读 2015-08-30 16:11:48
    Option Explicit Dim qipan(1 To 19, 1 To 19) As Integer '棋盘数组,0:无 1:黑子 2:白子Private Sub Form_Load() Me.AutoRedraw = True End SubPrivate Sub Form_MouseUp(Button As Integer, Shift As Integer,...
    Option Explicit
    Dim qipan(1 To 19, 1 To 19) As Integer '棋盘数组,0:无 1:黑子 2:白子
    
    Private Sub Form_Load()
    Me.AutoRedraw = True
    End Sub
    
    Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
    
    Static c As Boolean '落子颜色
    Dim x0 As Integer, y0 As Integer '落子坐标
    
    x0 = Int(x + 0.5) '坐标四舍五入
    y0 = Int(y + 0.5)
    
    If x0 > 0 And x0 < 21 And y0 > 0 And y0 < 21 Then '是否在鼠标点在棋盘上?
    If qipan(x0, y0) = 0 Then '这一格是否已经有子?
    c = Not c '黑白转换
    FillStyle = 0
    If c Then '黑子还是白子
    FillColor = vbBlack
    qipan(x0, y0) = 1
    Else
    FillColor = vbWhite
    qipan(x0, y0) = 2
    End If
    Me.Circle (x0, y0), 0.25 '画棋子
    End If
    End If
    
    End Sub
    
    Private Sub Form_Resize()
    
    Dim i As Integer, j As Integer
    
    If Me.WindowState <> vbMinimized Then '不是最小化状态
    Me.Cls '清屏
    Me.Scale (0, 0)-(20, 20) '定义棋盘坐标系
    
    For i = 1 To 19
    Me.Line (i, 1)-(i, 19) '画19道竖线
    Me.Line (1, i)-(19, i) '画19道横线
    Next
    
    FillStyle = 0
    For i = 0 To 8 '画9个星位
    Me.Circle ((i Mod 3) * 6 + 4, (i \ 3) * 6 + 4), 0.1
    Next
    
    For i = 1 To 19 '重绘棋子
    For j = 1 To 19
    If qipan(i, j) = 1 Then
    FillColor = vbBlack
    Me.Circle (i, j), 0.25
    ElseIf qipan(i, j) = 2 Then
    FillColor = vbWhite
    Me.Circle (i, j), 0.25
    End If
    Next
    Next
    
    End If
    End Sub

    这里写图片描述
    窗体可随意拉伸,棋盘和棋子实时重绘。

    展开全文
  • 三角函数画圆

    千次阅读 2018-08-28 09:40:49
    public float redius;//半径 public float angle;//偏移角度 private float parts = 0; private const float pi = 3.14f; private List&lt;Vector2&gt; circleList = new List&... ...
  • vb.net二次开发AutoCAD中画圆示例

    千次阅读 2012-08-28 13:39:45
    Imports Autodesk Imports Autodesk.AutoCAD.Interop Imports Autodesk.AutoCAD.Interop.Common imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.A
  • C#基础教程-c#实例教程,适合初学者

    万次阅读 多人点赞 2016-08-22 11:13:24
     通用语言规范(Common Language Specification,CLS):.NET系统包括如下语言:C#、C++、VB、J#,他们都遵守通用语言规范。任何遵守通用语言规范的语言源程序,都可编译为相同的中间语言代码,由CLR负责执行。只要...
  • 自己学VB试着玩的,刚开始注册,赚点积分,勿怪
  • vb.net绘制图形方法

    千次阅读 2018-04-14 21:14:21
    简述VB.NET绘制图形 学习VB.NET时,你可能会遇到VB.NET绘制图形问题,这里将介绍VB.NET绘制图形问题的解决方法,在这里拿出来和大家分享一下。 1.创建Graphics对象 VB.NET绘制图形需要指定绘图表面。其中,窗体和...
  • 画圆 圆心为(350,250)半径为200 Public Class Form1 Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint Dim gr As Graphics = Me.CreateG
  • vb小程序——主要是共初学者使用的随机半径、随机颜色的同心圆!
  • 内容索引:VB源码,系统相关,时钟 新手练习的一个实例,用VB做的圆形指针时钟,自动获取系统当前时间,指针适时走动,对vb6新手应该有用吧,演示图如上所示。有朋友将其划入了图像绘制的范畴,这也是有道理的,因为要...
  • 内容索引:VB源码,图形处理,画图 VB版个性画图板附上源代码,可以学习到颜色填充(鼠标左键是前景颜色,鼠标右键是背景颜色)、区域选择、画线(鼠标左键是前景颜色,鼠标右键是背景颜色)、画圆角矩形(鼠标左键是...
  • 六、画圆功能实现 在“创建圆”按钮的Click事件下编写绘制圆的功能代码,本次绘制使用的是圆心与半径约束创建圆的方法。 软件完整代码如下所示。 Imports AutoCAD Public Class Form1 Dim AcadApp As...

空空如也

空空如也

1 2 3 4 5 ... 17
收藏数 330
精华内容 132
关键字:

vb画圆