import java.awt.Color
import java.awt.Graphics
import javax.swing.JFrame
public class OneAnt extends JFrame {
public void paint(Graphics g) {
int x = 100
int y = 80
int r = 50
g.setColor(Color.blue)
// 从x,y位置处画一个实心的圆
g.fillOval(x, y, 2 * r, 2 * r)
}
public static void main(String[] args)
{
OneAnt oa=new OneAnt()
oa.setSize(500, 300)
oa.setVisible(true)
}
}
动态圆可以用线程来实现
看看符合要求不?Option Explicit
Dim x, y As Integer '匀速旋转小球的位置
Dim A As Integer '角度
Private Sub Form_Load()
Show
Me.Picture1.Width = 2000
Me.Picture1.Height = 2000
Me.Picture1.Scale (-1000, -1000)-(1000, 1000)
A = 0
Me.Timer1.Interval = 100
End Sub
Private Sub Timer1_Timer()
Me.Picture1.Cls
Me.Picture1.Circle (0, 0), 500
Me.Picture1.PSet (0, 0)
A = A + 1
If A = 360 Then A = 0
x = 500 * Sin(A)
y = 500 * Cos(A)
Me.Picture1.Circle (x, y), 20, vbRed
End Sub
在WM_TIMER消息里{
圆周运动直接算坐标吧:用cos(x) sin(x)函数,x是弧度,不是角度.所以你得
2PI * iAngle /360把角度转成弧度
公式为:
x = y * sin( 2 * PI * iAngle / 360 )
y = y * cos( 2 * PI * iAngle /360 )
//比如iAngle==30度,那么Point(x,y)就在钟面时钟1点的位置
颜色改变的话,你直接hBrush = createSolidBrush(RGB(x,y,x) )这些数字你随便递增好了.然后就用Rectangle(rect.left, top, right ,bottom )画圆
}
注意的地方就是你的设置下SetROP2( hdc,R2_XNOR),把前一个小球重画一遍,这样它就消失了,不然你会看到无数个小球沿着圆周画下来.
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)