Skip to content

Commit

Permalink
Elliptical symmetry
Browse files Browse the repository at this point in the history
[CI BUILD]
  • Loading branch information
andybak committed Apr 5, 2023
1 parent 8ed1cc7 commit 20cdc7c
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 1 deletion.
58 changes: 58 additions & 0 deletions Assets/Resources/LuaScriptExamples/SymmetryScript.Ellipse.lua
@@ -0,0 +1,58 @@
Settings = {
description="Radial copies of your stroke with optional color shifts"
}

Parameters = {
copies={label="Number of copies", type="int", min=1, max=36, default=32},
eccentricity={label="Eccentricity", type="float", min=0.1, max=3, default=2},
axisConsistency={label="Axis Consistency", type="float", min=0, max=2, default=1},
hueShiftFrequency={label="Hue Shift Frequency", type="float", min=0.1, max=6, default=1},
hueShiftAmount={label="Hue Shift Amount", type="float", min=0, max=1, default=0.3}
}

function Start()
initialHsv = brush.colorHsv
--symmetry.transform = {
-- {0, 10, 6},
-- {0, 90, 90}
--}
end

function Main()

pointers = {}
theta = (math.pi * 2.0) / copies
Colors = {}

for i = 0, copies - 1 do
angle = (symmetry.rotation.y * unityMathf.deg2Rad) + i * theta
pointer = {
position={
symmetry.brushOffset.x * symmetry.ellipse(angle, eccentricity),
symmetry.brushOffset.y,
unityMathf.lerp(
symmetry.brushOffset.z,
symmetry.brushOffset.z * symmetry.ellipse(angle, eccentricity),
axisConsistency
),
},
rotation={0, angle * unityMathf.rad2Deg, 0}
}
table.insert(pointers, pointer)

--Colour cycling for the extra pointers
if hueShiftAmount > 0 then
t = i / copies
newHue = waveform.triangle(t, hueShiftFrequency) * hueShiftAmount
newColor = unityColor.hsvToRgb(initialHsv.x + newHue, initialHsv.y, initialHsv.z)
table.insert(Colors, newColor)
end

end
return pointers
end

function End()
--TODO
--color.setHsv(color.HsvToRgb(brush.colorHsv))
end
10 changes: 10 additions & 0 deletions Assets/Resources/LuaScriptExamples/SymmetryScript.Ellipse.lua.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -26,7 +26,7 @@ function Main()
angle = i * theta
pointer = {
position={
symmetry.brushOffset.x * (1 + (math.sin(angle/360 * 8 * math.pi)) * 0.125),
symmetry.brushOffset.x,
symmetry.brushOffset.y,
symmetry.brushOffset.z
},
Expand Down
@@ -0,0 +1,52 @@
Settings = {
description="Radial copies of your stroke with optional color shifts"
}

Parameters = {
copies={label="Number of copies", type="int", min=1, max=36, default=32},
hueShiftFrequency={label="Hue Shift Frequency", type="float", min=0.1, max=6, default=1},
hueShiftAmount={label="Hue Shift Amount", type="float", min=0, max=1, default=0.3}
}

function Start()
initialHsv = brush.colorHsv
--symmetry.transform = {
-- {0, 10, 6},
-- {0, 90, 90}
--}
end

function Main()

pointers = {}
theta = 360.0 / copies
Colors = {}

for i = 0, copies - 1 do
angle = i * theta
pointer = {
position={
symmetry.brushOffset.x * (1 + (math.sin(angle/360 * 16 * math.pi)) * 0.25),
symmetry.brushOffset.y,
symmetry.brushOffset.z
},
rotation={0, angle, 0}
}
table.insert(pointers, pointer)

--Colour cycling for the extra pointers
if hueShiftAmount > 0 then
t = i / copies
newHue = waveform.triangle(t, hueShiftFrequency) * hueShiftAmount
newColor = unityColor.hsvToRgb(initialHsv.x + newHue, initialHsv.y, initialHsv.z)
table.insert(Colors, newColor)
end

end
return pointers
end

function End()
--TODO
--color.setHsv(color.HsvToRgb(brush.colorHsv))
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Assets/Scripts/API/Lua/Wrappers/OpenBrushAppWrappers.cs
Expand Up @@ -200,6 +200,10 @@ public static Quaternion rotation
public static void twoHandeded() => ApiMethods.SymmetryTwoHanded();
public static void summonWidget() => ApiMethods.SummonMirror();
public static void spin(Vector3 rot) => PointerManager.m_Instance.SymmetryWidget.Spin(rot);
public static float ellipse(float angle, float minorRadius)
{
return minorRadius / Mathf.Sqrt(Mathf.Pow(minorRadius * Mathf.Cos(angle), 2) + Mathf.Pow(Mathf.Sin(angle), 2));
}
}

[MoonSharpUserData]
Expand Down

0 comments on commit 20cdc7c

Please sign in to comment.