It is currently July 17th, 2019, 1:40 pm

Drawing diagonal lines

Tips and Tricks from the Rainmeter Community
User avatar
ikarus1969
Posts: 331
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Drawing diagonal lines

ikarus1969 » March 29th, 2014, 4:46 pm

Have you ever wondered how to draw lines?

Not only those vertical or horizontal ones that are simulated by an image-meter but diagonal ones?

Here is how you can achieve that: for one line i use 3 measures and one meter.

The 3 measures are for calculating
  1. the angle between the start- and end-point of the line
  2. the length of the line (the distance between the start- and end-point)
The line itself is "drawn" by a "ROUNDLINE"-meter with the center as the starting-point.

The first code is a very simple skin where just one line is drawn.
The second one is only a little bit more complictaed and draws lines between random choosen points on the screen.
Both are fully functional.

Have fun! :welcome:

simple skin:

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1

[Metadata]
Author=ikarus1969
Name=Draw lines
Description=Drawing lines beyond only horizontal / vertical with images
Instructions=No instructions so far
Version=1
License=Public Domain

[Variables]
; Start point      : #LINE_P1X#, #LINE_P1Y#
; End   point      : #LINE_P2X#, #LINE_P2Y#
; width of the line: #LINE_Width#
LINE_P1X=10
LINE_P1Y=10
LINE_P2X=200
LINE_P2Y=150
LINE_Width=1

; -------------
; some measures
; -------------
; to calculate the angle between the starting-point and the end-point
[Measure_GetAngle_ATAN]
Measure=CALC
Formula=Atan((#LINE_P2Y# - #LINE_P1Y#) / (#LINE_P2X# - #LINE_P1X#))
DynamicVariables=1

; a "speciality" of the arcus-tangens-function:
;    you have to put it in the right quadrant to get the correct result
[Measure_GetAngle]
Measure=CALC
Formula=(#LINE_P2X# - #LINE_P1X#) <= 0 ? Measure_GetAngle_ATAN + (PI * 1.5) : Measure_GetAngle_ATAN + (PI / 2)
DynamicVariables=1
MinValue=0
MaxValue=(2*PI)

[Measure_LineLength]
Measure=CALC
Formula=Floor(Sqrt(((#LINE_P1X#-#LINE_P2X#)*(#LINE_P1X#-#LINE_P2X#))+((#LINE_P1Y#-#LINE_P2Y#)*(#LINE_P1Y#-#LINE_P2Y#))) + 0.5)
DynamicVariables=1


; ------------------------
; the "STRAIGHTLINE"-meter
; ------------------------
[Meter_LINE_From_A_to_B]
Meter=ROUNDLINE
MeasureName=Measure_GetAngle
X=(#LINE_P1X#-[Measure_LineLength])
Y=(#LINE_P1Y#-[Measure_LineLength])
W=(2 * [Measure_LineLength])
H=(2 * [Measure_LineLength])
LineWidth=#LINE_Width#
LineLength=([Measure_LineLength])
LineStart=0
StartAngle=(-PI/2)
RotationAngle=(PI * 2)
LineColor=000000FF
Solid=0
AntiAlias=1
DynamicVariables=1

drawing random lines:

Code: Select all

[Rainmeter]
Update=5000
AccurateText=1

[Metadata]
Author=ikarus1969
Name=Draw lines
Description=Drawing lines beyond only horizontal / vertical with images
Instructions=No instructions so far
Version=1
License=Public Domain

[Variables]
; Start point      : #LINE_P1X#, #LINE_P1Y#
; End   point      : #LINE_P2X#, #LINE_P2Y#
; width of the line: #LINE_Width#
LINE_P1X=10
LINE_P1Y=10
LINE_P2X=200
LINE_P2Y=150
LINE_Width=10

; -------------
; some measures
; -------------
;randomize start-point in the first half of the screen
[Measure_random_X1]
Measure=CALC
Formula=Random
UpdateRandom=1
UniqueRandom=1
LowBound=(#WORKAREAX# + 40)
HighBound=(#WORKAREAX# + (#WORKAREAWIDTH# / 2) - 40)
DynamicVariables=1

[Measure_random_Y1]
Measure=CALC
Formula=Random
UpdateRandom=1
UniqueRandom=1
LowBound=(#WORKAREAY# + 40)
HighBound=(#WORKAREAY# + #WORKAREAHEIGHT# - 40)
DynamicVariables=1

;randomize end-point in the second half of the screen
[Measure_random_X2]
Measure=CALC
Formula=Random
UpdateRandom=1
UniqueRandom=1
LowBound=(#WORKAREAX# + (#WORKAREAWIDTH# / 2) + 40)
HighBound=(#WORKAREAX# + #WORKAREAWIDTH# - 40)
DynamicVariables=1

[Measure_random_Y2]
Measure=CALC
Formula=Random
UpdateRandom=1
UniqueRandom=1
LowBound=(#WORKAREAY# + 40)
HighBound=(#WORKAREAY# + #WORKAREAHEIGHT# - 40)

[Measure_Set_Coordinates]
Measure=CALC
Formula=0
OnUpdateAction=[!SetVariable LINE_P1X [Measure_random_X1:]][!SetVariable LINE_P1Y [Measure_random_Y1:]][!SetVariable LINE_P2X [Measure_random_X2:]][!SetVariable LINE_P2Y [Measure_random_Y2:]]



; to calculate the angle between the starting-point and the end-point
[Measure_GetAngle_ATAN]
Measure=CALC
Formula=Atan((#LINE_P2Y# - #LINE_P1Y#) / (#LINE_P2X# - #LINE_P1X#))
DynamicVariables=1


; a "speciality" of the arcus-tangens-function:
;    you have to put it in the right quadrant to get the correct result
[Measure_GetAngle]
Measure=CALC
Formula=(#LINE_P2X# - #LINE_P1X#) <= 0 ? Measure_GetAngle_ATAN + (PI * 1.5) : Measure_GetAngle_ATAN + (PI / 2)
DynamicVariables=1
MinValue=0
MaxValue=(2*PI)


; just for the info-string-meter at the bottom:
[Measure_GetAngle_DEG]
Measure=CALC
Formula=(Measure_GetAngle * 180) / PI

[Measure_LineLength]
Measure=CALC
Formula=Floor(Sqrt(((#LINE_P1X#-#LINE_P2X#)*(#LINE_P1X#-#LINE_P2X#))+((#LINE_P1Y#-#LINE_P2Y#)*(#LINE_P1Y#-#LINE_P2Y#))) + 0.5)
DynamicVariables=1


; ------------------------------------------
; Divider between the 2 halfes of the screen
; ------------------------------------------
[Meter_LINE_Divider]
Meter=IMAGE
X=(#WORKAREAX# + (#WORKAREAWIDTH# / 2) - (#Line_Width# / 2))
Y=#WORKAREAY#
W=#LINE_Width#
H=#WORKAREAHEIGHT#
SolidColor=FFFF00FF
AntiAlias=1
DynamicVariables=1

; -----------------------------------------
; MAIN ACTOR here: the "STRAIGHTLINE"-meter
; -----------------------------------------
[Meter_LINE_From_A_to_B]
Meter=ROUNDLINE
MeasureName=Measure_GetAngle
X=(#LINE_P1X#-[Measure_LineLength])
Y=(#LINE_P1Y#-[Measure_LineLength])
W=(2 * [Measure_LineLength])
H=(2 * [Measure_LineLength])
LineWidth=#LINE_Width#
LineLength=([Measure_LineLength])
LineStart=0
StartAngle=(-PI/2)
RotationAngle=(PI * 2)
LineColor=4080C0FF
Solid=0
AntiAlias=1
DynamicVariables=1

; --------------------------------------------
; marking the start- and end-point of the line
; --------------------------------------------
[Meter_LINE_Start]
Meter=ROUNDLINE
X=(#LINE_P1X#- 2 * #LINE_Width#)
Y=(#LINE_P1Y#- 2 * #LINE_Width#)
W=(4 * #LINE_Width#)
H=(4 * #LINE_Width#)
LineWidth=1
LineLength=(2 * #LINE_Width#)
LineStart=0
StartAngle=(-PI/2)
RotationAngle=(PI * 2)
LineColor=008000FF
Solid=1
AntiAlias=1
DynamicVariables=1

[Meter_LINE_End]
Meter=ROUNDLINE
X=(#LINE_P2X#- 2 * #LINE_Width#)
Y=(#LINE_P2Y#- 2 * #LINE_Width#)
W=(4 * #LINE_Width#)
H=(4 * #LINE_Width#)
LineWidth=1
LineLength=(2 * #LINE_Width#)
LineStart=0
StartAngle=(-PI/2)
RotationAngle=(PI * 2)
LineColor=FF0000FF
Solid=1
AntiAlias=1
DynamicVariables=1


; -----------
; - some info
; -----------
[Meter_Info]
Meter=STRING
MeasureName=Measure_GetAngle_DEG
X=(#WORKAREAX# + (#WORKAREAWIDTH# / 2) - (#Line_Width# / 2))
Y=([Meter_BG:Y] + 27)
Text="P1(#LINE_P1X#, #LINE_P1Y#) - P2(#LINE_P2X#, #LINE_P2Y#)#CRLF#Angle=%1°, Length=[Measure_LineLength]"
NumOfDecimals=2
Padding=40,20,40,20
Fontface=Arial
FontColor=FFFFFFFF
FontSize=12
StringAlign=CENTER
StringStyle=BOLD
SolidColor=000000E0
AntiAlias=1
DynamicVariables=1
User avatar
ikarus1969
Posts: 331
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: Drawing diagonal lines

ikarus1969 » March 30th, 2014, 6:32 am

An animated gif to show a clock using the diagonal-lines from my initial post:
Rainmeter Diagonal lines with roundline.gif
You do not have the required permissions to view the files attached to this post.
User avatar
Mordasius
Posts: 1059
Joined: January 22nd, 2011, 4:23 pm
Location: GMT +8

Re: Drawing diagonal lines

Mordasius » April 1st, 2014, 11:27 am

Nifty stuff. Can't imagine why nobody else thought of using a Roundline meter to draw diagonal lines. It's about as obvious as the Northern Lights in Ecuador.
User avatar
moshi
Posts: 1851
Joined: November 13th, 2012, 9:53 pm

Re: Drawing diagonal lines

moshi » April 1st, 2014, 2:25 pm

pretty cool! too bad i'm too old to remember trigonometry. the only math left is stochastic.
User avatar
ikarus1969
Posts: 331
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: Drawing diagonal lines

ikarus1969 » April 2nd, 2014, 9:47 am

moshi wrote:pretty cool! too bad i'm too old to remember trigonometry. the only math left is stochastic.
Let's see if you can beat my 44 years :sly: (and i admit i had forgotten that part of trigonometry too - but some search on the web helped me to remember)