From 59156a7856279b13b47211412496e1e8a16ef84a Mon Sep 17 00:00:00 2001 From: mykedean Date: Thu, 10 Sep 2015 21:56:44 -0400 Subject: [PATCH] added Javascript externals and updated README --- Javascript/betadist.js | 76 ++++++++++++++++++++++++++++ Javascript/bounce.js | 94 +++++++++++++++++++++++++++++++++++ Javascript/gaussdist.js | 83 +++++++++++++++++++++++++++++++ Javascript/henon.js | 34 +++++++++++++ Javascript/jsreference.js | 101 ++++++++++++++++++++++++++++++++++++++ Javascript/lineardist.js | 68 +++++++++++++++++++++++++ Javascript/logistics.js | 49 ++++++++++++++++++ Javascript/mandelbrot.js | 54 ++++++++++++++++++++ Javascript/tinkerbell.js | 94 +++++++++++++++++++++++++++++++++++ Javascript/tridist.js | 58 ++++++++++++++++++++++ README.md | 2 - 11 files changed, 711 insertions(+), 2 deletions(-) create mode 100755 Javascript/betadist.js create mode 100755 Javascript/bounce.js create mode 100755 Javascript/gaussdist.js create mode 100755 Javascript/henon.js create mode 100755 Javascript/jsreference.js create mode 100755 Javascript/lineardist.js create mode 100755 Javascript/logistics.js create mode 100755 Javascript/mandelbrot.js create mode 100755 Javascript/tinkerbell.js create mode 100755 Javascript/tridist.js diff --git a/Javascript/betadist.js b/Javascript/betadist.js new file mode 100755 index 0000000..5315d8b --- /dev/null +++ b/Javascript/betadist.js @@ -0,0 +1,76 @@ +//Beta distribution generator - adapted from "Computer Music" by Dodge and Jerse +//--by Mike Dean + +//--GLOBAL------- +this.autowatch = 1; //automatically recompile everytime script is saved + +//declare number of inlets and outlets +inlets = 1; +outlets = 1; + +//-------------------------------------------- +//------------MAIN---------------------------- +//-------------------------------------------- +//function runs whenever a bang is received +function bang() { + var x = 0; + var y = 0; + var ainv = 1/second_arg(); + var binv = 1/third_arg(); + + //generate random numbers that are not 0 to avoid potential of underflow during exponentiation + while(x==0) { + x = Math.random(); + } + + while(y==0) { + y = Math.random(); + } + + //exponentiate + x = Math.pow(x,ainv); + y = Math.pow(y,binv); + + //add them together + var sum = x + y; + + //divide the first number by the sum + var result = x/sum; + + outlet(0, result*first_arg()); +} + +function first_arg() { + var range = 0; + + //define range + if (jsarguments[1] == undefined) { + range = 1; //set range automatically if no argument is given + } else { + range = jsarguments[1]; //otherwise, set resolution to first argument + } + + return range; +} + +function second_arg() { + //define a + if (jsarguments[2] == undefined) { + a = 0.5; //set a automatically if no argument is given + } else { + a = jsarguments[2]; //otherwise, set resolution to first argument + } + + return a; +} + +function third_arg() { + //define b + if (jsarguments[3] == undefined) { + b = 0.5; //set a automatically if no argument is given + } else { + b = jsarguments[3]; //otherwise, set resolution to first argument + } + + return b; +} \ No newline at end of file diff --git a/Javascript/bounce.js b/Javascript/bounce.js new file mode 100755 index 0000000..f79a524 --- /dev/null +++ b/Javascript/bounce.js @@ -0,0 +1,94 @@ +//---------------------------------------------------------------------------------- + +//OBJECT ATTRIBUTES +autocompile = 1; //compile on save + +//define number of inlets and outlets +inlets = 1; +outlets = 1; + +//GLOBALS +//define global variables +var tsk = new Task(repeatingBangs,this); //associate the tsk object with the repeatingBangs() function +var count = 0; +var decay = 1.0; +var dcoeff = -0.0002; // decay coefficient + +var polarity = 1; //direction of changing interval time +var count_dir = 1; //direction the counter is moving + +//argument defaults +var delay_time = 1000; + +//ARGUMENT HANDLING +// process arguments (decay coefficient, note to trigger) +if (jsarguments.length>1) { + delay_time = jsarguments[1]; +} + +if (jsarguments.length>2) { + dcoeff = jsarguments[2]; +} + +//------------ +//-FUNCTIONS- +//------------ +//reset the task everytime a bang is received +function bang() { + stop(); //cancel the task if it's already running + count = 0; + decay = 1.0; + tsk.interval = delay_time; //set the initial interval between bangs + tsk.repeat(); //repeat the task until canceled + +} + +//function associate with the task object +function repeatingBangs() { + outlet(0, 0); // send a 0 out the left outlet + + if(arguments.callee.task.interval<5 || arguments.callee.task.interval>delay_time) { + polarity = polarity*-1; + } + + if (count_dir>0) { + count++; + } else { + count--; + } + + if (count<1 || count>60 ) { + count_dir = count_dir*-1; //reverse directions + decay = 1.0; + } + + //post(count + "\n"); + + decay = decay*Math.exp(count*dcoeff); // increment the decay variable + + // update the task interval + if(polarity>0) { + + arguments.callee.task.interval=arguments.callee.task.interval*decay; + } else { + arguments.callee.task.interval=arguments.callee.task.interval/decay; + } +} + +//prevent triggering the task from anywhere other than this js object. ie. make function local/private +repeatingBangs.local = 1; + +//allow the user to cancel the process by sending the message 'stop' to the object +function stop() { + count = 0; + tsk.interval = delay_time; + tsk.cancel(); +} + +function msg_int(value) { + if (value==0) { + stop(); + } else if (value==1) { + bang(); + } +} \ No newline at end of file diff --git a/Javascript/gaussdist.js b/Javascript/gaussdist.js new file mode 100755 index 0000000..aa1371e --- /dev/null +++ b/Javascript/gaussdist.js @@ -0,0 +1,83 @@ +//Gaussian distribution generator - continuous domain +//--by Mike Dean + +//--DESCRIPTION-- +//Given two arguments, the object generates random numbers that conform to a Gaussian distribution probability density curve +//Argument 1 is the range that numbers are generated in. For example, if 100, numbers will be generated that occur between 0-99 +//Argument 2 is the total number of random numbers used to calculate the Gaussian distributed result. +// - A higher number will result in a more narrow curve centered around the mean. +// - A smaller number will result in a wider curve. +// - Less than 3 numbers cannot be used since 2 will result in a triangle distribution + +//--GLOBAL------- +this.autowatch = 1; //automatically recompile everytime script is saved + +//declare number of inlets and outlets +inlets = 1; +outlets = 1; + +//-------------------------------------------- +//------------MAIN---------------------------- +//-------------------------------------------- +//function runs whenever a bang message is received +function bang() { + var range = first_arg(); //range is the range that random numbers are generated between + var size = second_arg(); //size is the total number of random numbers generated to create a distributed result + var sumNumbers = 0; //the sum of all randomly generated numbers + var result = 0; //the result of the calculations + + //generate random numbers in the given range and sum them together + for (var i=0; i4) { + inSet = 0; //set to false + break; + } + zImag = 2*zReal*zImag + cImag; + zReal = zReal2 - zImag2 + cReal; + } + if(inSet==1) { + outlet(0, x,y); + } + } + } +} \ No newline at end of file diff --git a/Javascript/tinkerbell.js b/Javascript/tinkerbell.js new file mode 100755 index 0000000..b4de390 --- /dev/null +++ b/Javascript/tinkerbell.js @@ -0,0 +1,94 @@ +//programmed by Caitlin/Mike + +/* +xn+1 = xn^2 - yn^2 + a*xn + b*yn +yn+1 = 2xn*yn + c*xn + d*yn + +ynext => yn+1 +xnext => xn+1 + +Some commonly used values of a, b, c, and d are +a = 0.3, b = 0.6000, c =2, d = 0.27. +a = 0.9, b = -0.6013, c =2, d = 0.50. + +*/ + + +//------------ +//------GLOBAL +//------------ + +inlets = 2; +outlets = 2; +autowatch = 1; + +var x = -0.72; +var y = -0.64; +var a = 0.9; +var b = -.60; +var c = 2; +var d = 0.5; + +//------------ +//------FUNCTIONS +//------------ + +function bang() +{ + if (inlet==0) { + tinker_calc(); + } else if (inlet==1) { + //reset global values to initial condition + reset(); + } +} + +function tinker_calc() + { + //intialiaze values + var xnext=0; + var ynext=0; + + //calculate x value + xnext = x*x - y*y + a*x + b*y; + + //calculate y value + ynext = 2*x*y + c*x + d*y; + + //update last values + x = xnext; + y = ynext; + + //output results + outlet(0, xnext) + outlet(1, ynext); +} + +function set_a (a_val) +{ + a = a_val; +} + +function set_b (b_val) +{ + b = b_val; +} + +function set_c (c_val) +{ + c = c_val; +} + +function set_d (d_val) +{ + d = d_val; +} + +/* 1.what are the arguments and + 2.what does the function returns + + 3. what other functions does this affect */ +function reset() +{ + x = -0.72; + y = -0.64; +} \ No newline at end of file diff --git a/Javascript/tridist.js b/Javascript/tridist.js new file mode 100755 index 0000000..082f396 --- /dev/null +++ b/Javascript/tridist.js @@ -0,0 +1,58 @@ +//Triangle distribution generator - continuous domain +//--by Mike Dean + +//--DESCRIPTION-- +//Given one argument, the object generates random numbers that conform to a triangular distribution probability density curve +//Argument 1 is the range that numbers are generated in. For example, if 100, numbers will be generated that occur between 0-99 + +//--GLOBAL------- +this.autowatch = 1; //automatically recompile everytime script is saved + +//declare number of inlets and outlets +inlets = 1; +outlets = 1; + +//-------------------------------------------- +//------------MAIN---------------------------- +//-------------------------------------------- +//function runs whenever a bang message is received +function bang() { + var range = first_arg(); //range is the range that random numbers are generated between + var size = 2; //size is the total number of random numbers generated to create a distributed result + var sumNumbers = 0; //the sum of all randomly generated numbers + var result = 0; //the result of the calculations + + //generate random numbers in the given range and sum them together + for (var i=0; i