此帖子已被删除!! [英] THIS POST HAS BEEN DELETED!!

查看:97
本文介绍了此帖子已被删除!!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

------------没有更多可用的帖子--------

------------POST NO MORE AVAILABLE--------

推荐答案

您不应该问其他人来做功课.

Wikipedia上有一篇关于pgm的文章: http://en.wikipedia.org/wiki/Netpbm_format [
You shouldn''t ask other people to do your homework.

Wikipedia has an article on pgm: http://en.wikipedia.org/wiki/Netpbm_format[^]
Using that you should be able to output the sine curve.

Here''s an example, but don''t submit this as your homework, use it as reference only!

using System;
using System.IO;
using System.Text;

namespace PgmSine
{
    class Program
    {
        static void Main(string[] args)
        {
            int w = 500;
            int h = 250;
            int pgmValue = 255;

            int[,] pixels = new int[w, h]; 

            double halfH = (double)(h - 1) / 2.0;
            for (int x = 0; x < w; ++x)
            {
                double sinValue = Math.Sin(Math.PI * 2.0 * ((double)x / (double)w));
                int y = (int)(sinValue * halfH + halfH); 
                pixels[x, y] = pgmValue;
            }

            StringBuilder fileBuffer = new StringBuilder();
            fileBuffer.AppendLine("P2");
            fileBuffer.AppendLine("# This is a the function y=sin(x)");
            fileBuffer.AppendLine(String.Format("{0} {1}", w, h));
            fileBuffer.AppendLine(pgmValue.ToString());
            for (int y = 0; y < h; ++y)
            {
                StringBuilder buffer = new StringBuilder();
                for (int x = 0; x < w; ++x)
                {
                    buffer.AppendFormat("{0} ", pixels[x, y]);
                }
                fileBuffer.AppendLine(buffer.ToString().Trim());
            }
            File.WriteAllText(@"C:\Temp\out.pgm", fileBuffer.ToString());
        }
    }
}


这篇关于此帖子已被删除!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆