Last active
August 29, 2015 14:18
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Input = | |
(LTrim0 C | |
60 30 | |
'"^+$ | |
linear 30 30 0 0 | |
) | |
Gui, Font,, Courier New | |
Gui, Add, Edit, w640 h480, % GenerateGradient(Input) | |
Gui, Show | |
return | |
GuiClose: | |
ExitApp | |
return | |
GenerateGradient(Input) | |
{ | |
Input := StrSplit(Input, "`n", "`r") | |
Dimensions := StrSplit(Input[1], " ") | |
Chars := StrSplit(Input[2], "", "") | |
Params := StrSplit(Input[3], " ") | |
CharLen := Chars.MaxIndex() | |
if (Params[1] = "Radial") ; = is case insensitive | |
{ | |
rx := Params[2]+1 ; 1 indexed | |
ry := Params[3]+1 | |
r := Params[4] | |
Loop, % Dimensions[2] | |
{ | |
y := A_Index | |
Loop, % Dimensions[1] | |
{ | |
x := A_Index | |
Distance := Sqrt((x-rx)**2 + (y-ry)**2) | |
CharIndex := Floor(Distance/r*CharLen) + 1 ; 1 indexed | |
Out .= CharIndex <= CharLen ? Chars[CharIndex] : Chars[CharLen] | |
} | |
Out .= "`n" | |
} | |
} | |
else if (Params[1] = "Linear") ; Everything in this part is broken and I'm trying to fix it | |
{ | |
x1 := Params[2], y1 := Params[3] | |
x2 := Params[4], y2 := Params[5] | |
Angle := (y2-y1)/(x2-x1) ; Rise over run, right? That's what I learned in basic geom? | |
Loop, % Dimensions[2] | |
{ | |
y := A_Index | |
Loop, % Dimensions[1] | |
{ | |
x := A_Index | |
Distance := (x1-x) + (y1-y)*Angle | |
CharIndex := Floor(Distance/) + 1 | |
; Oh how I long for a proper clamp(), or just max() and min() | |
CharIndex := CharIndex>CharLen ? CharLen : CharIndex<1 ? 1 : CharIndex | |
Out .= CharIndex ;<= CharLen ? Chars[CharIndex] : Chars[CharLen] | |
} | |
Out .= "`n" | |
} | |
} | |
return Out | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment