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.运行结果

相关推荐
samble1 分钟前
从零搭建灌装监控系统(十九):单元测试实战,xUnit + 内存SQLite + 反射测试私有方法
c#·wpf·mvvm·modbus·工业控制
AI源码21 分钟前
鲜花商城(HTML 版)
前端·html
hiahiahia12328 分钟前
Message 和对话
服务器·前端·数据库
溪语流沙1 小时前
【Web全栈进阶】Composition API与组件通信:props深入、emit、插槽
前端·css·vue.js
ZoeLandia1 小时前
TypeScript 03:泛型与工具类型
前端·typescript
code_Bo1 小时前
从策划到上线:我和 AI 一起做了个微信记账小程序
前端·ai编程·cursor
Shirley~~1 小时前
Three.js加载Gltf模型并播放动画
前端·3d
Data analyse4561 小时前
Session超时与浏览器休眠的计时校验
大数据·前端·数据库·数据分析
星始流年1 小时前
AI 时代,软件程序员未来 10—15 年的职业前景
前端·后端·ai编程
猪猪拆迁队2 小时前
跨电脑复制共享-局域网直连踩坑
前端·后端·go