用Lu图形库Lu2D绘制(动态)函数图形

来源:互联网 发布:美国大选特朗普 知乎 编辑:程序博客网 时间:2024/06/05 03:22

 用Lu图形库Lu2D绘制(动态)函数图形

    图形库Lu2D32.dll主要包含一些绘制2D图形的函数。多线程动态绘制图形是Lu2D的基本特点。

    在Lu2D中的函数是通过二级函数命名空间“lu2d”输出的,所有函数均具有类似“lu2d::Plot(...)”的格式。使用!!!using("lu2d");可简化Lu2D中的函数访问。

    Lu2D中的Plot函数不仅可以绘制函数图形,而且可以绘制动画,当然要完整掌握Plot的用法需要较多的Lu脚本知识,这里只给出Plot函数的基础用法说明,详细说明参考:http://www.forcal.net/sysm/lu1/luhtm/lu2d.htm

    (1)Plot函数的简单用法

f(x)=sin[10*x];     //一元函数g(x)=x*sin[10*x];   //一元函数lu2d::Plot[@f, @g]; //绘制函数f和g的图形


图形:

    这种用法虽然简单,但需要通过菜单设置图形的属性,例如:X轴的范围、曲线的颜色等等。

    通过菜单只能设置图形的部分属性,以下的例子都是通过脚本设置图形属性的。

    (2)Iclear和Ix选项

!!!using("lu2d");   //使用命名空间lu2df(x)=sin[10*x];     //一元函数g(x)=x*sin[10*x];   //一元函数Plot[Iclear, Ix : -5.,5., @f, @g]; //绘制函数f和g的图形,Iclear将清除以前的设置(通常 要使用该参数),Ix指出X轴绘图范围


图形:

    (3)分步进行设置

!!!using("lu2d");   //使用命名空间lu2df(x)=sin[10*x];     //一元函数g(x)=x*sin[10*x];   //一元函数Plot[Iclear];       //Iclear将清除以前的设置 ,否则以前的设置会被本次图形绘制产生影响Plot[Ix : -5.,5.];  //Ix指出X轴绘图范围Plot[@f, @g];       //绘制函数f和g的图形


图形:

    (4)隐函数图形

!!!using("lu2d");f(x,y)=(x^2+y^2)^3-36*(x^2-y^2)^2;  //二元函数确定了一个隐函数Plot[Iclear, Ix : -8.,8., Igrid : true];  //Igrid指出是否绘制网格Plot[@f, Arange,-8.,8., Adots,200]; //Arange指出Y的可能的变化范围 ,通常不能省略该参数;Adot指出绘图点数,绘图点数越多越准确


友情提示:隐函数绘制时,调整Arange的范围大小有助于获得更准确的图形。

    图形:

    (5)绘制含参变量的函数

!!!using("lu2d");f(u,x,y)= x=u*sin[u],y=u*cos[u]^2;  //三元函数确定了一个含参变量的函数,第一个参数u是参变量,x和y的返回值确定了一个点lu2d::Plot[Iclear, Ix : -9.,9., @f, Arange,-9.,9.]; //Arange指出参变量u的变化范围


图形:

    (6)内部计时器控制演示动态图形

!!!using("lu2d","math");init(::A,B,max)= max=500, A=new[real_s, max], B=new[real_s, max];f(x,y,n,t:i,u,d,static,k:A,B,max)={    x=A,y=B,n=++k%(max+1), t=0.,    u=-9.,d=18./max,i=0,(i<n).while{        x[i]=u*sin[u], y[i]=u*cos[u]^2,        u=u+d, i++    },    true};Plot{Iclear, Ixdynamic : true, Itimer : true, 100,     Iiarray : @f,Adot,Ashape,Vdiamond,Acolor,Vred};


图形:

    (7)内部(计时器)控制的数组图形绘制,横轴动态更新

!!!using("lu2d","math");init(::A,B)= A=ra1[-9.5, -9, -7, -6.5, -5, -3, -2, -1.2, 0, 1.5, 2, 3, 5, 6, 7.7, 8, 8.2, 8.6, 9, 10],             B=ra1[5, -9, 7, 6.5, -5, -3, 12, 1.2, 0, 11.5, -9, -3, 5, -6, 7.7, -8, 5.2, -8.6, -9, 7];f(x,y,n,t:static,i:A,B)= x=A,y=B,n=++i%20;ff(x,y,n,t)= f(&x,&y,&n,&t);Plot{Iclear, Ixdynamic : true, Itimer : true, 1000,     Iiarray : @f,     Iiarray : @ff,Adot,Acolor,Vred};


图形:

    (8)内部计时器控制演示动态图形:旋轮线动画

!!!using("lu2d","math");init(::A,B,C,D,max)= max=200, A=new[real_s, max+1], B=new[real_s, max+1], C=new[real_s, max], D=new[real_s, max];f(x,y,n,t:i,u,d,static,k:A,B,max)={    x=A,y=B,n=[++k%(max+1)], t=0.,    u=0.,d=15./(max-1),i=0,(i<n).while{        x[i]=[u-sin(u)], y[i]=[1-cos(u)],        u=u+d, i++    },    x[i]=u, y[i]=1., n++,    true};g(x,y,n,t:i,u,d,static,k,v:C,D,max)={    x=C, y=D, n=max, t=0.,    if[1==[++k%(max+1)], v=0.],    u=0.,d=2*3.1416/(max-1),i=0,(i<n).while{        x[i]=v+cos(u), y[i]=1+sin(u),        u=u+d, i++    },    v=v+15./(max-1), true};Plot{Iclear, Ix : 0.,15., Iy : 0.,2., Iydynamic : false, Itimer : true, 100, Iaxisshape : Vaxisequal,     Iiarray : @f,Acolor,Vred,     Iiarray : @g,Acolor,Vblue};


图形:

原创粉丝点击