View on GitHub

George Nelson Design

Computational Graphic - final project | Francesco Di Paolo 413937

Download this project as a .zip file Download this project as a tar.gz file

Util Functions

In this page are presented some util functions used to model the objects in Plasm.js and PyPlasm. The functions follow the same conventions of the PLaSM language: they have upper-case name and functional signature, with a single argument.

AAPOINTS

This function is similar to the PLaSM's AA function, but apply a function to a list of points.
var AAPOINTS = function(func){
	/*
	Apply a function to all points
	usage:
	AAPOINTS(func)(parameters)(points)
	e.g.: AAPOINTS(SUM)([1,.3,10])([[0,0,0],[1,0,3],[2,0,9]])
	*/
	return function(operands){ return function(args){ return AA(function(list){
		var res = [];
		for (var i = 0; i < list.length; i++)
			res.push(func([operands[i],list[i]]));
		return res;
	})(args);}}
};

MIRROR

This function mirror an object along an axis

var MIRROR = function (axis){
	/**
	 * reflect an object along an axis
	 */
	return function (obj) {return STRUCT([obj, S([axis])([-1])(obj)])}
};

DUPLIROT

This function duplicate and rotate an object

var DUPLIROT = function(axis){
	/*
	Rotate end create n copies of an hpc object.
	Usage: DUPLIROT([axis, axis])(angle)(object)(number)
	*/
	// In python it was a oneliner... :(
	return function(alpha){ return function(obj){ return function(n){
		var res = [];
		for (var i = 0; i < n; i++)
			res.push(R(axis)(alpha*i)(obj));
		console.log(res);
		return STRUCT(res);
	} } }
};

ROTATIONAL_SOLID

From a list of points it creates a rotational surface that pass through all the points.

var ROTATIONAL_SOLID = function(points){
	/*
	Similar to ROTATIONAL_SURFACE but takes points, not curves.
	*/
	return function(angle){ return function(divs){
		var domain = PROD1x1([INTERVALS(points.length-1)(points.length-1), INTERVALS(angle)(divs)]);
		var profile = function(x) { return points[x[0]];}
		return MAP(ROTATIONAL_SURFACE(profile))(domain);
	}}
};

TORUS

Maps a bidimensional domainto a toroidal surface.

var TORUS = function (R, r) {
	return function(v) {
		var a = v[0];
		var b = v[1];
		var u = (r * COS(a) + R) * COS(b);
		var v = (r * COS(a) + R) * SIN(b);
		var w = r * SIN(a);
		return [u, v, w];
	}
};

MKRECT

Given the absence of the PyPlasm's function MKPOL in Plasm.js, this function generate quads that can be assembled to create more complex shapes.

var MKRECT = function (points) {
	/**
	 * given four verts, create a rect
	 **/
	return MAP(BEZIER(S1)([BEZIER(S0)([points[0],points[1]]),BEZIER(S0)([points[2],points[3]])]))(PROD1x1([INTERVALS(1)(1), INTERVALS(1)(1)]));
};