Project 11 – Composition – Min Lee

index

var comb = 50;
var s = 25;
var bees = [];
var px = [];
var py = [];

function setup() {
    createCanvas(480, 480);

    //sets each bees position

    for (var i = 0; i < 10; i++) {
    	px.push(random(0, width));
    	py.push(random(0, height));
    };

}

function draw() {
	background(199, 149, 68);

    strokeJoin(MITER);
    strokeCap(PROJECT);

    //draws dark lines on hive
	var ttl1 = makeTurtle(0, -300)
	ttl1.setColor("black");
	ttl1.setWeight(5);
	for (var y = 0; y < 30; y++) {
		for (var i = 0; i < 15; i++) {
			ttl1.penDown();
			ttl1.forward(s);
			ttl1.right(60);
			ttl1.forward(s);
			ttl1.left(60);
		};
		ttl1.penUp();
		ttl1.goto(0, y * 50 * sqrt(3) / 2 - 300);
	};

	//draws thin lines on hive
	var ttl2 = makeTurtle(0, -302)
	ttl2.setColor("black");
	ttl2.setWeight(0.5);
	for (var y = 0; y < 30; y++) {
		for (var i = 0; i < 15; i++) {
			ttl2.penDown();
			ttl2.forward(s);
			ttl2.left(60);
			ttl2.forward(s);
			ttl2.right(60);
		};
		ttl2.penUp();
		ttl2.goto(0, y * 50 * sqrt(3) / 2 - 300);
	};

	strokeCap(ROUND)

	//creates bees
	for (var i = 0; i < 10; i++) {
		//moves bees randomly
		fill(0);
		ellipse(px[i], py[i], random(10, 15), random(10, 15))
		px[i] += random(-1, 1);
		py[i] += random(-1, 1);


		//if bees are too close to edges, keep them from going off canvas
		if (px < 1) {
			px += random(0, 1);
		} else if (px > width - 1) {
			px += random(-1, 0);
		};

		if (py < 1) {
			py += random(0, 1);
		} else if (py > height - 1) {
			py += random(-1, 0);
		};
	};
}



//------------------------------------------------

function turtleLeft(d) {
    this.angle -= d;
}
 
 
function turtleRight(d) {
    this.angle += d;
}
 
 
function turtleForward(p) {
    var rad = radians(this.angle);
    var newx = this.x + cos(rad) * p;
    var newy = this.y + sin(rad) * p;
    this.goto(newx, newy);
}
 
 
function turtleBack(p) {
    this.forward(-p);
}
 
 
function turtlePenDown() {
    this.penIsDown = true;
}
 
 
function turtlePenUp() {
    this.penIsDown = false;
}
 
 
function turtleGoTo(x, y) {
    if (this.penIsDown) {
      stroke(this.color);
      strokeWeight(this.weight);
      line(this.x, this.y, x, y);
    }
    this.x = x;
    this.y = y;
}
 
 
function turtleDistTo(x, y) {
    return sqrt(sq(this.x - x) + sq(this.y - y));
}
 
 
function turtleAngleTo(x, y) {
    var absAngle = degrees(atan2(y - this.y, x - this.x));
    var angle = ((absAngle - this.angle) + 360) % 360.0;
    return angle;
}
 
 
function turtleTurnToward(x, y, d) {
    var angle = this.angleTo(x, y);
    if (angle < 180) {
        this.angle += d;
    } else {
        this.angle -= d;
    }
}
 
 
function turtleSetColor(c) {
    this.color = c;
}
 
 
function turtleSetWeight(w) {
    this.weight = w;
}
 
 
function turtleFace(angle) {
    this.angle = angle;
}
 
 
function makeTurtle(tx, ty) {
    var turtle = {x: tx, y: ty,
                  angle: 0.0, 
                  penIsDown: true,
                  color: color(128),
                  weight: 1,
                  left: turtleLeft, right: turtleRight,
                  forward: turtleForward, back: turtleBack,
                  penDown: turtlePenDown, penUp: turtlePenUp,
                  goto: turtleGoTo, angleto: turtleAngleTo,
                  turnToward: turtleTurnToward,
                  distanceTo: turtleDistTo, angleTo: turtleAngleTo,
                  setColor: turtleSetColor, setWeight: turtleSetWeight,
                  face: turtleFace};
    return turtle;
}

For this project I wanted to recreate a beehive’s hexagons and add bees, but I unfortunately ran out of time so I simplified the bees.

An initial sketch behind the math I was trying to figure out.

Leave a Reply