Skip to content

Commit

Permalink
Add/update example plugins and remove some duds
Browse files Browse the repository at this point in the history
  • Loading branch information
andybak committed Jan 5, 2025
1 parent e5e99e6 commit 50e8ef9
Show file tree
Hide file tree
Showing 13 changed files with 389 additions and 184 deletions.
22 changes: 22 additions & 0 deletions Assets/Resources/LuaScriptExamples/PointerScript.Spirograph.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Settings = {
description="Draws a spirograph pattern around the pointer."
}

Parameters = {
outerRadius={label="Outer Radius", type="float", min=0.1, max=5, default=2},
innerRadius={label="Inner Radius", type="float", min=0.1, max=5, default=1},
penOffset={label="Pen Offset", type="float", min=0.1, max=5, default=1},
speed={label="Speed", type="float", min=0.1, max=10, default=2},
}

function Main()
local t = App.time * Parameters.speed
local outerAngle = t
local innerAngle = t * Parameters.outerRadius / Parameters.innerRadius

local x = (Parameters.outerRadius - Parameters.innerRadius) * Math:Cos(outerAngle) + Parameters.penOffset * Math:Cos(innerAngle)
local y = (Parameters.outerRadius - Parameters.innerRadius) * Math:Sin(outerAngle) - Parameters.penOffset * Math:Sin(innerAngle)

local position = Vector2:New(x, y):OnZ() -- Convert 2D to 3D on the Z plane
return Transform:New(position)
end

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

38 changes: 38 additions & 0 deletions Assets/Resources/LuaScriptExamples/SymmetryScript.PointSymSpin.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Settings = {
description="Point Symmetry Spin", space="widget"
}

Parameters = {
symType={label="Symmetry Type", type=SymmetryPointType},
symOrder={label="Symmetry Order", type="int", min=1, max=10, default=6},
frequency={label="Frequency", type="float", min=0.01, max=10, default=5},
size={label="Size", type="float", min=1, max=10, default=1},
}

symmetryHueShift = require "symmetryHueShift"

function Start()
initialHsv = Brush.colorHsv
end

function Main()

mySymSettings = SymmetrySettings:NewPointSymmetry(Parameters.symType, Parameters.symOrder)
pointers = mySymSettings.matrices

if Brush.triggerPressedThisFrame then
symmetryHueShift.generate(pointers.count, initialHsv)
end

-- Rotate each matrix around the origin based on the current time
tx = Math:Cos(App.time * Parameters.frequency) * Parameters.size
ty = Math:Sin(App.time * Parameters.frequency) * Parameters.size
for i = 0, pointers.count - 1 do
pointers[i] = pointers[i] * Matrix:NewTranslation(Vector3:New(tx, ty, 0))
end
return pointers
end

function End()
-- TODO fix Brush.colorHsv = initialHsv
end

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

Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
Settings = {space="pointer"}

Parameters = {
copies={label="Copies", type="int", min=1, max=96, default=32},
}

symmetryHueShift = require "symmetryHueShift"

function Start()
initialHsv = Brush.colorHsv
stroke = Sketch.strokes.last
updatePath()
end

function Main()

-- Update the path only when we change the number of copies
if Parameters.copies ~= previousCopies then
updatePath()
previousCopies = Parameters.copies
end

return path

end

function updatePath()

if stroke == nil then
App:Error("Please draw a stroke and then restart this plugin")
path = Path:New()
else
path = stroke.path
path:SampleByCount(Parameters.copies)
path:Center()
symmetryHueShift.generate(Parameters.copies, initialHsv)
end

end
Settings = {
space="pointer",
description="Uses the points of the most recently drawn stroke to generate new strokes"
}

Parameters = {
copies={label="Copies", type="int", min=1, max=96, default=32},
}

symmetryHueShift = require "symmetryHueShift"

function Start()
initialHsv = Brush.colorHsv
stroke = Sketch.strokes.last
updatePath()
end

function Main()

-- Update the path only when we change the number of copies
if Parameters.copies ~= previousCopies then
updatePath()
previousCopies = Parameters.copies
end

return path

end

function updatePath()

if stroke == nil then
App:Error("Please draw a stroke and then restart this plugin")
path = Path:New()
else
path = stroke.path
path:SampleByCount(Parameters.copies)
path:Center()
symmetryHueShift.generate(Parameters.copies, initialHsv)
end

end

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

41 changes: 0 additions & 41 deletions Assets/Resources/LuaScriptExamples/ToolScript.CircularPath.lua

This file was deleted.

171 changes: 171 additions & 0 deletions Assets/Resources/LuaScriptExamples/ToolScript.Platonic.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
Settings = {
description = "Draws the wireframe of a chosen Platonic solid",
previewType = "cube"
}

Parameters = {
solidType = {
label = "Solid Type",
type = "list",
items= {"Tetrahedron", "Cube", "Octahedron", "Dodecahedron", "Icosahedron"},
default = "Icosahedron"
},
spacing = {label="Point Spacing", type="float", min=0.1, max=1, default=0.1}
}

-- Helper function to get vertices and faces of Platonic solids
function GetPlatonicSolidData(solidType)
local vertices = {}
local faces = {}

if solidType == "Tetrahedron" then
vertices = {
Vector3:New(1, 1, 1), Vector3:New(-1, -1, 1),
Vector3:New(-1, 1, -1), Vector3:New(1, -1, -1)
}
faces = {
{1, 2, 3}, {1, 2, 4}, {1, 3, 4}, {2, 3, 4}
}
elseif solidType == "Cube" then
vertices = {
Vector3:New(-1, -1, -1), Vector3:New(1, -1, -1),
Vector3:New(1, 1, -1), Vector3:New(-1, 1, -1),
Vector3:New(-1, -1, 1), Vector3:New(1, -1, 1),
Vector3:New(1, 1, 1), Vector3:New(-1, 1, 1)
}
faces = {
{1, 2, 3, 4}, {5, 6, 7, 8}, {1, 2, 6, 5},
{2, 3, 7, 6}, {3, 4, 8, 7}, {4, 1, 5, 8}
}
elseif solidType == "Octahedron" then

vertices = {
Vector3:New(0, 0, 1), Vector3:New(0, 0, -1),
Vector3:New(1, 0, 0), Vector3:New(-1, 0, 0),
Vector3:New(0, 1, 0), Vector3:New(0, -1, 0)
}
faces = {
{1, 3, 5}, {1, 5, 4}, {1, 4, 6}, {1, 6, 3},
{2, 3, 5}, {2, 5, 4}, {2, 4, 6}, {2, 6, 3}
}

elseif solidType == "Dodecahedron" then

local root5 = Math:Sqrt(5);
local phi = (1 + root5) / 2;
local phibar = (1 - root5) / 2;
local X = 1/(root5-1);
local Y = X*phi;
local Z = X*phibar;
local S = -X;
local T = -Y;
local W = -Z;

vertices = {
Vector3:New(X, X, X),
Vector3:New(X, X, S),
Vector3:New(X, S, X),
Vector3:New(X, S, S),
Vector3:New(S, X, X),
Vector3:New(S, X, S),
Vector3:New(S, S, X),
Vector3:New(S, S, S),
Vector3:New(W, Y, 0),
Vector3:New(Z, Y, 0),
Vector3:New(W, T, 0),
Vector3:New(Z, T, 0),
Vector3:New(Y, 0, W),
Vector3:New(Y, 0, Z),
Vector3:New(T, 0, W),
Vector3:New(T, 0, Z),
Vector3:New(0, W, Y),
Vector3:New(0, Z, Y),
Vector3:New(0, W, T),
Vector3:New(0, Z, T),
}

faces = {
{2, 9, 1, 13, 14},
{5, 10, 6, 16, 15},
{3, 11, 4, 14, 13},
{8, 12, 7, 15, 16},
{3, 13, 1, 17, 18},
{2, 14, 4, 20, 19},
{5, 15, 7, 18, 17},
{8, 16, 6, 19, 20},
{5, 17, 1, 9, 10},
{3, 18, 7, 12, 11},
{2, 19, 6, 10, 9},
{8, 20, 4, 11, 12}
}

elseif solidType == "Icosahedron" then

local root5 = Math:Sqrt(5);
local n = 1/2;
local X = n * (1 + root5) / 2;
local Y = -X;
local Z = n;
local W = -n;

vertices = {
Vector3:New(X, Z, 0),
Vector3:New(Y, Z, 0),
Vector3:New(X, W, 0),
Vector3:New(Y, W, 0),
Vector3:New(Z, 0, X),
Vector3:New(Z, 0, Y),
Vector3:New(W, 0, X),
Vector3:New(W, 0, Y),
Vector3:New(0, X, Z),
Vector3:New(0, Y, Z),
Vector3:New(0, X, W),
Vector3:New(0, Y, W),
}

faces = {
{1, 9, 5},
{1, 6, 11},
{3, 5, 10},
{3, 12, 6},
{2, 7, 9},
{2, 11, 8},
{4, 10, 7},
{4, 8, 12},
{1, 11, 9},
{2, 9, 11},
{3, 10, 12},
{4, 12, 10},
{5, 3, 1},
{6, 1, 3},
{7, 2, 4},
{8, 4, 2},
{9, 7, 5},
{10, 5, 7},
{11, 6, 8},
{12, 8, 6}
}

end

return vertices, faces
end

function Main()
if Brush.triggerReleasedThisFrame then
local vertices, faces = GetPlatonicSolidData(Parameters.solidType)
local pathList = PathList:New()

for _, face in ipairs(faces) do
local path = Path:New()
for _, vertexIndex in ipairs(face) do
path:Insert(Transform:New(vertices[vertexIndex]))
end
path:Insert(Transform:New(vertices[face[1]])) -- Close the loop
path:SampleByDistance(Parameters.spacing) -- Create evenly spaced points
pathList:Insert(path)
end

return pathList
end
end
10 changes: 10 additions & 0 deletions Assets/Resources/LuaScriptExamples/ToolScript.Platonic.lua.meta

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

Loading

0 comments on commit 50e8ef9

Please sign in to comment.