It is currently March 29th, 2024, 6:19 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

Rotate a shape around a specific point

Post by andersonventura »

Hello!
I would like to know how to reproduce this rotation using shapes. Just like in this image!

I believe that using a counter from 0 to 360 is already a clue!

Thanks in advance for your help!

Code: Select all

[Counter]
Measure=Calc
Formula=(Counter % 360) + 1
UpdateDivider=1
inner_rest.gif
You do not have the required permissions to view the files attached to this post.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5384
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Rotate a shape around a specific point

Post by eclectic-tech »

JSMorley offered an example that may help get you started.
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:58 am Hello!
I would like to know how to reproduce this rotation using shapes. Just like in this image!

I believe that using a counter from 0 to 360 is already a clue!

Thanks in advance for your help!

Code: Select all

[Counter]
Measure=Calc
Formula=(Counter % 360) + 1
UpdateDivider=1
inner_rest.gif
If you don't need the shape to also rotate around its center (i.e. you only need the revolution of the body), you can do this quite easily using a counter in the 0..2*PI interval and set the X and Y of the meter based on the sin() and cos() of the counter, with a desired radius, i.e.:

X=(#CenterX#+#Radius#*Cos([Counter]) and
Y=(#CenterY#-#Radius#*Sin([Counter])

If you need both rotation and revolution of the body, eclectic-tech's link is one way of doing it, besides using images instead of shapes in Rotator meters.

If you need to cancel or alleviate the drawbacks of having to do this using TransformationMatrix approaches (like mouse actions over the rotating meter, or its size and position) of the 2nd variant, further refining of the method would be needed.

In this specific case, I think the 1st variant would do just fine.
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 »

Beside eclectic-tech's and Yincognito's solution (which for sure are fine), as usually there are more possibilities, here is another. This uses a TransformationMatrix option. Although probably more users here don't agree with me, but this is a good solution as well and can be used.
For instance:

Code: Select all

[Rainmeter]
Update=50
SkinWidth=(2*#Radius#+10)
SkinHeight=(2*#Radius#+10)

[Variables]
Radius=150

[Counter]
Measure=Calc
Formula=(COUNTER % 360) + 10
UpdateDivider=1

[MeterSun]
Meter=Shape
X=#Radius#
Y=#Radius#
Shape=Ellipse 0,0,15 | Extend MyModifiers1
MyModifiers1=Fill Color 255,240,0 | StrokeWidth 2 | Stroke Color 220,220,220

[MeterEarth]
Meter=Shape
X=#Radius#
Y=#Radius#
Shape=Ellipse 0,0,(#Radius#-10) | Extend MyModifiers2
Shape2=Ellipse 0,(10-#Radius#),10 | Extend MyModifiers1
MyModifiers1=Fill Color 0,0,255 | StrokeWidth 2 | Stroke Color 220,220,220
MyModifiers2=Fill Color 0,0,0,0 | StrokeWidth 2 | Stroke Color 220,200,200
TransformationMatrix=(Cos(Rad([Counter])));(-Sin(Rad([Counter])));(Sin(Rad([Counter])));(Cos(Rad([Counter])));([#CURRENTSECTION#:X]-[#CURRENTSECTION#:X]*Cos(Rad([Counter]))-[#CURRENTSECTION#:Y]*Sin(Rad([Counter])));([#CURRENTSECTION#:Y]+[#CURRENTSECTION#:X]*Sin(Rad([Counter]))-[#CURRENTSECTION#:Y]*Cos(Rad([Counter])))
DynamicVariables=1
You can adjust the radius of the orbit of Earth (through the Radius variable).
This solution for sure has to be refined a little bit. If you're interested, please let me know for further improvements.
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, 9:41 am If you don't need the shape to also rotate around its center (i.e. you only need the revolution of the body), you can do this quite easily using a counter in the 0..2*PI interval and set the X and Y of the meter based on the sin() and cos() of the counter, with a desired radius, i.e.:

X=(#CenterX#+#Radius#*Cos([Counter]) and
Y=(#CenterY#-#Radius#*Sin([Counter])

If you need both rotation and revolution of the body, eclectic-tech's link is one way of doing it, besides using images instead of shapes in Rotator meters.

If you need to cancel or alleviate the drawbacks of having to do this using TransformationMatrix approaches (like mouse actions over the rotating meter, or its size and position) of the 2nd variant, further refining of the method would be needed.

In this specific case, I think the 1st variant would do just fine.
with this code I get the message:

Formula:Syntax error: (#CenterX#+#Radius#*Cos([Counter]))
Formula:Syntax error: (#CenterY#-#Radius#*Sin([Counter]))

I wil try now the other options. Thanks for now, guys!!!!
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 »

eclectic-tech wrote: September 26th, 2020, 6:24 am JSMorley offered an example that may help get you started.
I believe this is a good option to achieve what I am looking for.

One observation is that using Loop instead of Counter, I get less CPU processing.


The next step would be to be able to place 4 or 5 "planets" orbiting the "sun", all in the same orbit but at different points.
Ex:
Gray_circles_rotate.gif
You do not have the required permissions to view the files attached to this post.
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 »

andersonventura wrote: September 26th, 2020, 3:32 pm I believe this is a good option to achieve what I am looking for.

One observation is that using Loop instead of Counter, I get less CPU processing.


The next step would be to be able to place 4 or 5 "planets" orbiting the "sun", all in the same orbit but at different points.
Ex:
Gray_circles_rotate.gif

Got it!

Code: Select all

[Rainmeter]
Update=1
BackgroundMode=2
SkinWidth=600
SkinHeight=600
AccurateText=1
;MouseOverAction=[!UnpauseMeasure Counter]
;MouseLeaveAction=[!PauseMeasure Counter]


[Variables]

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

[Shapes]
DynamicVariables=1
Meter=Shape
Shape=Ellipse 50,50,50,50 | StrokeWidth 0 | Fill Color 0,0,0,30
Shape2=Ellipse 110,110,15,15 | StrokeWidth 0 | Fill Color 0,0,0,255 | Rotate [Loop],-45,-45
Shape3=Ellipse 110,110,15,15 | StrokeWidth 0 | Fill Color 0,0,0,255 | Rotate ([Loop]+45),-45,-45
Shape4=Ellipse 110,110,15,15 | StrokeWidth 0 | Fill Color 0,0,0,255 | Rotate ([Loop]+90),-45,-45
Shape5=Ellipse 110,110,15,15 | StrokeWidth 0 | Fill Color 0,0,0,255 | Rotate ([Loop]+135),-45,-45
Shape6=Ellipse 110,110,15,15 | StrokeWidth 0 | Fill Color 0,0,0,255 | Rotate ([Loop]+180),-45,-45
Shape7=Ellipse 110,110,15,15 | StrokeWidth 0 | Fill Color 0,0,0,255 | Rotate ([Loop]+225),-45,-45
Shape8=Ellipse 110,110,15,15 | StrokeWidth 0 | Fill Color 0,0,0,255 | Rotate ([Loop]+270),-45,-45
Shape9=Ellipse 110,110,15,15 | StrokeWidth 0 | Fill Color 0,0,0,255 | Rotate ([Loop]+315),-45,-45
W=152
H=152
X=300
Y=300

Now the hard part begins!

I would like to move the spheres away with the mouseover and mouseleave.

I thought about using the clamp with actiontimer, but I have no idea how to apply this!
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, 3:01 pm with this code I get the message:

Formula:Syntax error: (#CenterX#+#Radius#*Cos([Counter]))
Formula:Syntax error: (#CenterY#-#Radius#*Sin([Counter]))
Really?! :rofl: Then how comes it doesn't happen for me? :???:

Code:

Code: Select all

[Variables]
CenterX=100
CenterY=100
Radius=100

[Rainmeter]
Update=25
DynamicWindowSize=1
AccurateText=1
SkinWidth=240
SkinHeight=240
BackgroundMode=2
SolidColor=0,0,0,32

---Measures---

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

---Meters---

[Body]
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 1 | Stroke Color 255,0,0,255
DynamicVariables=1
Preview:
ezgif.com-gif-maker.gif
An answer generally assumes that the one asking the question can understand that there might be "some" minor changes and prerequisites - like converting to radians instead of degrees (0 to 2*PI interval, get it?), or declaring the variables in the [Variables] section) - in order to make the solution work. You can't just copy paste stuff and expect things to magically happen, LOL. And if you do, then better stick with already made code anyway... :confused:

P.S. By the way, that was not a "code", but the formulas needed to make it happen. I was on mobile then, so I couldn't write every little measure and meter for you.
You do not have the required permissions to view the files attached to this post.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
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:10 pm Really?! :rofl: Then how comes it doesn't happen for me? :???:

Code:

Code: Select all

[Variables]
CenterX=100
CenterY=100
Radius=100

[Rainmeter]
Update=25
DynamicWindowSize=1
AccurateText=1
SkinWidth=240
SkinHeight=240
BackgroundMode=2
SolidColor=0,0,0,32

---Measures---

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

---Meters---

[Body]
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 1 | Stroke Color 255,0,0,255
DynamicVariables=1
Preview:
ezgif.com-gif-maker.gif

An answer generally assumes that the one asking the question can understand that there might be "some" minor changes and prerequisites - like converting to radians instead of degrees (0 to 2*PI interval, get it?), or declaring the variables in the [Variables] section) - in order to make the solution work. You can't just copy paste stuff and expect things to magically happen, LOL. And if you do, then better stick with already made code anyway... :confused:

P.S. By the way, that was not a "code", but the formulas needed to make it happen. I was on mobile then, so I couldn't write every little measure and meter for you.
I understand!! I was using it wrong, really!

I believe with this formula, now I can change with ActionTimer the variable # Radius #. But i will test this!

I'm learning to rainmeter. So it's all on the basis of trial and error for now. Sorry for anything.

Thank you so much for your help!
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, 4:28 pm I understand!! I was using it wrong, really!

I believe with this formula, now I can change with ActionTimer the variable # Radius #. But i will test this!

I'm learning to rainmeter. So it's all on the basis of trial and error for now. Sorry for anything.

Thank you so much for your help!
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. ;-)
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth