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

相关推荐
Vincent_czr18 分钟前
iOS中常常遇到后端返回JSON出现null值问题
前端
问心无愧051320 分钟前
ctf show web入门90
前端·笔记
yingyima21 分钟前
午夜惊魂:用 Shell 脚本和 Hey Cron 解决服务器定时报警
前端
青山Coding21 分钟前
Cesium应用(五):通视分析,解锁三维场景的”无遮挡“视野
前端·cesium
JavaAgent架构师28 分钟前
前端AI工程化(三):异步编程与并发控制
前端·人工智能
独泪了无痕39 分钟前
利用vue-pdf-embed实现PDF文件的预览
前端·vue.js
Highcharts.js43 分钟前
无需搭建数据管道,如何快速上线投资基金筛选器?
开发语言·javascript·react.js·前端框架·highcharts
Exploring43 分钟前
Hola 计算器 v1.0.1 发布:个税计算全面升级,劳务报酬也能算清楚了!
前端
Pan Zonghui1 小时前
个人开源技术博客前端
前端·开源