sihand – Project Week 07 – Crystallize

Crystallize

I really enjoyed playing around with the equations and variables. During the course of my experimentation, I discovered a few cool effects combining different curves, but they all looked too chaotic. In the end, I chose this one, which is more simple and resembles an interesting crystallizing effect. It consists of an array of spiky shapes, which are modifications of a deltoid equation, that accumulate as the mouse moves across the canvas.

Sihan – crystallize

//Sihan Dong
//sihand@andrew.cmu.edu
//Section B
//Project Week 07: curves

var nPoints = 30;

function setup() {
    createCanvas(600, 400);
}

function draw() {
	background(255, map(mouseX, 0, width, 0, 200), map(mouseY, 0, height, 0, 200));
	stroke(255);
    noFill();
    drawDA();
}

function drawDA() {
	translate(width/2, height/2);
	var x = [];//array of spiky curves
	var y = [];
	var xa;//variables of circular curve
	var ya;
	
//only draw curves when mouse is within canvas
	if (mouseX < width & mouseY < height) {

    beginShape();
    for (var i = 0; i < nPoints; i++) {
        var t = map(i, 0, nPoints, 0, TWO_PI);
        for(var j = 0; j < min(mouseX/50, width); j++) {
        	var a = map(mouseX, 0, width, 0, 150);
			var d = map(mouseY, 0, width, 5, 8*j);
		//spiky curve
        	x[j] = j*d*cos(t) + j*cos(j*t);
        	y[j] = j*d*sin(t) - j*sin(j*t);
    	//circular curve    
        	xa = a*cos(t);
        	ya = a*sin(t);

        	vertex(xa, ya);
        	vertex(x[j], y[j]);
    	}
    }
    endShape();
    print(d);
    print(mouseY);
	}
}


	

Leave a Reply