using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace drawline
{
public partial class Form1 : Form
{
private int deg = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
Thread thread = new Thread(new ThreadStart(ThreadOn));
thread.Start();
}
private void ThreadOn()
{
int before = Environment.TickCount;
int frame = 0;
int FPS = 60;
while (!IsDisposed)
{
int now = Environment.TickCount;
int progress = now - before;
int ideal = (int)(frame * (1000.0f / FPS));
if (ideal > progress) Thread.Sleep(ideal - progress);
Invalidate();
frame++;
if (progress > 1000)
{
frame = 0;
before = now;
}
}
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Point pos = funcCircle();
SolidBrush brush = new SolidBrush(Color.Black);
Pen pen = new Pen(Color.Black);
e.Graphics.FillEllipse(brush, new Rectangle(pos.X - 16, pos.Y - 16, 32, 32));
}
private Point funcCircle()
{
Point npos;
deg += 2;
deg %= 360;
int x = (int)(Math.Sin((double)deg * Math.PI/180.0) * 100) + 300;
int y = (int)(Math.Cos((double)deg * Math.PI/180.0) * 100) + 300;
npos = new Point(x, y);
return npos;
}
}
}