Untitled

 avatar
unknown
plain_text
5 years ago
2.3 kB
8
Indexable
var values = {
	paths: 1110,
	minPoints: 5,
	maxPoints: 15,
	minRadius: 30,
	maxRadius: 90
};

var hitOptions = {
	segments: true,
	stroke: true,
	fill: true,
	tolerance: 5
};

var paths = [];
createPaths();

function createPaths() {
	var radiusDelta = values.maxRadius - values.minRadius;
	var pointsDelta = values.maxPoints - values.minPoints;
	for (var i = 0; i < values.paths; i++) {
		var radius = values.minRadius + Math.random() * radiusDelta;
		var points = values.minPoints + Math.floor(Math.random() * pointsDelta);
		var path = createBlob(view.size * Point.random(), radius, points);
		paths.push(path);
		var lightness = (Math.random() - 0.5) * 0.4 + 0.4;
		var hue = Math.random() * 360;
		path.fillColor = { hue: hue, saturation: 1, lightness: lightness };
		path.strokeColor = 'black';
	};
	
	for (var i = 0; i < values.paths; i+=3) {
	
		var myGr = new Group(paths[i],paths[i+1],paths[i+2]);
		
		paths[i].off('mouseenter')
		paths[i].off('mouseleave')
		paths[i].off('mousemove')
		paths[i].off('mousedrag')
		paths[i].off('click')
		paths[i].off('doubleclick')
		paths[i].off('frame')
//		paths[i].remove();
		
		paths[i+1].off('mouseenter')
		paths[i+1].off('mouseleave')
		paths[i+1].off('mousemove')
		paths[i+1].off('mousedrag')
		paths[i+1].off('click')
		paths[i+1].off('doubleclick')
		paths[i+1].off('frame')
	//	paths[i+1].remove()
		
		paths[i+2].off('mouseenter')
		paths[i+2].off('mouseleave')
		paths[i+2].off('mousemove')
		paths[i+2].off('mousedrag')
		paths[i+2].off('click')
		paths[i+2].off('doubleclick')
		paths[i+2].off('frame')
//		paths[i+2].remove()
		
		//paths[i+2].locked = true;
		
		myGr.children[0].locked = true;
		myGr.children[1].locked = true;
		//myGr.children[2].locked = true;
		
		myGr.on('mouseenter', function(){
			console.log('hey');
			this.selected = true;
		});
		
		myGr.on('mouseleave', function(){
			console.log('hey3');
			this.selected = false;
		});
		
		myGr.on('mousedrag', function(e){
			this.position += e.delta;
		});
		
		
	}
	
}

function createBlob(center, maxRadius, points) {
	var path = new Path();
	path.closed = true;
	for (var i = 0; i < points; i++) {
		var delta = new Point({
			length: (maxRadius * 0.5) + (Math.random() * maxRadius * 0.5),
			angle: (360 / points) * i
		});
		path.add(center + delta);
	}
	path.smooth();
	return path;
}
Editor is loading...