I am trying to make TPT render particles position from different formulas. For example, make particles follow a sine function, or a circle, to eventually use fractal functions.
I tried to loop x and y through a formula in the update function, but I found the following problem: whatever loop is in the update function, only the very end result gets rendered.
I tried nesting functions in whatever logic I could think of (having the update function within the loop function, having two udate functions, etc...), none of them working.
I also tried using the event.register(tick), but I end up with the same problem: only the end result of the update function gets rendered.
Any ideas, suggestions?
Marc
Hi jacob,
I tried the partProperty.tmp route, but I can ony paint on existing particles. I really need it to be a single particle that moves along a procedural path. I am now testing with simple sine or circle formulas.
I have not explored the graphics function route yet.
However I managed to grossly approximate what I want by using arrays to "port" position data across update function loops.
--edit: corrected the code. Now works.
For now, it is really cluncky and only draws only half a circle, but it is a proof of concept.
I would be happy if you would take a look.
--Initialize environnment variables
incr_array={}
increment=0.25
r=80 --radius
--
for a =-r, r, increment do
incr_array[#incr_array+1]=a
end
--
b=1 --Array pointer to be used in update loop
x_container={} --Array to store x values
y_container={} --Array to store y values
c=1 -- Array pointer to manage stored x and y values
d=0 -- Second hemisphere trigger
bb= (2 * r) / increment -- incr_array backwards pointer for second hemisphere
--
--Main update loop
local function M_OS_Update(i, x, y, ss, nt)
r=80
x_container[c]=x
y_container[c]=y
--
if bb==0 then -- Switch from second hemisphere to the first
d=0 bb=(2 * r) / increment
--print("if bb==0", "r=", r, increment, "bb=", bb, "incr_array[bb]=", incr_array[bb], "b=", b)
end
if incr_array[b]== nil then --Second hemisphere trigger
b=1 d=1
--print("if incr_array[b]== nil", "r=", r, increment, "bb=", bb, "incr_array[bb]=", incr_array[bb], "b=", b)
end
--
if d==0 then
--print("if d==0", "r=", r, increment, "bb=", bb, "incr_array[b]=", incr_array[b], "b=", b)
xpos = x_container[1] + incr_array[b]
ypos = y_container[1] + math.sqrt(math.abs(r^2 - (xpos-x_container[1])^2))
sim.partProperty(i, sim.FIELD_X, xpos)
sim.partProperty(i, sim.FIELD_Y, ypos)
b=b+1
end
if d==1 then
--print("if d==1", "r=", r, increment, "bb=", bb, "incr_array[bb]=", incr_array[bb], "b=", b)
xpos = x_container[1] + incr_array[bb]
ypos = y_container[1] - math.sqrt(math.abs(r^2 - (xpos-x_container[1])^2))
sim.partProperty(i, sim.FIELD_X, xpos)
sim.partProperty(i, sim.FIELD_Y, ypos)
bb=bb-1
end
c=c+1
end
elements.property(elem.MARKHUSS_PT_M_OS, "Update", M_OS_Update)