柚子快報(bào)激活碼778899分享:c# 畫一個(gè)正弦函數(shù)
柚子快報(bào)激活碼778899分享:c# 畫一個(gè)正弦函數(shù)
1.概要
c# 畫一個(gè)正弦函數(shù)
2.代碼
using System;
using System.Drawing;
using System.Windows.Forms;
public class SineWaveForm : Form
{
private const int Width = 800;
private const int Height = 600;
private const double Amplitude = 100.0;
private const double Period = 200.0;
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
Pen pen = new Pen(Color.Blue, 2);
for (double x = 0; x < Width; x += 1)
{
double y = Height / 2 - Amplitude * Math.Sin((2 * Math.PI / Period) * x);
int yInt = (int)y;
if (yInt >= 0 && yInt < Height)
{
// 繪制點(diǎn)來(lái)模擬連續(xù)的線(對(duì)于更平滑的線,使用g.DrawCurve或g.DrawBezier)
g.DrawEllipse(pen, (float)x, (float)yInt, 2, 2);
}
}
pen.Dispose();
}
public SineWaveForm()
{
this.DoubleBuffered = true; // 減少繪圖時(shí)的閃爍
this.ClientSize = new Size(Width, Height);
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new SineWaveForm());
}
}
3.運(yùn)行結(jié)果
?
柚子快報(bào)激活碼778899分享:c# 畫一個(gè)正弦函數(shù)
推薦鏈接
本文內(nèi)容根據(jù)網(wǎng)絡(luò)資料整理,出于傳遞更多信息之目的,不代表金鑰匙跨境贊同其觀點(diǎn)和立場(chǎng)。
轉(zhuǎn)載請(qǐng)注明,如有侵權(quán),聯(lián)系刪除。