Differenze tra le versioni di "Ruotare un romboide in una DrawingArea"

Da Gambas-it.org - Wikipedia.
(Creata pagina con "Di seguito mostreremo un possibile codice per ruotare un Romboide disegnato in una ''DrawingArea''. E' possibile variare la dimensione del Romboide, modificando il raggio del...")
 
 
(2 versioni intermedie di uno stesso utente non sono mostrate)
Riga 5: Riga 5:
 
Il fulcro del Metodo ".Translate()" agisce da vortice, ossia da centro di rotazione intorno a una ipotetica circonferenza.  
 
Il fulcro del Metodo ".Translate()" agisce da vortice, ossia da centro di rotazione intorno a una ipotetica circonferenza.  
 
  Private DrawingArea1 As DrawingArea
 
  Private DrawingArea1 As DrawingArea
 +
Private Const ROMBOIDE As Byte = 4
 
  Private Const <FONT Color=#B22222>RAGGIO</font> As Single = 40.0
 
  Private Const <FONT Color=#B22222>RAGGIO</font> As Single = 40.0
Private Const ROMBOIDE As Byte = 4
 
 
  Private ANGOLO As Single = 0.8
 
  Private ANGOLO As Single = 0.8
 
  Private an As Single
 
  Private an As Single
Riga 13: Riga 13:
 
  Private coord As Single[]
 
  Private coord As Single[]
 
  Private pol As New Single[]
 
  Private pol As New Single[]
 +
Private c As Integer[] = [Color.Blue, Color.Green, Color.Yellow, Color.Red]
 +
Private f As Float[] = [0, 0.34, 0.67, 1]
 
   
 
   
 
   
 
   
Riga 38: Riga 40:
 
   Next
 
   Next
 
   
 
   
   xs = (coord[0] + coord[0] + pol[2] + coord[0] + Abs(pol[4]) + coord[0] - Abs(pol[6])) / ROMBOIDE
+
<FONT Color=gray>' ''Il valore 10 aggiusta in orizzontale il punto di rotazione del Romboide:''</font>
 +
   xs = (coord[0] + coord[0] + pol[2] + coord[0] + Abs(pol[4]) + coord[0] - Abs(pol[6])) / ROMBOIDE - <FONT Color=darkorange>10</font>
 
   ys = (coord[1] + coord[1] + pol[3] + coord[1] + pol[5] + coord[1] + pol[7]) / ROMBOIDE
 
   ys = (coord[1] + coord[1] + pol[3] + coord[1] + pol[5] + coord[1] + pol[7]) / ROMBOIDE
 
   
 
   
Riga 58: Riga 61:
 
     .Arc(coord[0], coord[1], 2, Rad(0), Rad(360), False)
 
     .Arc(coord[0], coord[1], 2, Rad(0), Rad(360), False)
 
     .Fill
 
     .Fill
 +
    .Brush = .LinearGradient(0, 20, 15, 0, c, f)
 
     .Translate(coord[0], coord[1])
 
     .Translate(coord[0], coord[1])
 
     .Rotate(Rad(-an))
 
     .Rotate(Rad(-an))

Versione attuale delle 12:06, 23 ott 2023

Di seguito mostreremo un possibile codice per ruotare un Romboide disegnato in una DrawingArea.

E' possibile variare la dimensione del Romboide, modificando il raggio della circonferenza, sulla quale i suoi vertici insistono. 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 ROMBOIDE As Byte = 4
Private Const RAGGIO As Single = 40.0
Private ANGOLO As Single = 0.8
Private an As Single
Private xs As Single
Private ys As Single
Private coord As Single[]
Private pol As New Single[]
Private c As Integer[] = [Color.Blue, Color.Green, Color.Yellow, Color.Red]
Private f As Float[] = [0, 0.34, 0.67, 1]


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()

 coord = [DrawingArea1.W / 2, DrawingArea1.H / 2]

 Dim gradi As Single[] = [0.0, 90.0, 180.0, 270.0]
 For t As Byte = 0 To ROMBOIDE - 1
   pol.Push(RAGGIO * Cos(Rad(gradi[t])))
   pol.Push(RAGGIO * Sin(Rad(gradi[t])))
 Next

' Il valore 10 aggiusta in orizzontale il punto di rotazione del Romboide:
 xs = (coord[0] + coord[0] + pol[2] + coord[0] + Abs(pol[4]) + coord[0] - Abs(pol[6])) / ROMBOIDE - 10
 ys = (coord[1] + coord[1] + pol[3] + coord[1] + pol[5] + coord[1] + pol[7]) / ROMBOIDE

End

Public Sub DrawingArea1_MouseUp()

 While Object.IsValid(DrawingArea1)
   an += ANGOLO
   DrawingArea1.Refresh
   Wait 0.01
 Wend

End

Public Sub DrawingArea1_Draw()

 With Paint
   .Arc(coord[0], coord[1], 2, Rad(0), Rad(360), False)
   .Fill
   .Brush = .LinearGradient(0, 20, 15, 0, c, f)
   .Translate(coord[0], coord[1])
   .Rotate(Rad(-an))
   .Polygon([(coord[0] + pol[0]) - xs, (coord[1] + pol[1]) - ys, (coord[0] + pol[2]) - xs, (coord[1] + pol[3]) - ys, (coord[0] + pol[4]) - xs - 150, (coord[1] + pol[5]) - ys, (coord[0] + pol[6]) - xs, (coord[1] + pol[7]) - ys])
   .Stroke
   .End
 End With

End