Differenze tra le versioni di "Disegnare in una DrawingArea un cerchio"

Da Gambas-it.org - Wikipedia.
Riga 16: Riga 16:
 
   
 
   
 
   With DrawingArea1 = New DrawingArea(Me) As "DrawingArea1"
 
   With DrawingArea1 = New DrawingArea(Me) As "DrawingArea1"
     .X = 0
+
     .Background = Color.White
    .Y = 0
 
 
   End With
 
   End With
 
    
 
    
Riga 51: Riga 50:
 
   
 
   
 
   With DrawingArea1 = New DrawingArea(Me) As "DrawingArea1"
 
   With DrawingArea1 = New DrawingArea(Me) As "DrawingArea1"
     .X = 0
+
     .Background = Color.White
    .Y = 0
 
 
   End With
 
   End With
 
    
 
    
Riga 86: Riga 84:
 
   
 
   
 
   With DrawingArea1 = New DrawingArea(Me) As "DrawingArea1"
 
   With DrawingArea1 = New DrawingArea(Me) As "DrawingArea1"
     .X = 0
+
     .Background = Color.White
    .Y = 0
 
 
   End With
 
   End With
 
+
 
  '''End'''
 
  '''End'''
 
   
 
   

Versione delle 22:56, 3 gen 2022

Per disegnare un cerchio all'interno di una DrawingArea, è possibile utilizzare la Classe "Paint".

Uso del Metodo ".Arc()"

La Classe Paint ci consente di disegnare un cerchio mediante il Metodo ".Arc()":

Private DrawingArea1 As DrawingArea


Public Sub Form_Open()

 With Me
   .Center
   .W = 600
   .H = 500
   .Arrangement = Arrange.Fill
 End With

 With DrawingArea1 = New DrawingArea(Me) As "DrawingArea1"
   .Background = Color.White
 End With
 
End

Public Sub DrawingArea1_Draw()
 
 With Paint
   .Brush = Paint.Color(Color.Red)
   .Arc(DrawingArea1.W / 2, DrawingArea1.H / 2, 100, Rad(0), Rad(360), False)
' Se si desidera disegnare un cerchio vuoto, si userà il Metodo ".Stroke":
   .Stroke
' Se si desidera disegnare un cerchio ripieno di colore, si userà il Metodo ".Fill":
   .Fill
   .End
 End With
 
End

Uso del Metodo ".Ellipse()"

La Classe Paint ci consente di disegnare un cerchio anche mediante il Metodo ".Ellipse()":

Private DrawingArea1 As DrawingArea


Public Sub Form_Open()

 With Me
   .Center
   .W = 600
   .H = 500
   .Arrangement = Arrange.Fill
 End With

 With DrawingArea1 = New DrawingArea(Me) As "DrawingArea1"
   .Background = Color.White
 End With
 
End

Public Sub DrawingArea1_Draw()
 
 With Paint
   .Brush = Paint.Color(Color.Red)
   .Ellipse(DrawingArea1.W / 2, DrawingArea1.H / 2,  100, 100, Rad(0), Rad(360), False)
' Se si desidera disegnare un cerchio vuoto, si userà il Metodo ".Stroke":
   .Stroke
' Se si desidera disegnare un cerchio ripieno di colore, si userà il Metodo ".Fill":
   .Fill
   .End
 End With
 
End

Usare una formula trigonometrica

E' possibile anche disegnare un cerchio punto per punto mediante una formula trigonometrica ed usando il Metodo ".FillRect()" della Classe "Paint" per ottenere un punto: [Nota 1]

Private DrawingArea1 As DrawingArea


Public Sub Form_Open()

 With Me
   .Center
   .W = 600
   .H = 500
   .Arrangement = Arrange.Fill
 End With

 With DrawingArea1 = New DrawingArea(Me) As "DrawingArea1"
   .Background = Color.White
 End With

End

Public Sub DrawingArea1_Draw()
 
 Dim x, y, r, t As Single     
 x = DrawingArea1.W / 2
 y = DrawingArea1.H / 2
' Lunghezza del raggio della circonferenza:
 r = 100
 
' Il ciclo disegna l'arco della circonferenza:
 For t = 0 To 360  ' Per maggiore dettaglio si potrà aggiungere: Step 0.25
   Paint.FillRect(x + (r * Cos(Rad(t))), y + (r * Sin(Rad(t))), 1, 1, Color.Red)
 Next
  
 Paint.End
 
End


Note

[1] Vedere anche questa pagina: Visibili il punto corrente disegnato e tutti i punti precedentemente disegnati