Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Drawing;
- //using System.Windows.Forms;
- namespace modelowanie
- {
- class Program
- {
- static void Main(string[] args)
- {
- int prec = 0;
- const int N = 500;
- double V = 1000;
- double[,] s = new double[N, N];
- double[,] pp = new double[N, N];
- double[,] p = new double[N, N];
- double[,] pm = new double[N, N];
- //double cmax = 1000;
- double ds = 1;
- double dtr = ds / (2 * V);
- for (int i = 0; i < N; i++)
- for (int j = 0; j < N; j++)
- {
- pp[i, j] = 0;
- p[i, j] = 0;
- pm[i, j] = 0;
- s[i, j] = 0;
- }
- int k = 0;
- double x, xx = 0;
- float fpeak = 30.0f;
- double t = 0.0;
- using (Bitmap b = new Bitmap(N, N))
- {
- using (Graphics g = Graphics.FromImage(b))
- {
- g.Clear(Color.White);
- while (true)
- {
- k++;
- t = k * dtr;
- x = Math.PI * fpeak * (t - (1.0 / fpeak));
- xx = x * x;
- s[N / 2, N / 2] = Math.Exp(-xx) * (1.0f - 2.0f * xx);
- //s[N / 2, N / 2] = t;
- //s[N / 2, N / 2] = Math.Sin(Math.PI* t );
- pp = new double[N, N];
- if (prec == 0)//2th order
- {
- for (int i = 2; i <= N - 2; i++)
- {
- for (int j = 2; j <= N - 2; j++)
- {
- //System.Console.WriteLine(p[i, j] + " : " + pm[i, j] + " : " + pp[i, j]);
- pp[i, j] = 2.0 * p[i, j] - pm[i, j] + ((dtr * dtr) / (ds * ds)) * V * V *
- (p[i + 1, j] + p[i - 1, j] + p[i, j + 1] + p[i, j - 1] - 4.0 * p[i, j]) + s[i, j];
- // b.SetPixel(j, i, Color.FromArgb(Convert.ToInt32(pp[i, j] + 3), Convert.ToInt32(pp[i, j] + 3), Convert.ToInt32(pp[i, j] + 3)));
- }
- }
- pm = p;
- p = pp;
- if (t >= 0.2) break;
- }
- }
- //System.Console.WriteLine("Koniec");
- double max = 0;
- double min = 1000;
- for (int i = 0; i < N; i++)
- for (int j = 0; j < N; j++)
- {
- // jeżeli element jest większy od dotychczasowego maksimum to on staje się maksimum
- if (pp[i, j] > max)
- max = pp[i, j];
- if (pp[i, j] < min)
- min = pp[i, j];
- }
- //System.Console.WriteLine(max + " " + min);
- for (int i = 2; i <= N - 2; i++)
- {
- for (int j = 2; j <= N - 2; j++)
- {
- int value = (int)((255 / (max - min)) * (pp[i, j] - min));
- b.SetPixel(j, i, Color.FromArgb(value, value, value));
- }
- }
- b.Save(@"D:\fala\blank.jpeg");
- }
- //System.Console.ReadLine();
- //Form form = new Form() { Width = 500, Height = 500 };
- //form.Controls.Add(new PictureBox(){Image = b,Width=500,Height=500});
- //form.Show();
- //Application.Run(form);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement