public PerlinTestWindow()
 {
     InitializeComponent();
     WriteableBitmap wb = new WriteableBitmap(256, 256, 96.0, 96.0, PixelFormats.Gray8, null);
     PerlinNoise noise = new PerlinNoise(99);
     wb.WritePixels(new Int32Rect(0, 0, 256, 256), noise.GetPixels(256, 256), 256, 0);
     MainImage.Source = wb;
 }
Esempio n. 2
0
        private void GenerateMenuItem_Click(object sender, RoutedEventArgs e)
        {
            if (m_random == null)
            {
                m_random = new Random();
            }
            GenerateWindow window = new GenerateWindow(m_projectManager.CurrentCampaign);
            window.ShowDialog();
            if (!window.DialogResult == true)
            {
                return;
            }

            int value = (int)window.MainSlider.Value;
            bool success = (window.FirstComboBox.SelectedItem != null) && (window.SecondComboBox.SelectedItem != null);

            if (!success)
            {
                return;
            }

            int random = m_random.Next();
            PerlinNoise noise = new PerlinNoise(random);
            byte[] pixels = noise.GetPixels(128, 128);

            Scenario scenario = ScenariosListBox.SelectedItem as Scenario;
            double ratiox = 128.0 / scenario.CanvasSpaceWidth;
            double ratioy = 128.0 / scenario.CanvasSpaceHeight;

            for(int i = 0; i < scenario.CanvasSpaceHeight; i++)
            {
                for (int j = 0; j < scenario.CanvasSpaceWidth; j++)
                {
                    TileSlot tile = scenario.TileSlots[i * scenario.CanvasSpaceWidth + j];
                    int point = pixels[((int)(i * ratioy)) * 128 + ((int)(j * ratiox))];
                    if (point <= value)
                    {
                        tile.TileTypeKey = (window.FirstComboBox.SelectedItem as TileType).Name;
                    }
                    else
                    {
                        tile.TileTypeKey = (window.SecondComboBox.SelectedItem as TileType).Name;
                    }
                }
            }
        }