<commit_before>// VCE Project - flash.js
//
// This script facilitates the simple modelling of a flash drum
//
// Requires:
// - p5.js or p5.min.js
// - vce_utils.js
//
// <NAME> 2017
// <EMAIL>
//----------------------------------------------------------

// --------------------------------------------------
//             visualisation functionality
// --------------------------------------------------
var img; // fash tank image object used by draw
var xmax;
var ymax;
var tops_particles = [];
var bottoms_particles = [];
var feed_particles = [];
var rpart = 2;
var img_shrink_factor = 0.60;
var testPart1;
var testPart2;
var paused_log = true;

function preload() {
    // preload the flash tank image
    URL = "http://visualchemeng.com/wp-content/uploads/2018/01/flash.svg";
    img = loadImage(URL, pic => print(pic), loadImgErrFix);
}

function setup() {
    
    /* This function is called upon entry to create the
       simulation canvas which we draw onto and run 
       a very simple flash unit test */
    
    var dimensions = getSimBoxDimensions();
    xmax = dimensions.xmax;
    ymax = dimensions.ymax;
    console.log("xmax=",xmax);
    console.log("ymax=",ymax);
    var canvas= createCanvas(xmax, ymax);
    canvas.parent("sim_container")
    var testInput = new Input(0.5, 390.0, [0.5,0.3,0.2], [1.685,0.742,0.532],20);
    var expectedOutput = new Output([0.33940869696634357, 0.3650560590371706, 0.2955352439964858],
				[0.5719036543882889, 0.27087159580558057, 0.15722474980613044],
				    13.814605255477089, 6.185394744522911);
    //img = loadImage("http://visualchemeng.com/wp-content/uploads/2018/01/flash.svg");
    test(testInput,expectedOutput);

    // draw the flash schematic to stream
    background(51);
    imageMode(CENTER);
    var sid = getImgScaledDimensions(img);
    image(img, xmax/2 , ymax/2, sid.width, sid.height);

    //initialise the particles
    var tops_pos = getTopsPosition(sid);
    var bottoms_pos = getBottonsPositions(sid);
    testPart1 = new Particle(tops_pos.x,tops_pos.y,rpart,1.0,2.0,0.0,null,createVector(0,-0.01));
    testPart2 = new Particle(bottoms_pos.x,bottoms_pos.y,rpart,1.0,2.0,0.0,null,createVector(0,0.01)); 

}

function draw() {

    /* Draws background and img to the canvas.
       This function is continuously called for the
       lifetime of the scripts executions after setup()
       has completed. */
    
    // draw the particle stream
    background(51);
    imageMode(CENTER);
    var sid = getImgScaledDimensions(img);
    image(img, xmax/2 , ymax/2, sid.width, sid.height);
    stroke(255);
    strokeWeight(1);
    testPart1.show();
    testPart2.show();

    // update the particle positions
    if (!(paused_log)) {
	testPart1.update(5.0);
	testPart2.update(5.0);
	if (!particleInSimBox(testPart1)) {
	    var tops_pos = getTopsPosition(sid);
	    testPart1 = new Particle(tops_pos.x,tops_pos.y,rpart,1.0,2.0,0.0,null,createVector(0,-0.01));
	};
	if (!particleInSimBox(testPart2)) {
	    var bottoms_pos = getBottonsPositions(sid);
	    testPart2 = new Particle(bottoms_pos.x,bottoms_pos.y,rpart,1.0,2.0,0.0,null,createVector(0,0.01)); 
	}   
    };
};

function getTopsPosition(sid) {
    
    // return the position of the tops exit as a p5 vector
    var tops_x = (xmax/2) + 0.5*sid.width;
    var tops_y = (ymax/2.0) - 0.475*sid.height;<commit_msg>Flash module: making particle streams support multiple particles<commit_after>// VCE Project - flash.js
//
// This script facilitates the simple modelling of a flash drum
//
// Requires:
// - p5.js or p5.min.js
// - vce_utils.js
//
// <NAME> 2017
// <EMAIL>
//----------------------------------------------------------

// --------------------------------------------------
//             visualisation functionality
// --------------------------------------------------
var img; // fash tank image object used by draw
var xmax;
var ymax;
var tops_particles = [];
var bottoms_particles = [];
var feed_particles = [];
var rpart = 2;
var img_shrink_factor = 0.60;
var testPart1;
var testPart2;
var paused_log = true;
var ndraws = 0;
var outlet_freq = 10;

function preload() {
    // preload the flash tank image
    URL = "http://visualchemeng.com/wp-content/uploads/2018/01/flash.svg";
    img = loadImage(URL, pic => print(pic), loadImgErrFix);
}

function setup() {
    
    /* This function is called upon entry to create the
       simulation canvas which we draw onto and run 
       a very simple flash unit test */
    
    var dimensions = getSimBoxDimensions();
    xmax = dimensions.xmax;
    ymax = dimensions.ymax;
    console.log("xmax=",xmax);
    console.log("ymax=",ymax);
    var canvas= createCanvas(xmax, ymax);
    canvas.parent("sim_container")
    var testInput = new Input(0.5, 390.0, [0.5,0.3,0.2], [1.685,0.742,0.532],20);
    var expectedOutput = new Output([0.33940869696634357, 0.3650560590371706, 0.2955352439964858],
				[0.5719036543882889, 0.27087159580558057, 0.15722474980613044],
				    13.814605255477089, 6.185394744522911);
    //img = loadImage("http://visualchemeng.com/wp-content/uploads/2018/01/flash.svg");
    test(testInput,expectedOutput);

    // draw the flash schematic to stream
    background(51);
    imageMode(CENTER);
    var sid = getImgScaledDimensions(img);
    image(img, xmax/2 , ymax/2, sid.width, sid.height);

    //initialise the particles
    // var tops_pos = getTopsPosition(sid);
    // var bottoms_pos = getBottonsPositions(sid);
    // testPart1 = new Particle(tops_pos.x,tops_pos.y,rpart,1.0,2.0,0.0,null,createVector(0,-0.01));
    // testPart2 = new Particle(bottoms_pos.x,bottoms_pos.y,rpart,1.0,2.0,0.0,null,createVector(0,0.01)); 

}

function draw() {

    /* Draws background and img to the canvas.
       This function is continuously called for the
       lifetime of the scripts executions after setup()
       has completed. */
    
    // draw the particle stream
    background(51);
    imageMode(CENTER);
    var sid = getImgScaledDimensions(img);
    image(img, xmax/2 , ymax/2, sid.width, sid.height);
    showAllParticles();

    
    // update particle streams
    if (!(paused_log)) {

	// update exisiting particle positions
	if (tops_particles.length !== 0 && bottoms_particles.length !== 0) {
	    updateAllParticles(0.5);
	    removeLostParticles();
	}

	// add new particles at desired freq
	if (ndraws % outlet_freq === 0) {
	    tops_pos = getTopsPosition(sid);
	    var new_tops_part = new Particle(tops_pos.x,tops_pos.y,rpart,1.0,2.0,0.0,null,createVector(0,-0.01));
	    tops_particles.push(new_tops_part);
	    var bottoms_pos = getBottonsPositions(sid);
	    var new_bottoms_part = 	new Particle(bottoms_pos.x,bottoms_pos.y,rpart,1.0,2.0,0.0,null,createVector(0,0.01));
	    bottoms_particles.push(new_bottoms_part);
	};
	ndraws = ndraws + 1;
	if (ndraws === 10000) {
	    ndraws = 0;
	}
    };
};

function showAllParticles() {

    // draw the particle to the canvas
    
    stroke(255);
    strokeWeight(1);
    for (i = 0; i < tops_particles.length; i++) {
	tops_particles[i].show();
    };
    for (i = 0; i < bottoms_particles.length; i++) {
	bottoms_particles[i].show();
    };
};

function updateAllParticles(dt) {

    //move all the particles forward in time by dt
    for (i = 0; i < tops_particles.length; i++) {
	tops_particles[i].update(dt);
    };
    for (i = 0; i < bottoms_particles.length; i++) {
	bottoms_particles[i].update(dt);
    };
};    

function removeLostParticles() {
       
    for (i = 0; i < tops_particles.length; i++) {
	if (!particleInSimBox(tops_particles[i])) {
	    tops_particles.splice(i,1);
	};
    };
    for (i = 0; i < bottoms_particles.length; i++) {
	if (!particleInSimBox(bottoms_particles[i])) {
	    bottoms_particles.splice(i,1);
	};
    };
};

function getTopsPosition(sid) {
    
    // return the position of the tops exit as a p5 vector
    var tops_x = (xmax/2) + 0.5*sid.width;
    var tops_y = (ymax/2.0) - 0.475*sid.height;
{'fraction_non_alphanumeric': 0.17524864660707543, 'fraction_numerical': 0.06785849175374543, 'mean_word_length': 2.715622076707203, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2321687', 'n_tokens_mistral': 3104, 'n_tokens_neox': 2798, 'n_words': 601}