File: scimage_animation.scd

package info (click to toggle)
supercollider 1%3A3.4.5-1wheezy1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 26,972 kB
  • sloc: cpp: 116,645; lisp: 64,914; ansic: 10,725; python: 3,548; perl: 766; ruby: 487; sh: 152; makefile: 117; xml: 13
file content (94 lines) | stat: -rw-r--r-- 1,979 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94

(
	// SCImage animation example - from a code of Tom Tlalim, adapted for SCImage by blackrain
	
	var w, h = 800, v = 600, seed = Date.seed, phase=0, phasef = 0.00125, zoom = 1, zoomf = 1.01, trans=0.1, run = true, i=0, amess, ind=0;
	var size = 100, mess, ordered;
	var image,
	
	export=false;		// <--- toggle to export frames

	w = Window("animation", Rect(40, 40, h, v));
	
	w.view.background_(Color.white);
	u = UserView.new(w, Rect(0, 0, h, v));
	w.front;

	// image preparation
	image =  SCImage.new(h@v);
	image.lockFocus;
	Color.black.set;
	Pen.fillRect(Rect(0,0,h,v));
	image.unlockFocus;

	mess = [{1.0.rand2}!200, {1.0.rand2}!200, {1.0.rand2}!200];
	size = mess[0].size;

	u.drawFunc = {
	
		image.drawAtPoint(0@0);
			
	};

	{
		while { run } {

		    phase = phase+phasef;
		    zoom = zoom*zoomf;
		    amess = mess;
		    
			//{
				image.lockFocus;
				
				    Pen.use {
				        Pen.color = Color.black.alpha_(0.1);
				        Pen.fillRect(Rect(0,0,h, v));
				        Pen.strokeColor = Color.grey(1,0.7);
				        (mess[0].size * (zoom*0.1).min(1)).do {
				            var x, y, z;
				            #x, y, z = [amess[0][i], amess[1][i],  amess[2][i]];
				            Pen.addRect(
				                Rect(
				                (x*0.5+1)*400, 
				                (z.neg*0.5+0.75)*400, 
				                (y.neg)*100 + (z*0.5 +1)*(zoom/5), 
				                (y.neg)*100  + (z*0.5+1)*(zoom/5)
				                )
				            );
				            i=(i+1)%((mess[0].size));
				        };

						Pen.stroke;
						
						i = (mess[0].size/(zoom));
					
					}; // End of Pen.use
				
				image.unlockFocus;				
				
				if(export, {
					image.write(Document.current.path.dirname ++ "/SavedImage_"++ind++".jpeg");
				});
			
			//}.bench; // bench to tune it 
		
			u.refresh;
			
			0.05.wait;
			
			ind=ind+1;
		}
		
	}.fork(AppClock);

	w.onClose_({
	
		run = false;
		{
			image.free;
		}.defer(0.3); // enough to release safely
	
	});
)