All pastes #898394 Raw Edit

Something

public text v1 · immutable
·published 2008-02-10 08:47 UTC
rendered paste body
  public static float[] gen_hills()
                {
                        Random PRNG = new Random();
                        float[,] map = new float[256,256];
                        int center_x=0;
                        int center_y=0;
                        int tx=0;
                        int ty=0;
                        int i=0;
                        float height;
                        int width;
                        for(tx=0; tx<256; tx++) {
                                for(ty=0; ty<256; ty++) {
                                        map[tx,ty]=((float)PRNG.NextDouble()*8)+18.0f;
                                }
                        }
                        Console.WriteLine("Rendering hills...");
                        for(i=0; i<=50; i++) {
                                Console.Write(".");
                                center_x=PRNG.Next(31,225);
                                center_y=PRNG.Next(31,225);
                                height = ((float)PRNG.NextDouble())*12.0f;
                                for(width=30; width>0; width--) {
                                        map[center_x+width,center_y+width] = map[center_x+width,center_y+width]+(((float)width)*height);
                                        map[center_x-width,center_y-width] = map[center_x-width,center_y-width]+(((float)width)*height);
                                        map[center_x+width,center_y-width] = map[center_x+width,center_y-width]+(((float)width)*height);
                                        map[center_x-width,center_y+width] = map[center_x-width,center_y+width]+(((float)width)*height);

                                }

                        }
                        Console.WriteLine("\\nSmoothing terrain...");
                        float[] retval = new float[65536];
                        for(tx=0; tx<256; tx++) {
                                for(ty=0; ty<256; ty++) {
                                        retval[tx+(ty*256)]=map[tx,ty];
                                }
                        }
                        for(i=0; i<=300; i++) {
                                retval = smooth(retval);
                        }
                        return retval;
                }