File: stream_test_rand.js

package info (click to toggle)
freej 0.10git20100110-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 32,080 kB
  • ctags: 22,705
  • sloc: cpp: 156,254; ansic: 25,531; sh: 13,538; perl: 4,624; makefile: 3,278; python: 2,889; objc: 1,284; asm: 1,125; ruby: 126
file content (125 lines) | stat: -rw-r--r-- 2,397 bytes parent folder | download
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// freej script to test randomness
// this also shows keyboard interactivity
// and smart use of function pointers
// (C)2005 Denis Jaromil Rojo - GNU GPL 

width =  400;
height = 300;
drawer = draw_triangles;

function draw_pixels(geo) {
  var x, y;

  x = rand()%width;
  y = rand()%height;

  if(x<0) x = -x;
  if(y<0) y = -y;

  geo.pixel(x,y);
}


function draw_triangles(geo) {
  var x1, x2, x3;
  var y1, y2, y3;

  x1 = rand()%width;
  x2 = rand()%width;
  x3 = rand()%width;
  y1 = rand()%height;
  y2 = rand()%height;
  y3 = rand()%height;

  if(x1<0) x1 = -x1;
  if(x2<0) x2 = -x2;
  if(x3<0) x3 = -x3;
  if(y1<0) y1 = -y1;
  if(y2<0) y2 = -y2;
  if(y3<0) y3 = -y3;

  geo.trigon_fill(x1,y1,x2,y2,x3,y3);
}


function draw_ellipses(geo) {
  var x, y;
  var rx, ry;

  x = rand()%width;
  y = rand()%height;
  rx = rand()%(width/2);
  ry = rand()%(height/2);

  if(x<0) x = -x;
  if(y<0) y = -y;
  if(rx<0) rx = -rx;
  if(ry<0) ry = -ry;

  geo.ellipse_fill(x, y, rx, ry);
}

function randomize_color(geo) {
  var r, g, b;

  r = rand() % 255;
  g = rand() % 255;
  b = rand() % 255;

  if(r<0) r = -r;
  if(g<0) g = -g;
  if(b<0) b = -b;

  geo.color(r,g,b,150); 
}

set_fps(10);

geo = new GeometryLayer(400,300);
geo.activate(true);
add_layer(geo);

try {
    txt = new TextLayer();
    txt.activate(true);
    txt.print("FreeJ 0.9 test stream");
    txt.set_position(20,10);
    txt.set_blit("add");
    add_layer(txt);
} catch(e) {
    echo("No text layer "+e);
}


bang = new TriggerController();
bang.frame = function() {
  randomize_color(geo);
  drawer(geo);
};
register_controller(bang);


kbd = new KeyboardController();
kbd.released_q = function() { quit(); };
kbd.released_p = function() { drawer = draw_pixels; };
kbd.released_t = function() { drawer = draw_triangles; };
kbd.released_e = function() { drawer = draw_ellipses; };
register_controller( kbd );

// create a video encoder object
//    values 1-100         video quality  video bitrate  audio quality  audio_bitrate
encoder = new VideoEncoder(10,             128000,        0,             0);


encoder.stream_host("video.dyne.org");
encoder.stream_port(8000);
encoder.stream_title("testing new freej");
encoder.stream_username("source");
encoder.stream_password("hackme");
encoder.stream_mountpoint("freej-test.ogg");


register_encoder(encoder);
encoder.start_stream();
//encoder.start_filesave("prova.ogg");