Good approach, however I think there is a way to simplify even more the code. For this you should have to use the newer !SetWindowPosition bang, instead of !Move. For instance:To restrict the skin to a central position and limit how far off center it moves from that point, look at this example.
Code:
[Rainmeter]OnRefreshAction=[!SetWindowPosition "(50+[MeasureX])%" "(50+[MeasureY])%" "50%" "50%"][Variables]StepRate=10OffCenterMaxPercent=25[MeasureX]Measure=CalcFormula=RandomLowBound=-#OffCenterMaxPercent#HighBound=#OffCenterMaxPercent#UpdateRandom=1UpdateDivider=-1Group=Position[MeasureY]Measure=CalcFormula=RandomLowBound=-#OffCenterMaxPercent#HighBound=#OffCenterMaxPercent#UpdateRandom=1UpdateDivider=-1DynamicVariables=1Group=Position[MeasureTimer]Measure=CalcOnUpdateAction=[!UpdateMeasureGroup "Position"][!SetWindowPosition "(50+[MeasureX])%" "(50+[MeasureY])%" "50%" "50%"]UpdateDivider=#StepRate#DynamicVariables=1[MeterImage]Meter=ShapeX=2Y=2Shape=Rectangle 1,1,200,200,4 | StrokeWidth 2 | Fill Color 244,220,100DynamicVariables=1[Location]Meter=StringMeasureName=MeasureXMeasureName2=MeasureYStringAlign=CenterCenterStringStyle=BoldX=100Y=100Text=X=%1#CRLF#Y=%2
- I replaced the !Move bangs with !SetWindowPosition (both of them, in the OnRefreshAction option of the [Rainmeter] section and on the [MeasureTime] measure, however I rewrote this measure as well - see below). The advantage of this bang against !Move is that you easily can set the anchor point of the skin, by the last two parameters, no need to calculate the position of the skin to get it centered. I set both of them to 50%, this way getting the skin centered around the appropriate point.
- I replaced both, the LowBound and HighBound options of the [MeasureX] and [MeasureY] measures by LowBound=-#OffCenterMaxPercent# and HighBound=#OffCenterMaxPercent#. OffCenterMaxPercent is a variable defined into the [Variables] section and it represents the percentage with which the skin can move away by the center of the screen. The generated random numbers are kept between -#OffCenterMaxPercent# and #OffCenterMaxPercent#, ensuring a move of the skin around the center of the screen (which is set by the 50% used in the formulas of first two parameters of the !SetWindowPosition bangs).
- I removed the Formula option of the [MeasureTimer] measure (not needed in this approach), added an UpdateDivider=#StepRate# option to get it updated on each #StepRate# seconds. A DynamicVariables=1 was required as well, so I added this one as well.
- I removed the DynamicVariables=1 options from the [MeasureX] and [MeasureY] options. By simplifying these measures, the DynamicVariables option became useless.
- I removed the not needed anymore XCenterPosition and YCenterPosition variables from the [Variables] section.
- I kept unchanged both meters.
Statistics: Posted by balala — Yesterday, 7:14 pm