/************************************************************ /* Author: Dr. Parson /* Creation Date: 9/14/2017 /* Due Date: 9/29/2017 /* Course: CSC120 Intro. to Creative Graphical Coding /* Professor Name: Dr. Parson /* Assignment: 1. /* Sketch name: avatar2017NoModulo /* Purpose: Animate an avatar using Processing. This is an example /* of my solution to assignment 1. /* Simplified version of avatar2017NoModulo that avoid the "%" operation. /* It must use pushMatrix(), translate(), and popMatrix() to /* position your avatar. You can pushMatrix-translate-popMatrix /* around your scenery items if you want; you may also use scale /* or totate if you like. I will give 1.5 bonus points for each of /* scale (1.5 points) and rotate (1.5 points) if you use them. /* Add a comment at the top if you use them. /* See textbook example 5-6 and 5-7 for bouncing ball & color examples. /* http://learningprocessing.com/examples/chp05/example-05-06-bouncingball /* http://learningprocessing.com/examples/chp05/example-05-07-bouncingcolor *********************************************************/ // Modeled after http://www.gradprofiles.com/images/kutzlib.gif // These variables can hold integers, i.e., whole numbers with no fractional parts. int backgroundColor = 0 ; // Bounces from 1 to 254 to 1 using backgroundColorSpeed. // backgroundColor flickers if I let it go < 0 or > 255, hence I am using range 1..254. int backgroundColorSpeed = 1 ; // Starts in a positve direction. int avatarX = 0 ; // Move the avatar left-right-left in cycles. int avatarXspeed = 1 ; // Initially move to the right. int legX = 0 ; // How far is leg from X endpoint, range -10 + 10. int legXspeed = 1 ; // go to 10, then reverse direction. // Also use 2 * lexG offset to wiggle arms up & down (in Y coordinate); // HIGHPOINTS OF MINE (not requirements): // 1. Use semi-transparency of grass and sky to pass through background light to dark, // which also cycles smoothly from day-night-day. backgroundColor used for both // background gray scale and tree red/green mix. void setup() { size(750, 500); background(backgroundColor); } void draw() { // Make the background cyclic through light & dark, no jumps. backgroundColor = backgroundColor + backgroundColorSpeed ; if (backgroundColor < 1 || backgroundColor > 254) { // It went out of range backgroundColorSpeed = - backgroundColorSpeed ; // reverse direction } background(backgroundColor); // PAINT BACKGROUND SCENERY. rectMode(CENTER); // Semi-transparent green grass uses the background's light-to-dark. fill(0, 100, 0, 100); rect(width/2, height*3/4, width, height/2); // Semi-transparent blue sky uses the background's light-to-dark. fill(0, 0, 100, 100); rect(width/2, height/4, width, height/2); // Create the building (library). fill(108, 57, 15); rect(width/2, height/4, width/2, height/3); rect(width/2, height/2-35, width, height/3); fill(100); rect(width/2, height/2, width*2/3, height/5); // Create poles leading into library, make one foreground later. strokeWeight(4); stroke(200); ellipseMode(CENTER); fill(255); line(width/3, height/3, width/3, height*2/3); line(width*2/3, height/3, width*2/3, height*2/3); arc(width/3, height/3, 40, 40, PI, 2*PI, PIE); arc(width*2/3, height/3, 40, 40, PI, 2*PI, PIE); // Make the next poll be the same distance further. int newx = (width/3 - width/4) + width/3 ; // Do the same for its height -- shrink by same amount. int newy = (height/3 - height/4) + height/3 ; line(newx, newy, newx, height-newy); line(width-newx, newy, width-newx, height-newy); arc(newx, newy, 30, 30, PI, 2*PI, PIE); arc(width-newx, newy, 30, 30, PI, 2*PI, PIE); // DRAW THE AVATAR // Fall 2017 USE GEOMETRIC TRANSFORMS TO POSITION THE PROFESSOR // All avatar-specific coordinates are relative to the translated center of the avatar. pushMatrix(); // After popmatrix() we can draw the foregorund scenery. translate(avatarX, height/2); // This is where to center the avatar. noStroke(); fill(240, 150, 150); ellipse(0, 0, 50, 40); // head quad(-5, 0, 5, 0, 10, 0+40, -10, 0+40); // neck fill(0); // professor gown ellipse(0, 0+60, 40, 80); // torso stroke(0); // stick arms & legs strokeWeight(8); line(0, 0+60, -20-abs(legX), 0+120); // left leg line(0, 0+60, 20+abs(legX), 0+120); // right leg strokeWeight(5); line(0, 0+60, -40, 0+20-2*abs(legX)); // left arm line(0, 0+60, 40, 0+20+2*abs(legX)); // right arm strokeWeight(2); fill(0, 50, 255); ellipse(-10, 0-5, 10, 10); // avatar's right side of glasses ellipse(10, 0-5, 10, 10); // avatar's right side of glasses line(-5, 0-5, 5, 0-5); // glasses connector line(-15, 0-5, -22, 0-8); // left earpiece line(15, 0-5, 22, 0-8); // right earpiece fill(0); ellipse(0, 0+1, 5, 5); // nose arc(0, 0+10, 20, 10, 0, PI); // mouth quad(-30, 0-15, 30, 0-15, 15, 0-30, -35, 0-30); // get ready for movement in next frame. avatarX = avatarX + avatarXspeed ; if (avatarX < 0 || avatarX > width) { // It went out of range avatarXspeed = - avatarXspeed ; // reverse direction } legX = legX + legXspeed ; if (legX < -10 || legX > 10) { // It went out of range legXspeed = - legXspeed ; // reverse direction } popMatrix(); // Restore the coordinates of the window with 0,0 at left,top. // END OF THE AVATAR /* move this to foreground */ // Create last pole leading into library. strokeWeight(6); stroke(200); ellipseMode(CENTER); fill(255); line(width/4, height/4, width/4, height*3/4); line(width*3/4, height/4, width*3/4, height*3/4); arc(width/4, height/4, 50, 50, PI, 2*PI, PIE); arc(width*3/4, height/4, 50, 50, PI, 2*PI, PIE); // fill(0, 100, 0) ; // dark green for some foreground trees fill(255 - abs(backgroundColor - 255), abs(backgroundColor - 255), 0); noStroke(); triangle(0, 0, 100, 180, 0, 180); triangle(0, 135, 100, 315, 0, 315); triangle(0, 270, 100, 450, 0, 450); fill(85, 73, 25); rectMode(CORNER); rect(0, 450, 20, height-450); // Put another tree on the right. // fill(0, 100, 0) ; // dark green for some foreground trees fill(255 - abs(backgroundColor - 255), abs(backgroundColor - 255), 0); noStroke(); triangle(width, 0, width-100, 180, width, 180); triangle(width, 135, width-100, 315, width, 315); triangle(width, 270, width-100, 450, width, 450); fill(85, 73, 25); rectMode(CORNER); rect(width-20, 450, width, height-450); }