Request: Noisy Point Animation to Selected layers

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
8BitHobo
Posts: 12
Joined: Fri Jul 06, 2018 8:02 pm

Request: Noisy Point Animation to Selected layers

Post by 8BitHobo »

Hey Hey guys,
Love the new "Noisy Point Animation tool" in the new update, really gives a great hand drawn effect to the animation, however as is I believe you have to select the points in a layer, go to scripts and apply the Noisy Point Animation to each layer/selected points. Is it possible to make a script to apply this to many layers at once?
It looks great but is a bit of a hassle applying it to every layer individually.

Thanks for looking!
User avatar
Greenlaw
Posts: 9269
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: Request: Noisy Point Animation to Selected layers

Post by Greenlaw »

I think all this script does is it automates applying and setting a Noisy key at frame 0. You can do this by selecting each of the vector layers you wish to apply this effect to and pasting the key. A little simpler but...

What might be easier is to select all the vector layers you wish to apply the effect to, go into layer settings and enable Noisy Outlines, Noisy Fills, Animated Noise, and optionally Extra Sketchy. You may also want to increase the Interval so it's not too noisy. When multiple layers are selected, you can apply these settings to all of them at once.

Personally, I prefer doing this sort of thing in compositing program where I have a bit more control over the timing and overall look. But there, it's a pixel displacement and not vector, so that might not be what you want.

Hope this helps.
User avatar
Greenlaw
Posts: 9269
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: Request: Noisy Point Animation to Selected layers

Post by Greenlaw »

Playing around with this and I guess one big difference with using the Timeline's Noisy channel method (what the script does) is it applies the animation to selected points only. That's pretty neat when you only want some points to jitter. Like, for example, jitter a simple outline character's hair but not his entire head. Because of this, I don't think this tool was ever meant to be used on multiple layers at once because you generally don't want to select and animate points this way.

If you want to apply this effect to all points in multiple layers all at once, using the Layer Settings method described in the previous post is the way to go.
User avatar
synthsin75
Posts: 9975
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Request: Noisy Point Animation to Selected layers

Post by synthsin75 »

Since it works on all selected points, I assume you want it to work on all points of every selected layer. Otherwise, you'd have to select every layer to select the points.
So with more that one layer selected, this affects all points on selected layers.

Code: Select all

-- **************************************************
-- Provide Moho with the name of this script object
-- **************************************************

ScriptName = "LM_NoisyPointAnimation"

-- **************************************************
-- General information about this script
-- **************************************************

LM_NoisyPointAnimation = {}

LM_NoisyPointAnimation.BASE_STR = 2480

function LM_NoisyPointAnimation:Name()
	return "NoisyPointAnimation"
end

function LM_NoisyPointAnimation:Version()
	return "13.5.2"
end

function LM_NoisyPointAnimation:Description()
	return MOHO.Localize("/Scripts/Menu/NoisyPointAnimation/Description=Sets selected points' animation to noisy interpolation.")
end

function LM_NoisyPointAnimation:Creator()
	return "Lost Marble LLC, modified (c)2021 J.Wesley Fowler (synthsin75)"
end

function LM_NoisyPointAnimation:UILabel()
	return(MOHO.Localize("/Scripts/Menu/NoisyPointAnimation/NoisyPointAnimation=Noisy Point Animation..."))
end

-- **************************************************
-- Recurring values
-- **************************************************

LM_NoisyPointAnimation.amplitude = 0.05
LM_NoisyPointAnimation.scale = 0.2
LM_NoisyPointAnimation.interval = 1

-- **************************************************
-- NoisyPointAnimation dialog
-- **************************************************

local LM_NoisyPointAnimationDialog = {}

function LM_NoisyPointAnimationDialog:new(moho)
	local d = LM.GUI.SimpleDialog(MOHO.Localize("/Scripts/Menu/NoisyPointAnimation/Title=Noisy Point Animation"), LM_NoisyPointAnimationDialog)
	local l = d:GetLayout()

	d.moho = moho

	l:PushH()
		l:PushV()
			l:AddChild(LM.GUI.StaticText(MOHO.Localize("/Scripts/Menu/NoisyPointAnimation/Amplitude=Amplitude")), LM.GUI.ALIGN_LEFT)
			l:AddChild(LM.GUI.StaticText(MOHO.Localize("/Scripts/Menu/NoisyPointAnimation/Scale=Scale")), LM.GUI.ALIGN_LEFT)
			l:AddChild(LM.GUI.StaticText(MOHO.Localize("/Scripts/Menu/NoisyPointAnimation/Interval=Interval")), LM.GUI.ALIGN_LEFT)
		l:Pop()
		l:PushV()
			d.amplitude = LM.GUI.TextControl(0, "000000", 0, LM.GUI.FIELD_UFLOAT)
			l:AddChild(d.amplitude)
			d.scale = LM.GUI.TextControl(0, "000000", 0, LM.GUI.FIELD_UFLOAT)
			l:AddChild(d.scale)
			d.interval = LM.GUI.TextControl(0, "000000", 0, LM.GUI.FIELD_UINT)
			l:AddChild(d.interval)
		l:Pop()
	l:Pop()

	return d
end

function LM_NoisyPointAnimationDialog:UpdateWidgets()
	self.amplitude:SetValue(LM_NoisyPointAnimation.amplitude)
	self.scale:SetValue(LM_NoisyPointAnimation.scale)
	self.interval:SetValue(LM_NoisyPointAnimation.interval)
end

function LM_NoisyPointAnimationDialog:OnValidate()
	local b = true
	if (not self:Validate(self.amplitude, 0.0001, 100)) then
		b = false
	end
	if (not self:Validate(self.scale, 0.0001, 30)) then
		b = false
	end
	if (not self:Validate(self.interval, 1, 60)) then
		b = false
	end
	return b
end

function LM_NoisyPointAnimationDialog:OnOK()
	LM_NoisyPointAnimation.amplitude = self.amplitude:FloatValue()
	LM_NoisyPointAnimation.scale = self.scale:FloatValue()
	LM_NoisyPointAnimation.interval = self.interval:Value()
end

-- **************************************************
-- The guts of this script
-- **************************************************

function LM_NoisyPointAnimation:IsEnabled(moho)
--[syn]	if (moho:CountSelectedPoints() > 0) then
--[[syn]]	if (moho.document:CountSelectedLayers() > 1) or (moho:CountSelectedPoints() > 0) then
		return true
	else
		return false
	end
end

function LM_NoisyPointAnimation:Run(moho)
	local mesh = moho:Mesh()
	if (mesh == nil) then
		return
	end

	local dlog = LM_NoisyPointAnimationDialog:new(moho)
	if (dlog:DoModal() == LM.GUI.MSG_CANCEL) then
		return
	end

--[syn]	moho.document:PrepUndo(moho.layer)
--[[syn]]	moho.document:PrepMultiUndo()
	moho.document:SetDirty()

	local interp = MOHO.InterpSetting:new_local()
--syn\/
	local count = -1
	local origLayer = moho.layer
	repeat
		count = count + 1
		local layer = moho.document:LayerByAbsoluteID(count)
		local multiLayers = moho.document:CountSelectedLayers() > 1
		if (layer and layer:SecondarySelection() and layer:LayerType() == MOHO.LT_VECTOR) then
			mesh = moho:LayerAsVector(layer):Mesh()
--syn/\
	for ptID = mesh:CountPoints() - 1, 0, -1 do
		local pt = mesh:Point(ptID)
--[syn]		if (pt.fSelected) then
--[[syn]]		if (multiLayers) or (pt.fSelected) then
			for keyID = pt.fAnimPos:CountKeys() - 1, 0, -1 do
				pt.fAnimPos:GetKeyInterpByID(keyID, interp)
				interp.interpMode = MOHO.INTERP_NOISY
				interp.val1 = self.amplitude
				interp.val2 = 1.0 / self.scale
				interp.interval = self.interval
				pt.fAnimPos:SetKeyInterpByID(keyID, interp)
			end
		end
	end
--syn\/
		end
	until not layer
--syn/\
end
User avatar
8BitHobo
Posts: 12
Joined: Fri Jul 06, 2018 8:02 pm

Re: Request: Noisy Point Animation to Selected layers

Post by 8BitHobo »

Yeah I thought It would be the same but it seems to tackle it slightly different with the script. The layer method seems to add artificial mumps along the vector lines whereas the script seems to move the points ever so slightly looking more subtle.
Hopefully the Gif below works =S

Image
User avatar
Greenlaw
Posts: 9269
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: Request: Noisy Point Animation to Selected layers

Post by Greenlaw »

I think you can get the same or similar displacement in the Layers Settings by using a low Offset, and high Scale value. For example, try 2 and 60 respectively. If you look at the preview window inside Layer Settings, it will show you what it will look like.

Basically, the low/high values displace the lines by a small distance but uses a larger fractal pattern so the jitter effect is broad and not so 'scribbly'...and similar to your second example.
User avatar
8BitHobo
Posts: 12
Joined: Fri Jul 06, 2018 8:02 pm

Re: Request: Noisy Point Animation to Selected layers

Post by 8BitHobo »

synthsin75 wrote: Mon Nov 22, 2021 12:09 am Since it works on all selected points, I assume you want it to work on all points of every selected layer. Otherwise, you'd have to select every layer to select the points.
So with more that one layer selected, this affects all points on selected layers.

Code: Select all

-- **************************************************
-- Provide Moho with the name of this script object
-- **************************************************

ScriptName = "LM_NoisyPointAnimation"

-- **************************************************
-- General information about this script
-- **************************************************

LM_NoisyPointAnimation = {}

LM_NoisyPointAnimation.BASE_STR = 2480

function LM_NoisyPointAnimation:Name()
	return "NoisyPointAnimation"
end

function LM_NoisyPointAnimation:Version()
	return "13.5.2"
end

function LM_NoisyPointAnimation:Description()
	return MOHO.Localize("/Scripts/Menu/NoisyPointAnimation/Description=Sets selected points' animation to noisy interpolation.")
end

function LM_NoisyPointAnimation:Creator()
	return "Lost Marble LLC, modified (c)2021 J.Wesley Fowler (synthsin75)"
end

function LM_NoisyPointAnimation:UILabel()
	return(MOHO.Localize("/Scripts/Menu/NoisyPointAnimation/NoisyPointAnimation=Noisy Point Animation..."))
end

-- **************************************************
-- Recurring values
-- **************************************************

LM_NoisyPointAnimation.amplitude = 0.05
LM_NoisyPointAnimation.scale = 0.2
LM_NoisyPointAnimation.interval = 1

-- **************************************************
-- NoisyPointAnimation dialog
-- **************************************************

local LM_NoisyPointAnimationDialog = {}

function LM_NoisyPointAnimationDialog:new(moho)
	local d = LM.GUI.SimpleDialog(MOHO.Localize("/Scripts/Menu/NoisyPointAnimation/Title=Noisy Point Animation"), LM_NoisyPointAnimationDialog)
	local l = d:GetLayout()

	d.moho = moho

	l:PushH()
		l:PushV()
			l:AddChild(LM.GUI.StaticText(MOHO.Localize("/Scripts/Menu/NoisyPointAnimation/Amplitude=Amplitude")), LM.GUI.ALIGN_LEFT)
			l:AddChild(LM.GUI.StaticText(MOHO.Localize("/Scripts/Menu/NoisyPointAnimation/Scale=Scale")), LM.GUI.ALIGN_LEFT)
			l:AddChild(LM.GUI.StaticText(MOHO.Localize("/Scripts/Menu/NoisyPointAnimation/Interval=Interval")), LM.GUI.ALIGN_LEFT)
		l:Pop()
		l:PushV()
			d.amplitude = LM.GUI.TextControl(0, "000000", 0, LM.GUI.FIELD_UFLOAT)
			l:AddChild(d.amplitude)
			d.scale = LM.GUI.TextControl(0, "000000", 0, LM.GUI.FIELD_UFLOAT)
			l:AddChild(d.scale)
			d.interval = LM.GUI.TextControl(0, "000000", 0, LM.GUI.FIELD_UINT)
			l:AddChild(d.interval)
		l:Pop()
	l:Pop()

	return d
end

function LM_NoisyPointAnimationDialog:UpdateWidgets()
	self.amplitude:SetValue(LM_NoisyPointAnimation.amplitude)
	self.scale:SetValue(LM_NoisyPointAnimation.scale)
	self.interval:SetValue(LM_NoisyPointAnimation.interval)
end

function LM_NoisyPointAnimationDialog:OnValidate()
	local b = true
	if (not self:Validate(self.amplitude, 0.0001, 100)) then
		b = false
	end
	if (not self:Validate(self.scale, 0.0001, 30)) then
		b = false
	end
	if (not self:Validate(self.interval, 1, 60)) then
		b = false
	end
	return b
end

function LM_NoisyPointAnimationDialog:OnOK()
	LM_NoisyPointAnimation.amplitude = self.amplitude:FloatValue()
	LM_NoisyPointAnimation.scale = self.scale:FloatValue()
	LM_NoisyPointAnimation.interval = self.interval:Value()
end

-- **************************************************
-- The guts of this script
-- **************************************************

function LM_NoisyPointAnimation:IsEnabled(moho)
--[syn]	if (moho:CountSelectedPoints() > 0) then
--[[syn]]	if (moho.document:CountSelectedLayers() > 1) or (moho:CountSelectedPoints() > 0) then
		return true
	else
		return false
	end
end

function LM_NoisyPointAnimation:Run(moho)
	local mesh = moho:Mesh()
	if (mesh == nil) then
		return
	end

	local dlog = LM_NoisyPointAnimationDialog:new(moho)
	if (dlog:DoModal() == LM.GUI.MSG_CANCEL) then
		return
	end

--[syn]	moho.document:PrepUndo(moho.layer)
--[[syn]]	moho.document:PrepMultiUndo()
	moho.document:SetDirty()

	local interp = MOHO.InterpSetting:new_local()
--syn\/
	local count = -1
	local origLayer = moho.layer
	repeat
		count = count + 1
		local layer = moho.document:LayerByAbsoluteID(count)
		local multiLayers = moho.document:CountSelectedLayers() > 1
		if (layer and layer:SecondarySelection() and layer:LayerType() == MOHO.LT_VECTOR) then
			mesh = moho:LayerAsVector(layer):Mesh()
--syn/\
	for ptID = mesh:CountPoints() - 1, 0, -1 do
		local pt = mesh:Point(ptID)
--[syn]		if (pt.fSelected) then
--[[syn]]		if (multiLayers) or (pt.fSelected) then
			for keyID = pt.fAnimPos:CountKeys() - 1, 0, -1 do
				pt.fAnimPos:GetKeyInterpByID(keyID, interp)
				interp.interpMode = MOHO.INTERP_NOISY
				interp.val1 = self.amplitude
				interp.val2 = 1.0 / self.scale
				interp.interval = self.interval
				pt.fAnimPos:SetKeyInterpByID(keyID, interp)
			end
		end
	end
--syn\/
		end
	until not layer
--syn/\
end
Yes! This works Great! Thanks Wes! I could only get it working as a Tool Script tho and not in the Menu but it is probably handier to have on the toolbar anyways =)
User avatar
8BitHobo
Posts: 12
Joined: Fri Jul 06, 2018 8:02 pm

Re: Request: Noisy Point Animation to Selected layers

Post by 8BitHobo »

Greenlaw wrote: Mon Nov 22, 2021 12:25 am I think you can get the same or similar displacement in the Layers Settings by using a low Offset, and high Scale value. For example, try 2 and 60 respectively. If you look at the preview window inside Layer Settings, it will show you what it will look like.

Basically, the low/high values displace the lines by a small distance but uses a larger fractal pattern so the jitter effect is broad and not so 'scribbly'...and similar to your second example.
oOo I'll Check this out also, can never have too many options to solve a problem!
Thanks!
User avatar
Greenlaw
Posts: 9269
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: Request: Noisy Point Animation to Selected layers

Post by Greenlaw »

Here are some examples of the Layer Settings method using different values. I think the last one is similar to what you're getting with Points.

Image
Last edited by Greenlaw on Mon Nov 22, 2021 1:25 am, edited 1 time in total.
User avatar
Greenlaw
Posts: 9269
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: Request: Noisy Point Animation to Selected layers

Post by Greenlaw »

That said, after doing this, I think the Layers method is a post effect applied to the rendered image because there aren't enough points in my acorn drawing to displace the way it looks in the really noisy versions. So, it's actually similar to what I described with using a compositing program for the effect.
User avatar
synthsin75
Posts: 9975
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Request: Noisy Point Animation to Selected layers

Post by synthsin75 »

8BitHobo wrote: Mon Nov 22, 2021 12:35 am I could only get it working as a Tool Script tho and not in the Menu but it is probably handier to have on the toolbar anyways =)
If you want to make sure it overrides the LM script, it needs to be in the Scripts>Animation folder.

Greenlaw wrote: Mon Nov 22, 2021 1:04 am Here are some example of the Layer Settings method using different values. I think the last one is similar to what you're getting with Points.

Image
I'd have to agree with 8BitHobo that noisy point motion has much more of that 8bit pulse look than vector line noise.
Daxel
Posts: 996
Joined: Wed Mar 27, 2019 8:34 pm

Re: Request: Noisy Point Animation to Selected layers

Post by Daxel »

Very informative post. Thanks for the examples, experiences and the script mod.

Yeah it looks like the difference is inevitable, because the script moves points, and that means that the curves produced along a specific line are nicely limited to the amount of points you used for that line. But the layer effect can take a straight line made just by two points and create any amount of curves along it, even if they are subtle. So the script effect somehow adapts to your drawing and I'm finding it very interesting.
chucky
Posts: 4650
Joined: Sun Jan 28, 2007 4:24 am

Re: Request: Noisy Point Animation to Selected layers

Post by chucky »

yes low offset and high scale, plus I mostly use a high step rate maybe even to 4s which looks less bubbly
Post Reply