c# 绘制正玄函数 控制台绘制

1.概要

2.代码

复制代码
using System;

class Program
{
    static void Main()
    {
        const int width = 80; // 控制台宽度  
        const int height = 20; // 正弦波的高度范围  
        const double period = 10.0; // 正弦波的周期  
        const double amplitude = 5.0; // 正弦波的振幅  

        for (int x = 0; x < width; x++)
        {
            double y = amplitude * Math.Sin((2 * Math.PI / period) * x) + height / 2; // 计算y值并调整位置  
            int yPos = (int)y; // 转换为整数位置  
            if (yPos >= 0 && yPos < height) // 确保在可见范围内  
            {
                Console.SetCursorPosition(x, height - yPos - 1); // 设置光标位置  
                Console.Write("*"); // 绘制字符  
            }
        }

        Console.ReadLine(); // 等待用户输入  
    }
}

3.运行结果

相关推荐
王同学 学出来13 小时前
React案例实操(二)
前端·react.js·前端框架
向前V14 小时前
Flutter for OpenHarmony 二维码扫描App实战 - 关于实现
开发语言·javascript·flutter
weixin_4277716114 小时前
Vite 与 Webpack 模块解析差异
前端·webpack·node.js
永远是我的最爱14 小时前
基于ASP.NET的图书管理系统的设计与实现
前端·后端·sql·visual studio
广州华水科技14 小时前
单北斗GNSS技术在变形监测中的应用及其位移监测优势解析
前端
刘晓倩14 小时前
Python内置函数-hasattr()
前端·javascript·python
爱上妖精的尾巴14 小时前
7-10 WPS JS宏 对象使用实例7--拆分单表到多工作簿下的多表
javascript·restful·wps·jsa
C_心欲无痕14 小时前
不点击鼠标也能通过MouseEvent实现点击事件
前端·javascript
鲨莎分不晴15 小时前
【实战】老项目焕发新生:从 Webpack 平滑迁移到 Vite 避坑全记录
前端·webpack·node.js
hoiii18715 小时前
C# 俄罗斯方块游戏
开发语言·游戏·c#