Wilbert
3rd February 2003, 11:22
If you are bored you can try the script below. It basically plots curves. You can define your own curves or use some predefined ones. I hope you like it. Oh, eh, if you move the slider in VdubMod it will take a while before you will see anything :)
_____
################
# curve_plot(clip clip, int x0, int x1, string mode, string "f_x", string "f_y", string "text", int "n")
# Plots a curve. The curve must be parametrized:
# x = f_x = f_x(t)
# y = f_y = f_y(t)
# and it is plotted from t=x0 to t=x1. There are a bunch of curves predefined (the mode option):
# "Descartes", "Lemniscate", "Cycloide", "Hypocycloide" ("Deltoide", "Astroide"), "Epicycloide" ("Cardiode", "Nefroide").
# Mode must be "user_defined" if you want to define and plot your own defined fuction.
# The option "text" shows a text message in the upper center of you screen. The option "n" is used in the curves
# Hypocloide and Epicycloide, and can be varied (1, 2, 3, ...).
#
# The origin is located at the center of the black background clip, the units are given in pixels.
################
# Adjust the height to 480 and fps 29.976 of "clip" for NTSC:
clip = BlankClip(length=3000, width=720, height=576, fps=25, pixel_type="YUY2", color=$000000).ConvertToRGB32 # a black clip
function axis(clip clip)
{
x_axis = clip.BlankClip(width=clip.width, height=2, pixel_type="YUY2", color=$0000ff).ConvertToRGB32
x_axis = clip.Layer(x_axis, "Add", 255, 0, round(-1+clip.height*0.5))
y_axis = clip.BlankClip(width=2, height=clip.height, pixel_type="YUY2", color=$0000ff).ConvertToRGB32
y_axis = x_axis.Layer(y_axis, "Add", 255, round(-1+clip.width*0.5), 0)
return y_axis
}
# parametrizations:
function Descartes_x(float t, int a)
{
t = 0.1*t
return 3*a*t/(1+Pow(t,3))
}
function Descartes_y(float t, int a)
{
t = 0.1*t
return 3*a*Pow(t,2)/(1+Pow(t,3))
}
function Lemniscate_x(float t, int a)
{
t = 0.1*t
return a*sqrt(2*cos(2*t))*cos(t)
}
function Lemniscate_y(float t, int a)
{
t = 0.1*t
return a*sqrt(2*cos(2*t))*sin(t)
}
function Cycloide_x(float t, int a)
{
t = 0.1*t
return a*(t+sin(t))
}
function Cycloide_y(float t, int a)
{
t = 0.1*t
return a*(1+cos(t))
}
function Hypocycloide_x(float t, int a, int n)
{
t = 0.1*t
R = n*a
return a*sin((1./a)*(R-a)*t) + (R-a)*sin(t)
}
function Hypocycloide_y(float t, int a, int n)
{
t = 0.1*t
R = n*a
return -a*cos((1./a)*(R-a)*t) + (R-a)*cos(t)
}
function Epicycloide_x(float t, int a, int n)
{
t = 0.1*t
R = n*a
return a*sin((1./a)*(R+a)*t) + (R+a)*sin(t)
}
function Epicycloide_y(float t, int a, int n)
{
t = 0.1*t
R = n*a
return a*cos((1./a)*(R+a)*t) + (R+a)*cos(t)
}
function Message(clip clip, string text)
{
return clip.Subtitle(text, y=0, align=8)
}
function g(clip clip, int t, string f_x, string f_y, int "n")
{
pix = clip.BlankClip(width=2, height=2, pixel_type="YUY2", color=$ff0000).ConvertToRGB32
pixel = clip.Layer(pix, "Add", 255, round(-1+clip.width*0.5+Eval(f_x)), round((clip.height*0.5-Eval(f_y)))-1)
return pixel.Mask(pixel.Greyscale.Levels(0, 1, 1, 0, 255))
}
function h(clip clip, int x0, int x1, string f_x, string f_y, int "n")
{
h = (x1>x0) ? clip.g(x1, f_x, f_y, n).h(x0, x1-1, f_x, f_y, n) : clip.g(x0, f_x, f_y, n)
return h
}
function curve_plot(clip clip, int x0, int x1, string mode, string "f_x", string "f_y", string "text", int "n")
{
message1 = (mode=="Hypocycloide" && n==3) ? "Deltoide" : (mode=="Hypocycloide" && n==4) ? "Astroide" : "Hypocycloide"
message2 = (mode=="Epicycloide" && n==1) ? "Cardiode" : (mode=="Epicycloide" && n==2) ? "Nefroide" : "Epicycloide"
mode = (mode=="Descartes") ? 0 : (mode=="Lemniscate") ? 1 : (mode=="Cycloide") ? 2 : (mode=="Hypocycloide") ? 3 :
\ (mode=="Epicycloide") ? 4 : (mode=="user_defined") ? 5 : -1
Assert(mode>=0, """curve_plot: "mode" parameter must be "Descartes", "Lemniscate", "Cycloide", "Hypocycloide", "Epicycloide" or "user_defined"""")
(Defined(n)==true) ? Assert((n>0), "Hypocycloide, Epicycloide: make sure that n>0") : 0
plot =
\ (mode==0) ? clip.axis.Message("Folium of Descartes: x^3 + y^3 - 3axy = 0").Layer(h(clip, x0, x1, "Descartes_x(t, 100)", "Descartes_y(t, 100)"), "Add", 255, 0, 0) :
\ (mode==1) ? clip.axis.Message("Lemniscate of Bernoulli: (x^2 + y^2)^2 = 2a^2(x^2 - y^2)").Layer(h(clip, x0, x1, "Lemniscate_x(t, 100)", "Lemniscate_y(t, 100)"), "Add", 255, 0, 0) :
\ (mode==2) ? clip.axis.Message("Cycloide: (a(t+sin(t)), a(1+cos(t)))").Layer(h(clip, x0, x1, "Cycloide_x(t, 25)", "Cycloide_y(t, 25)"), "Add", 255, 0, 0) :
\ (mode==3) ? clip.axis.Message(message1+": (a*sin((1/a)*(R-a)*t) + (R-a)*sin(t), a*cos((1/a)*(R-a)*t) + (R-a)*cos(t), R="+String(n)+"a").Layer(h(clip, x0, x1, "Hypocycloide_x(t, 50, n)", "Hypocycloide_y(t, 50, n)", n), "Add", 255, 0, 0) :
\ (mode==4) ? clip.axis.Message(message2+": (a*sin((1./a)*(R+a)*t) + (R+a)*sin(t), a*cos((1./a)*(R+a)*t) + (R+a)*cos(t)), R="+String(n)+"a").Layer(h(clip, x0, x1, "Epicycloide_x(t, 40, n)", "Epicycloide_y(t, 40, n)", n), "Add", 255, 0, 0) :
\ clip.axis.Message(text).Layer(h(clip, x0, x1, f_x, f_y), "Add", 255, 0, 0)
return plot
}
function id(int t)
{
return t
}
function c(int t)
{
return 50*sin(0.1*t)
}
# a bunch of examples:
# return curve_plot(clip, -100, 100, "user_defined", "id(t)", "c(t)", "(t, 50*sin(0.1*t))")
# return curve_plot(clip, -100, 100, "Descartes")
# return curve_plot(clip, -125, 125, "Lemniscate")
# return curve_plot(clip, -150, 150, "Cycloide")
# return curve_plot(clip, -150, 150, "Hypocycloide", n=3)
# return curve_plot(clip, -150, 150, "Hypocycloide", n=4)
# return curve_plot(clip, -150, 150, "Hypocycloide", n=5)
# return curve_plot(clip, -100, 100, "Epicycloide", n=1)
# return curve_plot(clip, -100, 100, "Epicycloide", n=2)
return curve_plot(clip, -100, 100, "Epicycloide", n=4)
_____
################
# curve_plot(clip clip, int x0, int x1, string mode, string "f_x", string "f_y", string "text", int "n")
# Plots a curve. The curve must be parametrized:
# x = f_x = f_x(t)
# y = f_y = f_y(t)
# and it is plotted from t=x0 to t=x1. There are a bunch of curves predefined (the mode option):
# "Descartes", "Lemniscate", "Cycloide", "Hypocycloide" ("Deltoide", "Astroide"), "Epicycloide" ("Cardiode", "Nefroide").
# Mode must be "user_defined" if you want to define and plot your own defined fuction.
# The option "text" shows a text message in the upper center of you screen. The option "n" is used in the curves
# Hypocloide and Epicycloide, and can be varied (1, 2, 3, ...).
#
# The origin is located at the center of the black background clip, the units are given in pixels.
################
# Adjust the height to 480 and fps 29.976 of "clip" for NTSC:
clip = BlankClip(length=3000, width=720, height=576, fps=25, pixel_type="YUY2", color=$000000).ConvertToRGB32 # a black clip
function axis(clip clip)
{
x_axis = clip.BlankClip(width=clip.width, height=2, pixel_type="YUY2", color=$0000ff).ConvertToRGB32
x_axis = clip.Layer(x_axis, "Add", 255, 0, round(-1+clip.height*0.5))
y_axis = clip.BlankClip(width=2, height=clip.height, pixel_type="YUY2", color=$0000ff).ConvertToRGB32
y_axis = x_axis.Layer(y_axis, "Add", 255, round(-1+clip.width*0.5), 0)
return y_axis
}
# parametrizations:
function Descartes_x(float t, int a)
{
t = 0.1*t
return 3*a*t/(1+Pow(t,3))
}
function Descartes_y(float t, int a)
{
t = 0.1*t
return 3*a*Pow(t,2)/(1+Pow(t,3))
}
function Lemniscate_x(float t, int a)
{
t = 0.1*t
return a*sqrt(2*cos(2*t))*cos(t)
}
function Lemniscate_y(float t, int a)
{
t = 0.1*t
return a*sqrt(2*cos(2*t))*sin(t)
}
function Cycloide_x(float t, int a)
{
t = 0.1*t
return a*(t+sin(t))
}
function Cycloide_y(float t, int a)
{
t = 0.1*t
return a*(1+cos(t))
}
function Hypocycloide_x(float t, int a, int n)
{
t = 0.1*t
R = n*a
return a*sin((1./a)*(R-a)*t) + (R-a)*sin(t)
}
function Hypocycloide_y(float t, int a, int n)
{
t = 0.1*t
R = n*a
return -a*cos((1./a)*(R-a)*t) + (R-a)*cos(t)
}
function Epicycloide_x(float t, int a, int n)
{
t = 0.1*t
R = n*a
return a*sin((1./a)*(R+a)*t) + (R+a)*sin(t)
}
function Epicycloide_y(float t, int a, int n)
{
t = 0.1*t
R = n*a
return a*cos((1./a)*(R+a)*t) + (R+a)*cos(t)
}
function Message(clip clip, string text)
{
return clip.Subtitle(text, y=0, align=8)
}
function g(clip clip, int t, string f_x, string f_y, int "n")
{
pix = clip.BlankClip(width=2, height=2, pixel_type="YUY2", color=$ff0000).ConvertToRGB32
pixel = clip.Layer(pix, "Add", 255, round(-1+clip.width*0.5+Eval(f_x)), round((clip.height*0.5-Eval(f_y)))-1)
return pixel.Mask(pixel.Greyscale.Levels(0, 1, 1, 0, 255))
}
function h(clip clip, int x0, int x1, string f_x, string f_y, int "n")
{
h = (x1>x0) ? clip.g(x1, f_x, f_y, n).h(x0, x1-1, f_x, f_y, n) : clip.g(x0, f_x, f_y, n)
return h
}
function curve_plot(clip clip, int x0, int x1, string mode, string "f_x", string "f_y", string "text", int "n")
{
message1 = (mode=="Hypocycloide" && n==3) ? "Deltoide" : (mode=="Hypocycloide" && n==4) ? "Astroide" : "Hypocycloide"
message2 = (mode=="Epicycloide" && n==1) ? "Cardiode" : (mode=="Epicycloide" && n==2) ? "Nefroide" : "Epicycloide"
mode = (mode=="Descartes") ? 0 : (mode=="Lemniscate") ? 1 : (mode=="Cycloide") ? 2 : (mode=="Hypocycloide") ? 3 :
\ (mode=="Epicycloide") ? 4 : (mode=="user_defined") ? 5 : -1
Assert(mode>=0, """curve_plot: "mode" parameter must be "Descartes", "Lemniscate", "Cycloide", "Hypocycloide", "Epicycloide" or "user_defined"""")
(Defined(n)==true) ? Assert((n>0), "Hypocycloide, Epicycloide: make sure that n>0") : 0
plot =
\ (mode==0) ? clip.axis.Message("Folium of Descartes: x^3 + y^3 - 3axy = 0").Layer(h(clip, x0, x1, "Descartes_x(t, 100)", "Descartes_y(t, 100)"), "Add", 255, 0, 0) :
\ (mode==1) ? clip.axis.Message("Lemniscate of Bernoulli: (x^2 + y^2)^2 = 2a^2(x^2 - y^2)").Layer(h(clip, x0, x1, "Lemniscate_x(t, 100)", "Lemniscate_y(t, 100)"), "Add", 255, 0, 0) :
\ (mode==2) ? clip.axis.Message("Cycloide: (a(t+sin(t)), a(1+cos(t)))").Layer(h(clip, x0, x1, "Cycloide_x(t, 25)", "Cycloide_y(t, 25)"), "Add", 255, 0, 0) :
\ (mode==3) ? clip.axis.Message(message1+": (a*sin((1/a)*(R-a)*t) + (R-a)*sin(t), a*cos((1/a)*(R-a)*t) + (R-a)*cos(t), R="+String(n)+"a").Layer(h(clip, x0, x1, "Hypocycloide_x(t, 50, n)", "Hypocycloide_y(t, 50, n)", n), "Add", 255, 0, 0) :
\ (mode==4) ? clip.axis.Message(message2+": (a*sin((1./a)*(R+a)*t) + (R+a)*sin(t), a*cos((1./a)*(R+a)*t) + (R+a)*cos(t)), R="+String(n)+"a").Layer(h(clip, x0, x1, "Epicycloide_x(t, 40, n)", "Epicycloide_y(t, 40, n)", n), "Add", 255, 0, 0) :
\ clip.axis.Message(text).Layer(h(clip, x0, x1, f_x, f_y), "Add", 255, 0, 0)
return plot
}
function id(int t)
{
return t
}
function c(int t)
{
return 50*sin(0.1*t)
}
# a bunch of examples:
# return curve_plot(clip, -100, 100, "user_defined", "id(t)", "c(t)", "(t, 50*sin(0.1*t))")
# return curve_plot(clip, -100, 100, "Descartes")
# return curve_plot(clip, -125, 125, "Lemniscate")
# return curve_plot(clip, -150, 150, "Cycloide")
# return curve_plot(clip, -150, 150, "Hypocycloide", n=3)
# return curve_plot(clip, -150, 150, "Hypocycloide", n=4)
# return curve_plot(clip, -150, 150, "Hypocycloide", n=5)
# return curve_plot(clip, -100, 100, "Epicycloide", n=1)
# return curve_plot(clip, -100, 100, "Epicycloide", n=2)
return curve_plot(clip, -100, 100, "Epicycloide", n=4)