Ruotare un pentagono in una DrawingArea

Da Gambas-it.org - Wikipedia.
Versione del 28 mag 2023 alle 11:58 di Vuott (Discussione | contributi) (Creata pagina con "Di seguito mostreremo un possibile codice per ruotare un pentagono disegnato in una ''DrawingArea''. <SUP>[[[#Note|Nota 1]]]</sup> <BR>La rotazione del pentagono si...")

(diff) ← Versione meno recente | Versione attuale (diff) | Versione più recente → (diff)

Di seguito mostreremo un possibile codice per ruotare un pentagono disegnato in una DrawingArea. [Nota 1]
La rotazione del pentagono si avvia semplicemente cliccando con il tasto sinistro del mouse sulla superficie della DrawingArea.
Il fulcro del Metodo ".Translate()" agisce da vortice, ossia da centro di rotazione intorno a una ipotetica circonferenza.

Private DrawingArea1 As DrawingArea
Private Const PENTAGONO As Byte = 5
Private ANGOLO As Single = 0.8
Private mezzaDAW As Single
Private mezzaDAH As Single
Private xs As Single
Private ys As Single
Private an As Float


Public Sub Form_Open()

 With Me
   .W = Screen.AvailableWidth
   .H = Screen.AvailableHeight
   .Arrangement = Arrange.Fill
 End With
 With DrawingArea1 = New DrawingArea(Me) As "DrawingArea1"
   .Background = Color.Lighter(Color.Yellow)
 End With

End

Public Sub Form_Arrange()
 
 mezzaDAW = DrawingArea1.W / 2
 mezzaDAH = DrawingArea1.H / 2
 
 xs = (mezzaDAW + mezzaDAW + 44 + mezzaDAW + 27 + mezzaDAW - 27 + mezzaDAW - 44) / PENTAGONO
 ys = (mezzaDAH + mezzaDAH + 32 + mezzaDAH + 84 + mezzaDAH + 84 + mezzaDAH + 32) / PENTAGONO
 
End

Public Sub DrawingArea1_MouseUp()
 
 While Object.IsValid(DrawingArea1)
   an += ANGOLO
   DrawingArea1.Refresh
   Wait 0.01
 Wend
 
End

Public Sub DrawingArea1_Draw()

 With Paint
   .Translate(mezzaDAW, mezzaDAH)
   .Rotate(Rad(an))
   .Polygon([mezzaDAW - xs, mezzaDAH - ys, (mezzaDAW + 44) - xs, (mezzaDAH + 32) - ys, (mezzaDAW + 27) - xs, (mezzaDAH + 84) - ys, (mezzaDAW - 27) - xs, (mezzaDAH + 84) - ys, (mezzaDAW - 44) - xs, (mezzaDAH + 32) - ys])
   .Stroke
   .End
 End With
 
End


Note

[1] Vedere anche la seguente pagina: Ruotare un triangolo in una DrawingArea