Dim BackBuffer As Image = New Bitmap(Me.ClientSize.Height, Me.ClientSize.Width) Using g As Graphics = Graphics.FromImage(BackBuffer) Dim i = 250 Dim tableau(i, i) As Integer Dim t As Double = Me.ClientSize.Height / i Dim R As New Rectangle(0, 0, t, t) For x As Integer = 1 To i For z As Integer = 0 To i Select Case tableau(x, z) Case 1 '"FeuG" g.DrawRectangle(Pens.Silver, R) 'Affichage du rectangle g.FillRectangle(Brushes.Silver, R) 'Remplissage du rectangle Case 2 '"FeuR" g.DrawRectangle(Pens.Red, R) g.FillRectangle(Brushes.Red, R) Case 3 '"Limite" g.DrawRectangle(Pens.Orange, R) g.FillRectangle(Brushes.Orange, R) Case 4 ' "Arbre" g.DrawRectangle(Pens.Green, R) g.FillRectangle(Brushes.Green, R) Case 5 '"Sol" g.DrawRectangle(Pens.Yellow, R) g.FillRectangle(Brushes.Yellow, R) Case 6 '"CoupeFeu" g.DrawRectangle(Pens.Indigo, R) g.FillRectangle(Brushes.Indigo, R) Case 7 '"Eau" g.DrawRectangle(Pens.Blue, R) g.FillRectangle(Brushes.Blue, R) Case Else g.DrawRectangle(Pens.Blue, R) g.FillRectangle(Brushes.Blue, R) End Select R.Offset(t, 0) Next R.Offset(-R.Left, t) Next End Using Me.CreateGraphics.DrawImage(BackBuffer, 0, 0)
'Affichage du carré final selon la matrice calculée Me.SuspendLayout() Dim t As Double = (Me.Height - 80) / i 'Calcul de la taille d'un côté du la figure en cases Dim ObjDessin As System.Drawing.Graphics = Me.CreateGraphics() 'Création de l'object graphique Dim ObjGraph As New System.Drawing.Rectangle(20, 20, t, t) 'Dim ObjGraph As New System.Drawing.Rectangle((z * t) + 20, (x * t) + 20, t, t) For x As Integer = 0 To i - 1 For z As Integer = 0 To i - 1 ObjGraph.Top = (z * t) + 20 ObjGraph.Left = (x * t) + 20 Select Case tableau(x, z) Case 0 ObjDessin.DrawRectangle(System.Drawing.Pens.Silver, ObjGraph) 'Affichage du rectangle ObjDessin.FillRectangle(Brushes.Silver, ObjGraph) 'Remplissage du rectangle Case 1 ObjDessin.DrawRectangle(System.Drawing.Pens.Red, ObjGraph) ObjDessin.FillRectangle(Brushes.Red, ObjGraph) Case 2 ObjDessin.DrawRectangle(System.Drawing.Pens.Orange, ObjGraph) ObjDessin.FillRectangle(Brushes.Orange, ObjGraph) Case 3 ObjDessin.DrawRectangle(System.Drawing.Pens.Green, ObjGraph) ObjDessin.FillRectangle(Brushes.Green, ObjGraph) Case 4 ObjDessin.DrawRectangle(System.Drawing.Pens.Yellow, ObjGraph) ObjDessin.FillRectangle(Brushes.Yellow, ObjGraph) Case 5 ObjDessin.DrawRectangle(System.Drawing.Pens.Indigo, ObjGraph) ObjDessin.FillRectangle(Brushes.Indigo, ObjGraph) Case 6 ObjDessin.DrawRectangle(System.Drawing.Pens.Blue, ObjGraph) ObjDessin.FillRectangle(Brushes.Blue, ObjGraph) End Select Next Next Me.ResumeLayout()
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionDim BackBuffer As Image = New Bitmap(Me.ClientSize.Height, Me.ClientSize.Width) Using g As Graphics = Graphics.FromImage(BackBuffer) Dim i = 250 Dim tableau(i, i) As Integer Dim t as double = (Me.ClientSize.height - 80) / i 'Calcul de la taille d'un côté de la figure en cases Dim R As New Rectangle(0, 20, t, t) For x As Integer = 0 To i - 1 For z As Integer = 0 To i - 1 If z = 0 Then R.Offset(t + 20, 0) Else R.Offset(t, 0) Select Case tableau(x, z) Case 0 '"FeuG" g.DrawRectangle(Pens.Silver, R) 'Affichage du rectangle g.FillRectangle(Brushes.Silver, R) 'Remplissage du rectangle Case 1 '"FeuR" g.DrawRectangle(Pens.Red, R) g.FillRectangle(Brushes.Red, R) Case 2 '"Limite" g.DrawRectangle(Pens.Orange, R) g.FillRectangle(Brushes.Orange, R) Case 3 '"Arbre" g.DrawRectangle(Pens.Green, R) g.FillRectangle(Brushes.Green, R) Case 4 '"Sol" g.DrawRectangle(Pens.Yellow, R) g.FillRectangle(Brushes.Yellow, R) Case 5 '"CoupeFeu" g.DrawRectangle(Pens.Indigo, R) g.FillRectangle(Brushes.Indigo, R) Case 6 '"Eau" g.DrawRectangle(Pens.Blue, R) g.FillRectangle(Brushes.Blue, R) Case Else g.DrawRectangle(Pens.Blue, R) g.FillRectangle(Brushes.Blue, R) End Select Me.PGB.Value += 1 Next R.Offset(-R.Left, t) Next End Using Me.CreateGraphics.DrawImage(BackBuffer, 0, 0)
Dim BackBuffer As Image = New Bitmap(Me.ClientSize.Height, Me.ClientSize.Width) Using g As Graphics = Graphics.FromImage(BackBuffer) Dim i = 250 Dim tableau(i, i) As Integer Dim t as double = (Me.ClientSize.height - 80) / i 'Calcul de la taille d'un côté de la figure en cases Dim R As New Rectangle(0, 20, t, t) Dim point As System.Drawing.Point For x As Integer = 0 To i - 1 For z As Integer = 0 To i - 1 point.X = (z * t) + 20 point.Y = (x * t) + 20 R.Location = point Select Case tableau(x, z) Case 0 '"FeuG" g.DrawRectangle(Pens.Silver, R) 'Affichage du rectangle g.FillRectangle(Brushes.Silver, R) 'Remplissage du rectangle Case 1 '"FeuR" g.DrawRectangle(Pens.Red, R) g.FillRectangle(Brushes.Red, R) Case 2 '"Limite" g.DrawRectangle(Pens.Orange, R) g.FillRectangle(Brushes.Orange, R) Case 3 '"Arbre" g.DrawRectangle(Pens.Green, R) g.FillRectangle(Brushes.Green, R) Case 4 '"Sol" g.DrawRectangle(Pens.Yellow, R) g.FillRectangle(Brushes.Yellow, R) Case 5 '"CoupeFeu" g.DrawRectangle(Pens.Indigo, R) g.FillRectangle(Brushes.Indigo, R) Case 6 '"Eau" g.DrawRectangle(Pens.Blue, R) g.FillRectangle(Brushes.Blue, R) Case Else g.DrawRectangle(Pens.Blue, R) g.FillRectangle(Brushes.Blue, R) End Select Next Next End Using Me.CreateGraphics.DrawImage(BackBuffer, 0, 0)