// Samuel Roman // MARCH 13 2012 // CST 112 // Project 4 ////////////////////// ////|#declarations|\\\\ float centerX= width/2; float centerY= height/2; float samX=150; float samY=150; float samW=40; float samH=45; float positionW=(samX-centerX)/centerX; float positionH=(centerY-samY)/centerY; float sunX=100; float sunY=45; float sunC= 255; float gh=20; float gw=2; float gi=18; float speedSy; float speedSx; float distanceX; float distanceY; //////////////////////// void setup() { size(600, 480); smooth(); frameRate(30); } void draw() { float sunDX= 5; scene(); sam(); grass(); } void mousePressed() { // CLICK MOUSE TO RESPAWN SAM samX=150; samY=150; } void scene() { // BROWN GROUND noStroke(); background(191, 145, 19); fill(10, 10, 199); // BLUE SKY rect(0, 1, 600, 140); fill(sunC, sunC, 10); // YELLOW SUN ellipse(sunX, sunY, 65, 65); fill(0); text("Samuel Roman", 420, 30); text("TITLE: PROJECT 4 || Growing Grass", width/3, 20); } void sam() { // DECLARATIONS FOR CHARACTER "sam" distanceX=(mouseX-samX); distanceY=(mouseY-samY); speedSx = (2*distanceX /30); speedSy = (2*distanceY /30); samX+=speedSx; samY+=speedSy; centerX= width/2; centerY= height/2; noStroke(); charDisplay(samX, samY); // function to draw character } void charDisplay(float samX, float samY) { // Specifications of character noStroke(); float xx= samX; float yy= samY; float ww= samW; float hh= samH; fill(100, 50, 200); rect(xx, yy, ww, hh); ellipse(xx, yy, ww, hh); fill(255);// EYE SHAPE ellipse(xx-5, yy, ww/2, hh/2); ellipse(xx+5, yy, ww/2, hh/2); fill(0);// BLACK PUPILS ellipse(xx-5, yy, ww/4, hh/4); ellipse(xx+5, yy, ww/4, hh/4); } void grass() {//Declarations used for Grass centerX=width/2; centerY=height/2; positionW=(samX-centerX)/centerX; positionH=(centerY-samY)/centerY; // short hand Declaration. float c1= centerX; float p2= positionW; float c3= centerY; float p4= positionH; stroke(0, 255, 0);// GRASS COLOR strokeWeight(3); // GRASS THICKNESS for (float i=0;i<=width;i+=gi) { line(i, height, i+gh*p2, height-gh-p4*gh); } }