Liu Xiangqi-Project 10

I tried to make this project look like heartbeat pattern of a dying person. The person will die after a while.sketch

var pulses = [];
var initialX = 0;

function setup() {
    createCanvas(640, 400); 

    for (var i = 0; i < 10; i ++){
     pulses[i] = makePulses(width);
    }
    frameRate(10);
}


function draw() {
    background(0); 
    updateAndDisplayPulses();
    removePulsesThatHaveSlippedOutOfView();
    addNewPulsesWithSomeRandomProbability(); 
    
    
}


function updateAndDisplayPulses(){
    // Update the pulse's positions, and display them.
    for (var i = 0; i < pulses.length; i++){
        pulses[i].move();
        pulses[i].display();
    }
}


function removePulsesThatHaveSlippedOutOfView(){
    var pulsesToKeep = [];
    for (var i = 0; i < pulses.length; i++){
        if (pulses[i].x + pulses[i].breadth > 0) {
            pulsesToKeep.push(pulses[i]);
        }
    }
    pulses = pulsesToKeep; 
}


function addNewPulsesWithSomeRandomProbability() {
    // With a very tiny probability, add a new shape of pulse to the end.
    var newPulsesLikelihood = 0.007; 
    if (random(0,1) < newPulsesLikelihood) {
        pulses.push(makePulses(width));
    }
}


// method to update position of pulse every frame
function PulseMove() {
    this.x += this.speed;
}
    

// show the pulses 
function PulseDisplay() {
    var pulseWidth = 50;
    //when the frame count exceeds 250, the person is dead...
    if (frameCount < 200) {
        var quietWidth = random(width); 
    }else{
        var quietWidth = width;
    }
    stroke(244, 66, 66);
    strokeWeight(3);
    push();
    translate(this.x, 0);
    line(0, height/2, quietWidth, height/2);
    line(quietWidth, height/2, quietWidth+pulseWidth/2, height/2-this.pheight);
    line(quietWidth+pulseWidth/2, height/2-this.pheight, quietWidth+pulseWidth, height/2);
    stroke(0);
    line(quietWidth, height/2, quietWidth+pulseWidth, height/2);
    pop();
}


function makePulses(birthLocationX) {
    var pulse = {x: birthLocationX,
                breadth: 50,
                speed: -4.0,
                pheight: random(-150, 150),
                move: PulseMove,
                display: PulseDisplay,
                }
    return pulse;
}

function deathPulse(){
    stroke(244, 66, 66);
    strokeWeight(3);
    line(0, height/2, width, height/2);
}


1 thought on “Liu Xiangqi-Project 10”

Leave a Reply