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

相关推荐
薄荷撞~可乐几秒前
C#拆箱/装箱(性能优化)
性能优化·c#
IT_陈寒8 分钟前
Redis性能翻倍的7个冷门技巧:从P5到P8都在偷偷用的优化策略!
前端·人工智能·后端
Moonbit20 分钟前
MoonBit Meetup 丨 手把手带你走进 AI 编程新世代
前端·后端·程序员
携欢21 分钟前
PortSwigger靶场之 CSRF where token is not tied to user session通关秘籍
前端·csrf
胖咕噜的稞达鸭29 分钟前
C++中的父继子承(2)多继承菱形继承问题,多继承指针偏移,继承组合分析+高质量习题扫尾继承多态
c语言·开发语言·数据结构·c++·算法·链表·c#
执剑、天涯35 分钟前
通过一个typescript的小游戏,使用单元测试实战(二)
javascript·typescript·单元测试
HHHHHY1 小时前
使用阿里lowcode,手搓一个Carousel 走马灯容器组件
前端·react.js
用户352120195601 小时前
React-router v7
前端
Mintopia1 小时前
⚡ AI 时代,全栈 Next.js 开发的激情在哪里?
前端·aigc·全栈
Hello123网站1 小时前
300多个Html5小游戏列表和下载地址
前端·html·html5