Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Charger les assemblies System.Windows.Forms et System.Drawing
- Add-Type -AssemblyName System.Windows.Forms
- Add-Type -AssemblyName System.Drawing
- # Définir le script en tant que chaîne
- $script = @"
- using System;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.Windows.Forms;
- public class SquarePatternGenerator
- {
- public static void Main()
- {
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- Form form = new Form();
- form.Text = "Générateur de Motif de Carrés";
- form.Width = 600; // Ajuster la largeur de la fenêtre
- form.Height = 800; // Ajuster la hauteur de la fenêtre
- form.StartPosition = FormStartPosition.CenterScreen;
- PictureBox pictureBox = new PictureBox();
- pictureBox.Location = new Point(20, 100);
- pictureBox.Width = form.Width - 40;
- pictureBox.Height = form.Height - 300;
- form.Controls.Add(pictureBox);
- Label label = new Label();
- label.Text = "Nombre de carrés:";
- label.Location = new Point(20, 20);
- form.Controls.Add(label);
- TextBox textBox = new TextBox();
- textBox.Location = new Point(150, 20);
- form.Controls.Add(textBox);
- Button generateButton = new Button();
- generateButton.Text = "Générer";
- generateButton.Location = new Point(20, pictureBox.Bottom + 10);
- form.Controls.Add(generateButton);
- Button saveButton = new Button();
- saveButton.Text = "Enregistrer";
- saveButton.Location = new Point(100, pictureBox.Bottom + 10);
- saveButton.Enabled = false;
- form.Controls.Add(saveButton);
- generateButton.Click += (sender, e) =>
- {
- int nombreDeCarres = int.Parse(textBox.Text);
- int largeurPagePixels = pictureBox.Width;
- int hauteurPagePixels = pictureBox.Height;
- float dpi = 1200f;
- float tailleCarreMM = 0.021f;
- float espaceEntreCarresMM = 0.021f;
- int tailleCarrePixels = (int)Math.Round(dpi * tailleCarreMM / 25.4f);
- int espaceEntreCarresPixels = (int)Math.Round(dpi * espaceEntreCarresMM / 25.4f);
- Bitmap bitmap = new Bitmap(largeurPagePixels, hauteurPagePixels);
- Graphics graphics = Graphics.FromImage(bitmap);
- SolidBrush whiteBrush = new SolidBrush(Color.White);
- SolidBrush blackBrush = new SolidBrush(Color.Black);
- graphics.FillRectangle(whiteBrush, 0, 0, largeurPagePixels, hauteurPagePixels);
- int carreCompteur = 0;
- for (int x = 0; x < largeurPagePixels; x += (tailleCarrePixels + espaceEntreCarresPixels))
- {
- for (int y = 0; y < hauteurPagePixels; y += (tailleCarrePixels + espaceEntreCarresPixels))
- {
- graphics.FillRectangle(blackBrush, x, y, tailleCarrePixels, tailleCarrePixels);
- carreCompteur++;
- if (carreCompteur >= nombreDeCarres)
- {
- break;
- }
- }
- if (carreCompteur >= nombreDeCarres)
- {
- break;
- }
- }
- pictureBox.Image = bitmap;
- saveButton.Enabled = true;
- };
- saveButton.Click += (sender, e) =>
- {
- SaveFileDialog saveFileDialog = new SaveFileDialog();
- saveFileDialog.Filter = "Images BMP|*.bmp";
- if (saveFileDialog.ShowDialog() == DialogResult.OK)
- {
- pictureBox.Image.Save(saveFileDialog.FileName, ImageFormat.Bmp);
- MessageBox.Show("Motif de carrés généré et enregistré sous " + saveFileDialog.FileName);
- }
- };
- form.Controls.Add(saveButton);
- Application.Run(form);
- }
- }
- "@
- # Exécuter le script
- Add-Type -TypeDefinition $script -ReferencedAssemblies System.Drawing, System.Windows.Forms
- # Appeler la méthode Main pour exécuter le formulaire
- [SquarePatternGenerator]::Main()
Add Comment
Please, Sign In to add comment