Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- autowatch = 1;
- outlets = 2;
- var m = mgraphics;
- m.init();
- m.relative_coords = 0;
- m.autofill = 0;
- m.redraw();
- var js_width = box.rect[2] - box.rect[0];
- var js_height = box.rect[3] - box.rect[1];
- var voice_max = 32;
- var voice_current = 1;
- var x = [];
- var y = [];
- var x_inc = [];
- var y_inc = [];
- var width = [];
- var rate = 6;
- var R = [];
- var G = [];
- var B = [];
- for (i = 0; i < voice_max; i++){
- x[i] = Math.random();
- y[i] = Math.random();
- x_inc[i] = Math.random() / js_width * rate;
- y_inc[i] = Math.random() / js_height * rate;
- R[i] = Math.random();
- G[i] = Math.random();
- B[i] = Math.random();
- if (x[i] > y[i]){
- width[i] = Math.random() * (1 - x[i]);
- }
- else if (x[i] < y[i]){
- width[i] = Math.random() * (1 - y[i]);
- }
- }
- function random(){
- for (i = 0; i < voice_max; i++){
- x[i] = Math.random();
- y[i] = Math.random();
- x_inc[i] = Math.random() / js_width * rate;
- y_inc[i] = Math.random() / js_height * rate;
- R[i] = Math.random();
- G[i] = Math.random();
- B[i] = Math.random();
- if (x[i] > y[i]){
- width[i] = Math.random() * (1 - x[i]);
- }
- else if (x[i] < y[i]){
- width[i] = Math.random() * (1 - y[i]);
- }
- }
- m.redraw();
- }
- function bang(){
- for (i = 0; i < voice_max; i++){
- x[i] += x_inc[i];
- y[i] += y_inc[i];
- if (x[i] < 0 || x[i] > 1 - width[i]){
- x_inc[i] *= -1;
- }
- if (y[i] < 0 || y[i] > 1- width[i]){
- y_inc[i] *= -1;
- }
- }
- for (i = 0; i < voice_current; i++){
- outlet(0, i, x[i], y[i]);
- if (x[i] < 0 || x[i] > 1 - width[i] || y[i] < 0 || y[i] > 1- width[i]){
- outlet(1, 'bang');
- }
- }
- m.redraw();
- }
- function voice(n){
- voice_current = n % 64;
- m.redraw();
- }
- function paint(){
- for (i = 0; i < voice_current; i++){
- m.set_source_rgba(R[i], G[i], B[i], 0.3); //ellipse fill
- m.ellipse(x[i] * js_width, y[i] * js_height, width[i] * js_width, width[i] * js_height);
- m.fill();
- m.set_source_rgba(1, 1, 1, 0.5); //ellipse stroke
- m.ellipse(x[i] * js_width, y[i] * js_height, width[i] * js_width, width[i] * js_height);
- m.stroke();
- m.set_source_rgba(1, 1, 1, 0.5); //up line
- m.move_to(js_width / 2, 0);
- m.line_to((x[i] + width[i] / 2) * js_width, y[i] * js_height);
- m.stroke();
- m.move_to(js_width / 2, js_height); // down line
- m.line_to((x[i] + width[i] / 2) * js_width, (y[i] + width[i]) * js_height);
- m.stroke();
- }
- }
- function onresize(x, y){
- js_width = x;
- js_height = y;
- m.redraw();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement