| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 591 人关注过本帖
标题:旋转picturebox中的图像
只看楼主 加入收藏
lianyicq
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:26
帖 子:737
专家分:3488
注 册:2013-1-26
结帖率:100%
收藏
 问题点数:0 回复次数:0 
旋转picturebox中的图像
原来写打飞机游戏时想让飞机任意角度旋转,就写了这个,比较简单。因为纯以像素点为对象,速度不理想,没用上。也没再考虑,看大家是否感兴趣,可以交流。
窗体代码
程序代码:
Option Explicit

Private Sub Command1_Click()
  Dim x, y As Integer
  Dim x0, y0, x1, y1 As Integer
  Dim zoom As Single '缩小倍数
  zoom = 1
    '以图片中心为圆心旋转
  x0 = Picture1.Width / 2
  y0 = Picture1.Height / 2
  For x1 = 0 To Picture1.Width
    For y1 = 0 To Picture1.Height
      x = rotate_point(x0, y0, x1, y1, 0, rotate).x + 200
      y = rotate_point(x0, y0, x1, y1, 0, rotate).y + 200
      Form1.PSet (x / zoom, y / zoom), Picture1.Point(x1, y1)
    Next
  Next
  rotate = rotate + 10
End Sub
模块代码
程序代码:
'coordinate type
Option Explicit
Type coodinate
  x As Integer
  y As Integer
End Type

Public rotate As Single
'function return x and y
Function rotate_point(x0, y0, x1, y1 As Integer, direction As Boolean, angle As Single) As coodinate 'center point(x0,y0) end point(x1,y1) direction=0 clockwise direction=1 counterclockwise
  Dim temp, r As Single
  r = ((y1 - y0) ^ 2 + (x1 - x0) ^ 2) ^ 0.5
  If (x1 - x0) <> 0 Then temp = Atn((y1 - y0) / (x1 - x0))
  If x1 < x0 Then temp = temp + 3.14
  If x1 > x0 And y1 < y0 Then temp = temp + 6.28

  temp = temp + ((-1) ^ direction) * (3.14 * angle / 180)
  If temp > 6.28 Then temp = temp - 6.28
  If temp < 0 Then temp = temp + 6.28
  rotate_point.x = x0 + r * Cos(temp)
  rotate_point.y = y0 + r * Sin(temp)
End Function


图片附件: 游客没有浏览图片的权限,请 登录注册

搜索更多相关主题的帖子: 游戏 
2015-07-15 14:37
快速回复:旋转picturebox中的图像
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018437 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved