SCAnimationView user-definable view that animates


Inherits from: Object : SCView : SCUserView



SCAnimationView is a SCUserView that refreshes itself at a constant rate.

With thisProcess.setDeferredTaskInterval(1/fps) you can set the global framerate. The default is 60fps.



See also: GUI-Overview, SCWindow, Pen, Color, and String



Accessing Instance and Class Variables

drawFunc_(arg1)

drawFunc

This works the same as for SCUserView, except that it also sends an endless frame counter (Integer)

as the second argument to the arg1 function.

showInfo_(bool)

showInfo

Enable/disable the average frame rate calculations in the upper left corner.


Examples



//--

(

var width = 400, height = 400, mx = 0, my = 0;

var win = Window("drag mouse test", Rect(100, 200, width, height));

u = AnimationView(win, Rect(0, 0, width, height));

u.background = Color.black;

u.showInfo = true;

u.drawFunc = {|view, i|

Pen.color = Color.white;

Pen.moveTo(Point(my, mx));

100.do{|j|

var x = sin(i*0.04.neg+j)*(5*j)+mx;

var y = cos(i*0.05+j)*(5*j)+my;

Pen.lineTo(Point(y, x));

Pen.addOval(Rect(x, y, j, j));

};

Pen.fillStroke;

};

u.mouseDownAction = {|v, x, y|

mx = x;

my = y;

};

u.mouseMoveAction = u.mouseDownAction;

win.front;

)


u.showInfo = false

u.showInfo = true


//close the window to stop




//--

(

var width = 400, height = 400, xspeed = 3, yspeed = 2, x = width*0.5, y = height*0.5;

var win = Window("ball", Rect(100, 200, width, height));

u = AnimationView(win, Rect(0, 0, width, height));

u.background = Color.black;

u.showInfo = true;

u.drawFunc = {|view, i|

if(x<0 or:{x>width}, {xspeed = 0-xspeed});

if(y<0 or:{y>height}, {yspeed = 0-yspeed});

x = x+xspeed;

y = y+yspeed;

Pen.fillColor = Color.white;

Pen.fillOval(Rect.aboutPoint(Point(x, y), 8, 8));

};

//u.clearOnRefresh = false;

win.front;

)


( //replace the drawFunc above while running

u.drawFunc = {|view, i|

Pen.fillColor = Color.red;

Pen.fillOval(Rect(200, 200, sin(i*0.031)*200, sin(i*0.044)*200));

Pen.fillOval(Rect(200, 200, sin(i*0.052)*200, sin(i*0.065)*200));

Pen.fillOval(Rect(200, 200, sin(i*0.073)*200, sin(i*0.086)*200));

}

)


//close the window to stop




//--

(

var ani, cnt = 0, n = 30;

w = Window("circ", Rect(100, 200, 700, 400), false, false); //not resizable, no border

ani = AnimationView(w, Rect(0, 0, 700, 400));

ani.background= Color.black;

ani.drawFunc = {

Pen.fillColor = Color.blue;

Pen.strokeColor = Color.white;

n.do{|i|

//Pen.addOval(Rect(cnt*(i+1)%700, cnt/(i+1)%400, 50, 50));

//Pen.addOval(Rect(sin(cnt+i/5)*300+325, cnt/(i+1)%400, 50, 50));

Pen.addOval(Rect(sin(cnt+i/5)*150+350, cos(cnt-i/10)*150+200, 50, 50));

};

Pen.draw(3);

cnt = cnt+0.3;

};

w.front;

)


w.close; //to stop



//--

(

s.latency= 0.05;

s.waitForBoot{

var width = 400, height = 400, xspeed = 10, yspeed = 12, x = width*0.5, y = height*0.5, index;

var win = Window("ball", Rect(100, 200, width, height));

var syn = SynthDef(\ping, {|t_trig = 0, freq = 500|

var env = EnvGen.kr(Env.perc, t_trig);

var src = SinOsc.ar([freq, freq+10], 0, env);

Out.ar(0, src);

}).play(s);

s.sync;

index = 0;

u = AnimationView(win, Rect(0, 0, width, height));

u.background = Color.black;

u.showInfo = true;

//draw function that simply renders (stateless)...

u.drawFunc = {|view, i|

Pen.fillColor = Color.white;

Pen.fillOval(Rect.aboutPoint(Point(x, y), 8, 8));

Pen.stringAtPoint("framecounter  "+i, Point(250, 30));

Pen.stringAtPoint("routinecounter"+index, Point(250, 40));

};

//independent routine for the control...

r = Routine

var stretch;

stretch = Pseg(Pseq([0,1],inf), 10).linexp(0,1, 10, 0.5).asStream; // let's fiddle with the rate

inf.do { | i |

index = i;

if(x<0 or:{x>width}, {xspeed = 0-xspeed; syn.set(\t_trig, 1, \freq, 800)});

if(y<0 or:{y>height}, {yspeed = 0-yspeed; syn.set(\t_trig, 1, \freq, 500)});

x = x+xspeed;

y = y+yspeed;

(1/60 * stretch.next).wait

}

};

r.play(SystemClock);

win.onClose_({ r.stop; syn.free; });

win.front;

};

)