Audrey Zheng-Project03

sketch

//Audrey Zheng
//Section A
//audreyz@andrew.cmu.edu
//Project 03

var cx = 0;
var cy = 0;
var radius = 150;
var blue = 40;

var vertices = 4;
var angle = 0;

var listvertices = new Array();
listvertices[0] = new Array(cx-radius, cy);
listvertices[1] = new Array(cx, cy-radius);
listvertices[2] = new Array(cx+radius, cy);
listvertices[3] = new Array(cx, cy+radius);


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

function wheel() {

    beginShape();
    for (i= 0; i <listvertices.length; i++) {
        for (j=0; j<listvertices.length; j++) {
            stroke(50,50,blue);
            line(listvertices[j][0], listvertices[j][1], listvertices[i][0], listvertices[i][1]);

        }
    }
    endShape(CLOSE);



} 


function mousePressed() {


}

function draw() {
    scale(0.8);
	background(255);

    text("p5.js test", 25, 15);

    push();
    translate(320,240);
    rotate(frameCount / 160.0);


    wheel();
    pop();

    //restrict mouseX from 0 to 255
    var m = max(min(mouseX, 255), 0);
    blue = m;

    stroke(50,50,blue);

    if ((mouseX > 320) & (frameCount%2 == 0) && (vertices <13)) { //do not let the points get infinitely bigger
        listvertices = [];
        vertices += 1;

        var j;
        var a = angle;
        for (j=1; j < vertices + 1; j++) {
            print("hi");
            a += 2* Math.PI/vertices; //2pi is whole circle in radians


            var newpoint = new Array(cx + radius*Math.cos(a), cy + radius*Math.sin(a));

            listvertices.push(newpoint);

        }   
    //print(listvertices);
    }

    if ((mouseX < 320) & (frameCount%2 == 0) && (vertices > 2)){
        listvertices = [];
        vertices -= 1;

        var k;
        var a = angle;
        for (k=1; k < vertices + 1; k++) {

            a += 2* Math.PI/vertices; //2pi is whole circle in radians


            var newpoint = new Array(cx + radius*Math.cos(a), cy + radius*Math.sin(a));

            listvertices.push(newpoint);

        }   
    //print(listvertices);
    }

    var size_of_each_line = max(min(mouseX, 230), 60);
    radius = size_of_each_line;



   
}

Leave a Reply