It is currently March 29th, 2024, 12:16 am

Rotate a shape around a specific point

Get help with creating, editing & fixing problems with skins
User avatar
andersonventura
Posts: 57
Joined: December 11th, 2018, 7:38 pm
Location: Brasil

Re: Rotate a shape around a specific point

Post by andersonventura »

Yincognito wrote: September 26th, 2020, 4:43 pm No problem, it happens, we've all been there. Use whatever solution you find comfortable, and feel free to ask if you don't know anything. I have to apologize too, as I didn't include the conversion to radians in my first reply, and I should have.

I will use this thread to post an accurate representation of the solar system made in Rainmeter later on, if that's ok with you. Apart from other bits of code meant to help you with what you want, of course. ;-)
That, for sure, will be amazing!

For now, I have come to this point:

Still with some bugs .. But I am trying!

Code: Select all

[Rainmeter]
Update=1
BackgroundMode=1
SkinWidth=260
SkinHeight=260
AccurateText=1
MouseOverAction=[!Commandmeasure ActionTimer "Stop 2"][!UnpauseMeasure Loop][!Commandmeasure ActionTimer "Execute 1"]
MouseLeaveAction=[!Commandmeasure ActionTimer "Stop 1"][!Commandmeasure ActionTimer "Execute 2"][!Delay 1000][!PauseMeasure Loop]

[Variables]
CenterSize=62
OrbitDistance=80
OrbitSize=18
CenterXY=50
OrbitDistanceMin=80
OrbitDistanceMax=110

[Loop]
Measure=Loop
StartValue=0
EndValue=359
Increment=1

[ActionTimer]
DynamicVariables=1
Measure=Plugin
Plugin=ActionTimer
ActionList1=Repeat Act1,10,40
Act1=[!SetVariable OrbitDistance "(Clamp(#OrbitDistance#+1,#OrbitDistanceMin#,#OrbitDistanceMax#))"]
ActionList2=Repeat Act2,10,40
Act2=[!SetVariable OrbitDistance "(Clamp(#OrbitDistance#-1,#OrbitDistanceMin#,#OrbitDistanceMax#))"]

[Shapes]
DynamicVariables=1
Meter=Shape
Shape=Ellipse #OrbitDistance#,#OrbitDistance#,#OrbitSize# | Rotate [Loop],(#CenterXY#-#OrbitDistance#+#OrbitSize#),(#CenterXY#-#OrbitDistance#+#OrbitSize#) | Extend M1
Shape2=Ellipse #OrbitDistance#,#OrbitDistance#,#OrbitSize# | Rotate ([Loop]+45),(#CenterXY#-#OrbitDistance#+#OrbitSize#),(#CenterXY#-#OrbitDistance#+#OrbitSize#) | Extend M1
Shape3=Ellipse #OrbitDistance#,#OrbitDistance#,#OrbitSize# | Rotate ([Loop]+90),(#CenterXY#-#OrbitDistance#+#OrbitSize#),(#CenterXY#-#OrbitDistance#+#OrbitSize#) | Extend M1
Shape4=Ellipse #OrbitDistance#,#OrbitDistance#,#OrbitSize# | Rotate ([Loop]+135),(#CenterXY#-#OrbitDistance#+#OrbitSize#),(#CenterXY#-#OrbitDistance#+#OrbitSize#) | Extend M1
Shape5=Ellipse #OrbitDistance#,#OrbitDistance#,#OrbitSize# | Rotate ([Loop]+180),(#CenterXY#-#OrbitDistance#+#OrbitSize#),(#CenterXY#-#OrbitDistance#+#OrbitSize#) | Extend M1
Shape6=Ellipse #OrbitDistance#,#OrbitDistance#,#OrbitSize# | Rotate ([Loop]+225),(#CenterXY#-#OrbitDistance#+#OrbitSize#),(#CenterXY#-#OrbitDistance#+#OrbitSize#) | Extend M1
Shape7=Ellipse #OrbitDistance#,#OrbitDistance#,#OrbitSize# | Rotate ([Loop]+270),(#CenterXY#-#OrbitDistance#+#OrbitSize#),(#CenterXY#-#OrbitDistance#+#OrbitSize#) | Extend M1
Shape8=Ellipse #OrbitDistance#,#OrbitDistance#,#OrbitSize# | Rotate ([Loop]+315),(#CenterXY#-#OrbitDistance#+#OrbitSize#),(#CenterXY#-#OrbitDistance#+#OrbitSize#) | Extend M1
Shape9=Ellipse #CenterXY#,#CenterXY#,#CenterSize# | Extend M2
M1=StrokeWidth 0 | Fill Color 0,0,0,75
M2=StrokeWidth 0 | Fill Color 0,0,0,255
W=190
H=190
X=80
Y=80
User avatar
andersonventura
Posts: 57
Joined: December 11th, 2018, 7:38 pm
Location: Brasil

Re: Rotate a shape around a specific point

Post by andersonventura »

Another way to achieve the same effect!

Code: Select all

[Rainmeter]
Update=1
DynamicWindowSize=1
AccurateText=1
SkinWidth=240
SkinHeight=240
BackgroundMode=2
SolidColor=0,0,0,32
MouseOverAction=[!Commandmeasure ActionTimer "Stop 2"][!UnpauseMeasure Counter][!Commandmeasure ActionTimer "Execute 1"]
MouseLeaveAction=[!Commandmeasure ActionTimer "Stop 1"][!Commandmeasure ActionTimer "Execute 2"][!Delay 1000][!PauseMeasure Counter]


[Variables]
CenterX=100
CenterY=100
Radius=40
RadiusMin=40
RadiusMax=100

---Measures---

[Counter]
Measure=Calc
Formula=((360+[Counter]+1)%360)
DynamicVariables=1

[ActionTimer]
DynamicVariables=1
Measure=Plugin
Plugin=ActionTimer
ActionList1=Repeat Act1,10,60
Act1=[!SetVariable Radius "(Clamp(#Radius#+1,#RadiusMin#,#RadiusMax#))"]
ActionList2=Repeat Act2,10,60
Act2=[!SetVariable Radius "(Clamp(#Radius#-1,#RadiusMin#,#RadiusMax#))"]

---Meters---

[Body1]
Meter=Shape
X=(#CenterX#+#Radius#*Cos(Rad([Counter])))
Y=(#CenterY#-#Radius#*Sin(Rad([Counter])))
Shape=Ellipse 20,20,20,20 | Fill Color 128,0,0,255 | StrokeWidth 0
DynamicVariables=1

[Body2]
Meter=Shape
X=(#CenterX#+#Radius#*Cos(Rad([Counter]+45)))
Y=(#CenterY#-#Radius#*Sin(Rad([Counter]+45)))
Shape=Ellipse 20,20,20,20 | Fill Color 128,0,0,255 | StrokeWidth 0
DynamicVariables=1

[Body3]
Meter=Shape
X=(#CenterX#+#Radius#*Cos(Rad([Counter]+90)))
Y=(#CenterY#-#Radius#*Sin(Rad([Counter]+90)))
Shape=Ellipse 20,20,20,20 | Fill Color 128,0,0,255 | StrokeWidth 0
DynamicVariables=1

[Body4]
Meter=Shape
X=(#CenterX#+#Radius#*Cos(Rad([Counter]+135)))
Y=(#CenterY#-#Radius#*Sin(Rad([Counter]+135)))
Shape=Ellipse 20,20,20,20 | Fill Color 128,0,0,255 | StrokeWidth 0
DynamicVariables=1

[Body5]
Meter=Shape
X=(#CenterX#+#Radius#*Cos(Rad([Counter]+180)))
Y=(#CenterY#-#Radius#*Sin(Rad([Counter]+180)))
Shape=Ellipse 20,20,20,20 | Fill Color 128,0,0,255 | StrokeWidth 0
DynamicVariables=1

[Body6]
Meter=Shape
X=(#CenterX#+#Radius#*Cos(Rad([Counter]+225)))
Y=(#CenterY#-#Radius#*Sin(Rad([Counter]+225)))
Shape=Ellipse 20,20,20,20 | Fill Color 128,0,0,255 | StrokeWidth 0
DynamicVariables=1

[Body7]
Meter=Shape
X=(#CenterX#+#Radius#*Cos(Rad([Counter]+270)))
Y=(#CenterY#-#Radius#*Sin(Rad([Counter]+270)))
Shape=Ellipse 20,20,20,20 | Fill Color 128,0,0,255 | StrokeWidth 0
DynamicVariables=1

[Body8]
Meter=Shape
X=(#CenterX#+#Radius#*Cos(Rad([Counter]+315)))
Y=(#CenterY#-#Radius#*Sin(Rad([Counter]+315)))
Shape=Ellipse 20,20,20,20 | Fill Color 128,0,0,255 | StrokeWidth 0
DynamicVariables=1

User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Rotate a shape around a specific point

Post by balala »

andersonventura wrote: September 26th, 2020, 5:44 pm

Code: Select all

[Rainmeter]
Update=1
...
This is not valid. The lowest possible value of Update is 16 (which means 16 milliseconds).
User avatar
andersonventura
Posts: 57
Joined: December 11th, 2018, 7:38 pm
Location: Brasil

Re: Rotate a shape around a specific point

Post by andersonventura »

balala wrote: September 26th, 2020, 5:46 pm This is not valid. The lowest possible value of Update is 16 (which means 16 milliseconds).
Ty!!

I read this in the manual!
But I effectively end up feeling a difference by setting 10 seems to act faster!
User avatar
Yincognito
Rainmeter Sage
Posts: 7029
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Rotate a shape around a specific point

Post by Yincognito »

andersonventura wrote: September 26th, 2020, 5:22 pm For now, I have come to this point:

Still with some bugs .. But I am trying!
andersonventura wrote: September 26th, 2020, 5:44 pmAnother way to achieve the same effect!
Those are really nice effects. 8-) Didn't notice any bugs though, they seem to work well.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Rotate a shape around a specific point

Post by balala »

andersonventura wrote: September 26th, 2020, 5:55 pm But I effectively end up feeling a difference by setting 10 seems to act faster!
Nor 10 is a valid value. The lowest possible value is 16 (as I already said - second paragraph here):
The lowest possible effective value for Update is "16". Some care should be taken to only use very low update rates (less than 100) when really needed, and to balance a low Update with DefaultUpdateDivider, or UpdateDivider on individual measures and meters, in order to keep the CPU usage by Rainmeter as low as possible.
But finally this isn't a real problem, because if you're using a too low value, the skin uses the lowest possible Update=16.
User avatar
Yincognito
Rainmeter Sage
Posts: 7029
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Rotate a shape around a specific point

Post by Yincognito »

Yincognito wrote: September 26th, 2020, 4:43 pmI will use this thread to post an accurate representation of the solar system made in Rainmeter later on, if that's ok with you.
Here it is - it took a bit to understand all the astronomical stuff, much more to design this as I wanted to, but it works and it's accurate, as far as my understanding of astronomy goes. The skin itself will take a lot of CPU when everything is moving (not my fault, it's Rainmeter's skin redrawing process in all its glory, LOL), so some tricks can be used to alleviate or even eliminate that entirely:
- use a larger update rate (I set it to 25 ms to have some nice animation, but it can be set to update once a second, once an hour or even once a day)
- hide the ellipses representing the orbits (by middle clicking on the desired object name in the texts displayed in the top right corner of the skin)
- make your own new skin based on the Solar System (Basic).ini or Solar System (Template).ini variants (the latter uses some hardcoded values)
- left click inside the viewport (the large black rounded rectangle where bodies and orbits are displayed) to "pause" the simulation

Skin:
Solar System_1.0.0.rmskin
Preview and Accuracy Comparison (Celestia used - as you can see the positions are similar in all cases):
- Inner Planets
Inner Planetary Orbits - Rainmeter (2020-Oct-09 11-49-14 UTC).jpg
Inner Planetary Orbits - Celestia (2020-Oct-09 11-49-14 UTC).jpg
- Outer Planets
Outer Planetary Orbits - Rainmeter (2020-Oct-09 11-49-14 UTC).jpg
Outer Planetary Orbits - Celestia (2020-Oct-09 11-49-14 UTC).jpg
Most things in the skin are triggered by hovering and left or middle clicking, so play around and see what each action does. The code or the skin can obviously be improved, if desired. I wrote some helpful comments along the code to make it easier to understand how it all works, and almost everything is using "parameters" (i.e. variables) to set stuff up so tweaking those might achieve the desired effect as well. If someone has questions, feel free to ask, but do it now and not 6 months from now when the approach is getting blurrier in my head due to time passing by. :D
You do not have the required permissions to view the files attached to this post.
Last edited by Yincognito on October 9th, 2020, 4:04 pm, edited 1 time in total.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Rotate a shape around a specific point

Post by balala »

Yincognito wrote: October 9th, 2020, 12:52 pm Here it is - it took a bit to understand all the astronomical stuff, much more to design this as I wanted to, but it works and it's accurate, as far as my understanding of astronomy goes. The skin itself will take a lot of CPU when everything is moving (not my fault, it's Rainmeter's skin redrawing process in all its glory, LOL)
Very good skin, at least as so far as I tested, it looks (almost) perfectly. I love it for sure.
A few comments:
  • On a decent resolution of the screen (mine is set to 1920 x 1080 pixels) both the planets and their orbits can be hardly seen. I'd recommend to increas e a little bit the size of planets and thicken the curves representing the orbits.
  • No such large CPU usage for me. When I loaded the skin the CPU usage increased only a few percentage.
  • Probablly you should post the skin in the Share Your Creations section as well. Or at least a link to your above post.
Congratulations once again. Good job. :thumbup: :great:
User avatar
Yincognito
Rainmeter Sage
Posts: 7029
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Rotate a shape around a specific point

Post by Yincognito »

balala wrote: October 9th, 2020, 1:55 pm Very good skin, at least as so far as I tested, it looks (almost) perfectly. I love it for sure.
A few comments:
  • On a decent resolution of the screen (mine is set to 1920 x 1080 pixels) both the planets and their orbits can be hardly seen. I'd recommend to increas e a little bit the size of planets and thicken the curves representing the orbits.
  • No such large CPU usage for me. When I loaded the skin the CPU usage increased only a few percentage.
  • Probablly you should post the skin in the Share Your Creations section as well. Or at least a link to your above post.
Congratulations once again. Good job. :thumbup: :great:
Thanks for the appreciation. :rosegift: However:

- it's normal for the planets to not be easily seen, since the cosmic scale distances and radiuses are simply put ... HUGE. That being said, both the size of the planets and the thickness of the orbits can easily be adjusted. The former by modifying the Radius factor's Amount value for the desired Object by scrolling over that amount in the texts from the top right corner of the skin, and the latter by setting up the WidthStroke variable in the [Variables] section to a larger value than the currently used 1. In other words, while the latter has to be done manually, the former is easily tweakable on an individual basis for every celestial body by scrolling over the top right corner texts. Now obviously you won't notice those changes if you don't "zoom in" a bit first, but I assure you they do happen.
- yes, the large CPU usage will probably decrease if Hardware Acceleration in Rainmeter works for the user's computer and it is used, and as far as I know, you do use it
- yes, thought about posting it in the Share Your Creations section, but this is meant to be more of a sample of "this is how you do it, feel free to work your own based on this approach", rather than a fully fledged skin that I'd have to "maintain", hence me posting it here. I will post it in that section as well though, if other folks are interested and think that I should do it.

A little explanation about the top right corner texts, which are a sort of a "control panel" for the skin:

- 'Object' allows the user to select an individual body for which the other 3 fields below can be tweaked; the values of object can be anything from the 'Solar System' to any planet, incuding the 'Sun'.
- 'Factor' is one of 'Zoom', 'Radius', 'Distance' and 'Time' for the currently selected 'Object' above, meaning the user can freely modify any object's radius, distance to the Sun or time based orbital speed. The real values of those fields is internally multiplied with the corresponding value of that factor (and also by the value of the zoom factor) to achieve the final result, e.g. if you select the 'Mars' object, the 'Radius' factor and set the 'Amount' below to 2, the planet Mars will be 2 times bigger than it actually is, basically achieving an individual magnification of the selected object. Naturally, if the same factor's 'Amount' (aka value) for all the objects is changed, then the change will be applied on a global basis. Some factors are global (like 'Zoom'), meaning that only the Solar System's zoom can be changed and no individual zoom is available, others are individual (like 'Radius', 'Distance' or 'Time') meaning they can be changed for any desired object besides the system itself. Instances that cannot be modified for a certain object are displayed as having the -1 value.
- 'Amount' is the value of the currently selected 'Factor' for the currently selected 'Object', e.g. if the 'Earth' object is selected, the 'Distance' factor is selected and the 'Amount' is 0.1 then this means the distance between Earth and the Sun is 0.1 aka 1/10 of what it actually is, obviously considering the current value of 'Zoom' as well.
- 'Change' is the value by which the currently selected 'Amount' is modified with when scrolling over that 'Amount'. For example, if the 'Sun' object is selected, the 'Radius' factor is selected, the current 'Amount' is 1 and the current 'Change' is 0.01, then scrolling up over the 'Amount' line will set the 'Amount' (i.e. the radius factor for the Sun) to 1+0.01=1.01, while scrolling down over it will set it to 1-0.01=0.99, in effect changing the desired factor for an object by a chosen decrement or increment value.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Rotate a shape around a specific point

Post by balala »

Yincognito wrote: October 9th, 2020, 4:03 pm it's normal for the planets to not be easily seen, since the cosmic scale distances and radiuses are simply put ... HUGE.
No, it's not normal at all in my opinion. The parameters should have such values for the planets to them be easily seen. There is no need (and in fact it's even impossible) to have the planets scaled. They have to be much larger than "normal" to can be seen and this would be required in order to have a usable skin - sorry, but this is my opinion.
Yincognito wrote: October 9th, 2020, 4:03 pm - yes, the large CPU usage will probably decrease if Hardware Acceleration in Rainmeter works for the user's computer and it is used, and as far as I know, you do use it
Yep, I do use it. But when I disabled it (just for a try) the planets have disapeared, so for me I only can see them if I have HA on.
Yincognito wrote: October 9th, 2020, 4:03 pm - 'Object' allows the user to select an individual body for which the other 3 fields below can be tweaked; the values of object can be anything from the 'Solar System' to any planet, incuding the 'Sun'.
- 'Factor' is one of 'Zoom', 'Radius', 'Distance' and 'Time' for the currently selected 'Object' above, meaning the user can freely modify any object's radius, distance to the Sun or time based orbital speed. The real values of those fields is internally multiplied with the corresponding value of that factor (and also by the value of the zoom factor) to achieve the final result, e.g. if you select the 'Mars' object, the 'Radius' factor and set the 'Amount' below to 2, the planet Mars will be 2 times bigger than it actually is, basically achieving an individual magnification of the selected object. Naturally, if the same factor's 'Amount' (aka value) for all the objects is changed, then the change will be applied on a global basis. Some factors are global (like 'Zoom'), meaning that only the Solar System's zoom can be changed and no individual zoom is available, others are individual (like 'Radius', 'Distance' or 'Time') meaning they can be changed for any desired object besides the system itself. Instances that cannot be modified for a certain object are displayed as having the -1 value.
- 'Amount' is the value of the currently selected 'Factor' for the currently selected 'Object', e.g. if the 'Earth' object is selected, the 'Distance' factor is selected and the 'Amount' is 0.1 then this means the distance between Earth and the Sun is 0.1 aka 1/10 of what it actually is, obviously considering the current value of 'Zoom' as well.
- 'Change' is the value by which the currently selected 'Amount' is modified with when scrolling over that 'Amount'. For example, if the 'Sun' object is selected, the 'Radius' factor is selected, the current 'Amount' is 1 and the current 'Change' is 0.01, then scrolling up over the 'Amount' line will set the 'Amount' (i.e. the radius factor for the Sun) to 1+0.01=1.01, while scrolling down over it will set it to 1-0.01=0.99, in effect changing the desired factor for an object by a chosen decrement or increment value.
Unfortunately I don't get a good result: I tried modifying the Radius of a planet (for instance Earth's) and for this I modified first the Amount for Earth's Radius to 1. Then I scrolled the Radius up to 10, or even higher, but the Earth is still not properly visible. Am I missing something?