I'll post the changes I've made. I haven't taken into account the performance of the program. Most surely it can be optimized quite a lot. Seeing your programming experience, I'm sure you're capable of it
1) Two important constants:
VB Code:
Public Const PI = 3.1415927
Public Const HALFPI = 1.5707963
2) I've extended your Star UDT:
VB Code:
Public Type Star
Phase As Double
Colour As wRGB
DestX As Long
DestY As Long
Speed As Double
LumCap As Long
x As Long
y As Long
[b] dist As Long
ang As Double[/b]
End Type
Dist and ang will hold the distance and angle of the star, as seen from the center of the picture box (polar coordinates). These will be derived from x and y.
3) Code modifications to make the starfield actually rotate
Dist is derived by simply applying Pythagoras.
Ang is derived by a modified Atn function (named Arctan2) (see modification 4)
X and Y are calculated accordingly.
Tip: to reverse the spinning you need to swap either the result of the Cosine or the Sine, not both.
4) The modified Atn function:
VB Code:
Public Function Arctan2(y As Double, x As Double) As Double
If x = 0 Then
If y > 0 Then
Arctan2 = HALFPI
Else
Arctan2 = -HALFPI
End If
ElseIf x > 0 Then
Arctan2 = Atn(y / x)
Else
If y < 0 Then
Arctan2 = Atn(y / x) - PI
Else
Arctan2 = Atn(y / x) + PI
End If
End If
End Function
The advantage of this way is that, if you pass x and y separately (instead of y/x), you'll get the angle in the right quadrant of your coordinate system (instead of only the first or fourth quadrant).
I've forgotten to mention a (literally!) side effect.
Since the starfield is rotating now, there will be some black spaces, depending on the rotation angle. If the angle is 45 degrees (or 135, 225, 315), there are four opposite black triangles in the corners. At angles of 90 and 270 degrees, there are two black sidebars. You'll need to remember the position of those stars as well. (A star might be able to rotate out and into the screen.)
The distance which you'll need to remember is sqr(2) * (longest side of your screen). In this case no black shapes will show at even square screens.
Works like a charm. However, I can get the top and left destinations to work, but not the bottom and right. I'll figure it out, it only happens when I use the Sqr(2) thing.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
(Just a heads-up)
You were scaling the starfield itself, not repositioning every individual star.
Because the position of all stars were modified the same way (by Cos(Angle * (3.1415926 / 180) or Sin(...)) the modification was the same for all stars.
This resulted in the rescaling and swapping of the entire starfield.