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

相关推荐
夜焱辰6 小时前
浏览器端 Agent 的文件版本管理:不用 Git,基于 OPFS + SQLite 自己造了一个
前端·人工智能
梦想的颜色6 小时前
TypeScript 完全指南(下):从类型体操到生产级配置
前端·javascript·typescript
Hi~晴天大圣8 小时前
npm使用介绍
前端·npm·node.js
888CC++8 小时前
如何在 C 语言中进行程序调试?
前端·javascript·算法
喵个咪9 小时前
基于 Taro 的 Headless CMS 多端前端架构:技术解析与二次开发导引
前端·react.js·taro
狂炫冰美式9 小时前
你还在古法PPT吗,试试HTML呢?免费编辑导出工具给 xdm 放这了
前端·后端·github
rockey6279 小时前
AScript之事件处理脚本
c#·.net·script·动态脚本
万少9 小时前
未来组织的分水岭不是员工数量,而是人才密度
前端·后端·面试
任磊abc9 小时前
nextjs16配置eslint+prettier
前端·eslint·nextjs·prettier
x***r15110 小时前
Another-Redis-Desktop-Manager.1.3.7安装步骤详解(附Redis可视化连接与Key管理教程)
前端·bootstrap·html