Project 07

sketch-mieep

var nPoints = 100;
var x = 1;

function setup() {
    createCanvas(480, 480);
    textSize(20);
    textAlign(CENTER, CENTER)
}

function draw() {
    background(0);
    noStroke();
//draws text on screen that changes with every mouse click
    if (x == 1) {
        fill(255, random(200), random(200), 220);
        text('我爱你', width/2, height/2);
    } else if (x == 2) {
        fill(255, random(200), random(200), 220);
        text('i love you', width/2, height/2);
    } else if (x == 3) {
        fill(255, random(200), random(200), 220);
        text('te amo', width/2, height/2);
    } else if (x == 4) {
        fill(255, random(200), random(200), 220);
        text('사랑해', width/2, height/2);
    } else if (x == 5) {
        fill(255, random(200), random(200), 220);
        text('愛してる', width/2, height/2);
    } else if (x == 6) {
        fill(255, random(200), random(200), 220);
        text('♡', width/2, height/2);
    }
//the code below this line starts drawing curves
//draws first curve/heart in top left corner
    fill(188, 0, 56, 200);
    drawEpitrochoidCurve();
//draws curve/heart in top right corner
    push();
    translate(width, 0);
    drawEpitrochoidCurve();
    pop();
//draws curve/heart in bottom left corner
    push();
    translate(0, height);
    drawEpitrochoidCurve();
    pop();
//draws curve/heart in bottom right corner
    push();
    translate(480, 480);
    drawEpitrochoidCurve();
    pop();
}

function mousePressed(){
    if (x == 1){
        x = 2;
    } else if (x == 2){
        x = 3;
    } else if (x == 3){
        x = 4;
    } else if (x == 4){
        x = 5;
    } else if (x == 5){
        x = 6;
    } else if (x == 6){
        x = 1;
    }
}

function drawEpitrochoidCurve() {
// Epicycloid:
 // http://mathworld.wolfram.com/Epicycloid.html
    var x;
    var y;
    var a = map(mouseX/3, 0, width, 0, 500);
    var b = a / 8;
    var h = constrain(mouseY / 8.0, 0, b);
    
    beginShape();
    for (var i = 0; i < nPoints; i++) {
        var t = map(i, 0, nPoints, 0, TWO_PI);
        x = (a + b) * cos(t) - h * cos(((a + b) / b) * t);
        y = (a + b) * sin(t) - h * sin(((a + b) / b) * t);
        vertex(x, y);
    }
    endShape();
}

Leave a Reply