Hallo Frank,
probier' mal das:
Controls: Picturebox
' © 2015 by Zardoz
Private Type XFORM
eM11 As Single
eM12 As Single
eM21 As Single
eM22 As Single
eDx As Single
eDy As Single
End Type
Private Declare Function GetWorldTransform Lib "gdi32" (ByVal hdc As Long, _
lpXform As XFORM) As Long
Private Declare Function SetGraphicsMode Lib "gdi32" (ByVal hdc As Long, ByVal _
iMode As Long) As Long
Private Declare Function SetWorldTransform Lib "gdi32" (ByVal hdc As Long, _
lpXform As XFORM) As Long
Private Const GM_ADVANCED = 2
Private Const GM_COMPATIBLE = 1
Private Const Pi As Single = 3.141593
Private Sub Form_Activate()
Dim x1!, y1!, x2!, y2!, Amplitude!, Frequence%
Me.ScaleMode = vbPixels
Me.WindowState = vbMaximized
DoEvents
With Picture1
.ScaleMode = vbPixels
.Move 0, 0, 1000, 700
.BackColor = vbBlack
.AutoRedraw = True
End With
x1 = 50
y1 = 600
x2 = 700
y2 = 100
Amplitude = 220
Frequence = 3
Call DrawSinus(x1, y1, x2, y2, Frequence, Amplitude)
End Sub
Private Sub DrawSinus(ByVal x1 As Single, ByVal y1 As Single, _
ByVal x2 As Single, ByVal y2 As Single, _
ByVal Frequence As Single, ByVal Amplitude As Single)
Dim XP!, YP!, Wnk!, DX!, DY!, S!
Dim OldMatrix As XFORM
Dim NewMatrix As XFORM
DX = x2 - x1
DY = y2 - y1
Wnk = AtnExt(DX, DY)
S = Sqr(DX * DX + DY * DY)
With NewMatrix
.eM11 = Cos(Wnk)
.eM12 = Sin(Wnk)
.eM21 = -.eM12
.eM22 = .eM11
.eDx = x1
.eDy = y1
End With
With Picture1
Call GetWorldTransform(.hdc, OldMatrix)
Call SetGraphicsMode(.hdc, GM_ADVANCED)
Call SetWorldTransform(.hdc, NewMatrix)
.CurrentX = 0
.CurrentY = 0
For XP = 0 To S - 1
Wnk = XP / S * 2 * Pi * Frequence
YP = -Amplitude / 2 * Sin(Wnk)
Picture1.Line -(XP, YP), vbWhite
Next XP
Call SetWorldTransform(.hdc, OldMatrix)
Call SetGraphicsMode(.hdc, GM_COMPATIBLE)
End With
End Sub
Private Function AtnExt(ByVal DX As Single, ByVal DY As Single) As Single
' erweiterte Atn-Funktion
Dim Wnk!, ArcTan!
If DX = 0 Then
ArcTan = 0
Else
ArcTan = Atn(Abs(DY / DX))
End If
If DX = 0 Then
If DY = 0 Then
Wnk = 0
ElseIf DY > 0 Then
Wnk = Pi / 2
Else
Wnk = 3 * Pi / 2
End If
ElseIf DX > 0 Then
If DY < 0 Then
Wnk = 2 * Pi - ArcTan
Else
Wnk = ArcTan
End If
Else
If DY < 0 Then
Wnk = ArcTan + Pi
Else
Wnk = Pi - ArcTan
End If
End If
AtnExt = Wnk
End Function Gruss,
Zardoz |