hur ska jag göra om jag vill rita ut 60 punktre i en ring men hjälp av en for-loop?? Ungefär såhär? En alternativ lösning. Lite optimerad:Rita med FOR-loop
Sv: Rita med FOR-loop
<code>
Private Sub Picture1_Click()
Const punkter = 60
Dim i As Integer
Dim step As Single
step = 6.28318530717959 / punkter
Picture1.ScaleMode = 3
For i = 1 To punkter
Picture1.PSet ((Cos(i * step) + 1) * Picture1.ScaleWidth \ 2, (Sin(i * step) + 1) * Picture1.ScaleHeight \ 2)
Next i
End Sub
</code>
/IvarSv: Rita med FOR-loop
<code>
Option Explicit
Private Sub Form_Load()
DrawWidth = 3
AutoRedraw = True
End Sub
Function DrawCircel(X As Single, Y As Single, Radius As Single, Punkter As Long)
Dim Step As Single
Dim Angel As Single
Dim CosValue As Single
Dim SinValue As Single
Const Pi As Single = 3.14159265358979
Step = (Pi * 2) / Punkter
For Angel = 0 To Pi / 2 Step Step
SinValue = Sin(Angel)
CosValue = Cos(Angel)
Me.PSet (X + CosValue * Radius, Y + SinValue * Radius)
Me.PSet (X + CosValue * Radius, Y - SinValue * Radius)
Me.PSet (X - CosValue * Radius, Y + SinValue * Radius)
Me.PSet (X - CosValue * Radius, Y - SinValue * Radius)
Next
End Function
Private Sub Form_Resize()
Cls
DrawCircel Me.ScaleWidth * 0.5, Me.ScaleHeight * 0.5, ScaleX(100, vbPixels), 60
End Sub
</code>