├── .gitattributes ├── 9781484236963.jpg ├── Appendix ├── .DS_Store ├── WallStreet2.html ├── fearlessGirls2 │ ├── .DS_Store │ ├── data │ │ ├── annikaWithFearlessGirl.jpg │ │ └── bull.jpg │ └── fearlessGirls2.pde ├── rainbowHelix.html └── rainboxHelix │ └── rainboxHelix.pde ├── Chapter_1 ├── .DS_Store ├── daddyLogo │ └── daddyLogo.pde ├── first0 │ ├── .DS_Store │ └── first0.pde ├── first1 │ └── first1.pde └── first2 │ └── first2.pde ├── Chapter_10 ├── .DS_Store ├── alhambra │ ├── .DS_Store │ ├── alhambra.pde │ └── data │ │ └── alhambra.jpg ├── alhambraShape │ ├── .DS_Store │ ├── alhambraShape.pde │ └── data │ │ ├── alhambra.jpg │ │ └── flag.png ├── annikaFrogFlowersMakeup │ ├── .DS_Store │ ├── annikaFrogFlowersMakeup.pde │ └── data │ │ ├── .DS_Store │ │ ├── AnnikaFlowers.JPG │ │ ├── AnnikaFrog.JPG │ │ └── AnnikaMakeup.jpg ├── annikaFrogFlowersMakeupFunny │ ├── .DS_Store │ ├── annikaFrogFlowersMakeupFunny.pde │ └── data │ │ ├── AnnikaFlowers.JPG │ │ ├── AnnikaFrog.JPG │ │ └── AnnikaMakeup.jpg ├── boxFillTest │ └── boxFillTest.pde ├── dreideladjust │ ├── .DS_Store │ ├── data │ │ ├── gimmel.jpeg │ │ ├── hay.jpeg │ │ ├── nun.jpeg │ │ └── shin.jpeg │ └── dreideladjust.pde ├── dreidelbase │ ├── .DS_Store │ ├── data │ │ ├── gimmel.jpeg │ │ ├── hay.jpeg │ │ ├── nun.jpeg │ │ └── shin.jpeg │ └── dreidelbase.pde ├── snowman │ └── snowman.pde ├── snowmanBox │ └── snowmanBox.pde └── solarsystem │ └── solarsystem.pde ├── Chapter_2 ├── .DS_Store ├── chapter2_PImageTest │ ├── .DS_Store │ ├── chapter2_PImageTest.pde │ └── data │ │ ├── braid.jpg │ │ └── smirk.JPG ├── coinflipImages │ ├── .DS_Store │ ├── coinflipImages.pde │ └── data │ │ ├── braid.jpg │ │ └── smirk.JPG └── mousePolygons │ └── mousePolygons.pde ├── Chapter_3 ├── .DS_Store ├── bouncingBalls │ └── bouncingBalls.pde ├── bouncingPentagon │ └── bouncingPentagon.pde ├── bouncingPolygons │ └── bouncingPolygons.pde └── bouncingball │ ├── .DS_Store │ └── bouncingball.pde ├── Chapter_4 ├── .DS_Store ├── bouncingPolygons │ └── bouncingPolygons.pde ├── classBouncingBalls │ └── classBouncingBalls.pde ├── classyBouncingThingsReverse │ ├── .DS_Store │ ├── classyBouncingThingsReverse.pde │ └── data │ │ ├── annikalook.jpg │ │ ├── annikalookright.jpg │ │ └── eigenharpHands.jpg ├── jigsaw2D │ ├── .DS_Store │ ├── data │ │ ├── cubaOldCar.jpg │ │ ├── cubaOldCarR.jpg │ │ └── grandcentralstation.jpg │ ├── jigsaw2D.pde │ └── sketch.properties └── makePathThenImageTravel │ ├── .DS_Store │ ├── data │ └── bikerchickWGrant.jpg │ └── makePathThenImageTravel.pde ├── Chapter_5 ├── .DS_Store ├── AnnikasInTree │ ├── .DS_Store │ ├── AnnikasInTree.pde │ └── data │ │ ├── .DS_Store │ │ ├── AnnikasInTree.jpg │ │ └── results.csv ├── jMeyerSlingshot │ ├── .DS_Store │ ├── data │ │ ├── chicken.gif │ │ └── feathers.gif │ └── jMeyerSlingshot.pde └── snake │ └── snake.pde ├── Chapter_6 ├── .DS_Store ├── hexagons │ └── hexagons.pde ├── imageFromWeb │ └── imageFromWeb.pde ├── imageFromWebErrorCheck │ └── imageFromWebErrorCheck.pde ├── imageFromWebErrorCheckBadURL │ └── imageFromWebErrorCheckBadURL.pde ├── imageFromWebErrorCheckBadURLtry │ └── imageFromWebErrorCheckBadURLtry.pde ├── userEntersURL │ └── userEntersURL.pde └── userEntersURLjustChangePicture1 │ └── userEntersURLjustChangePicture1.pde ├── Chapter_7 ├── .DS_Store ├── hangman │ ├── .DS_Store │ ├── data │ │ └── words.csv │ └── hangman.pde ├── makeCard │ ├── .DS_Store │ ├── Button.pde │ ├── data │ │ └── camera-shutter-click-01.wav │ ├── makeCard.pde │ └── snaps │ │ └── card2213.png ├── makeCardAsk │ ├── .DS_Store │ └── makeCardAsk.pde ├── showFonts │ └── showFonts.pde ├── wormsTakeSnapshot │ ├── .DS_Store │ ├── snaps │ │ ├── worms2056.png │ │ └── worms2924.png │ └── wormsTakeSnapshot.pde └── wormsTakeSnapshotErase │ ├── .DS_Store │ ├── snaps │ ├── worms2056.png │ ├── worms2331.png │ ├── worms2924.png │ └── worms3630.png │ └── wormsTakeSnapshotErase.pde ├── Chapter_8 ├── .DS_Store ├── collage6 │ ├── .DS_Store │ ├── collage6.pde │ ├── data │ │ ├── climbing.jpg │ │ ├── pigtails1.JPG │ │ └── snowman.MOV │ └── definitions.pde └── origamifish │ ├── .DS_Store │ ├── data │ ├── cleftlip.jpg │ ├── sink.mp4 │ ├── talk.mp4 │ ├── throat1.jpg │ └── throat2.jpg │ └── origamifish.pde ├── Chapter_9 ├── .DS_Store ├── hangman │ ├── .DS_Store │ ├── data │ │ └── words.csv │ └── hangman.pde └── hangmanButtons │ ├── .DS_Store │ ├── Button.pde │ ├── data │ └── words.csv │ └── hangmanButtons.pde ├── Contributing.md ├── LICENSE.txt ├── README.md └── Thumbs.db /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /9781484236963.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/9781484236963.jpg -------------------------------------------------------------------------------- /Appendix/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Appendix/.DS_Store -------------------------------------------------------------------------------- /Appendix/WallStreet2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Wall Street coin toss 4 | 8 | 9 | 10 | 11 | 12 |

13 | 14 | 15 |
16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Appendix/fearlessGirls2/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Appendix/fearlessGirls2/.DS_Store -------------------------------------------------------------------------------- /Appendix/fearlessGirls2/data/annikaWithFearlessGirl.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Appendix/fearlessGirls2/data/annikaWithFearlessGirl.jpg -------------------------------------------------------------------------------- /Appendix/fearlessGirls2/data/bull.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Appendix/fearlessGirls2/data/bull.jpg -------------------------------------------------------------------------------- /Appendix/fearlessGirls2/fearlessGirls2.pde: -------------------------------------------------------------------------------- 1 | //coin toss type of example showing photos 2 | //also reverts after set time period 3 | 4 | int lastChange; 5 | int limit = 3000; 6 | String msg = "Click anywhere for the bull or the fearless girl(s)."; 7 | 8 | PImage girls; 9 | PImage bull; 10 | 11 | 12 | void setup() { 13 | lastChange = millis(); 14 | size(1200,1200); 15 | girls = loadImage("annikaWithFearlessGirl.jpg"); 16 | background(255); 17 | bull = loadImage("bull.jpg"); 18 | fill(0); 19 | textSize(30); 20 | text(msg,100,100); 21 | 22 | } 23 | 24 | void draw() { 25 | if ((millis()-lastChange)>limit) { 26 | background(255); 27 | text(msg, 100, 100); 28 | } 29 | 30 | } 31 | 32 | void mouseClicked() { 33 | lastChange = millis(); 34 | background(255); 35 | if (random(1)>=.5) { 36 | image (girls,10,10); 37 | } 38 | else { 39 | image (bull,10,10); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /Appendix/rainbowHelix.html: -------------------------------------------------------------------------------- 1 | 2 | Rainbow helix 3 | 4 | 42 | 43 | Drag mouse or touch to rotate helix. 44 |
45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /Appendix/rainboxHelix/rainboxHelix.pde: -------------------------------------------------------------------------------- 1 | //collection of wedges drawn using beginShape and endShape representing a rainbox path. 2 | //helix constructing using 2 helices, each with its own radius, inner irad and outer orad 3 | //one layer of flat shapes drawn in 3D 4 | 5 | Wedge[] strip = {}; 6 | int multiples = 9; //multiples of rainbox segments 7 | color[] rainbowColors = { 8 | color(148,0,211), 9 | color(75,0,130), 10 | color(0,0,255), 11 | color(0,255,0), 12 | color(255,255,0), 13 | color(255,127,0), 14 | color(255,0,0) 15 | }; 16 | 17 | float rotx = 2.85; //used to support mouse dragging changing orientation 18 | float roty = 0.55; 19 | 20 | float a = 300; //radius of helix 21 | float b = -10; // step up for 1 turn 22 | float WedgeWidth = a*PI/(3*7); //3 complete rainbows per half a turn 23 | 24 | float tDelta = PI/21; //created to fit in 3 complete rainbows per half turn of helix 25 | float irad = a; 26 | float orad = a+WedgeWidth; 27 | 28 | void setup() { 29 | size(1000,800,P3D); 30 | 31 | float t = 0; //used for parameterized curves representing the two helix coordinates. 32 | 33 | for(int i = 0;izstart)&&(x==xstart)) { 33 | z--; 34 | translate(x,y,z);} 35 | else { if (xzend) {forward = false;}; 42 | } 43 | } 44 | fill(240,0,240); 45 | sphere(8); 46 | } 47 | void backwardtravel() { 48 | if ((z>zstart)&&(x>=xend)) { 49 | z--; 50 | translate(x,y,z);} 51 | else { if (x>xstart) { 52 | x--; 53 | translate(x,y,z); 54 | } 55 | else { z++; 56 | translate(x,y,z); 57 | if (z>zend) {forward = true;}; 58 | } 59 | } 60 | 61 | sphere(8); 62 | } -------------------------------------------------------------------------------- /Chapter_10/alhambra/data/alhambra.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_10/alhambra/data/alhambra.jpg -------------------------------------------------------------------------------- /Chapter_10/alhambraShape/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_10/alhambraShape/.DS_Store -------------------------------------------------------------------------------- /Chapter_10/alhambraShape/alhambraShape.pde: -------------------------------------------------------------------------------- 1 | PImage bg; 2 | float x,y,z; 3 | float xstart = 150; 4 | float xend = 330; 5 | float ylevel = 400; 6 | float zstart = -50; 7 | float zend = 450; 8 | boolean forward = true; 9 | float a=0; 10 | PShape ball; 11 | Boolean moving = true; 12 | String msg = "Press any key to stop or restart."; 13 | 14 | void setup() { 15 | size(500,740,P3D); 16 | noStroke(); 17 | sphereDetail(15); 18 | bg = loadImage("alhambra.jpg"); 19 | PImage design = loadImage("flag.png"); 20 | ball = createShape(SPHERE,10); 21 | ball.setTexture(design); 22 | background(bg); 23 | x = xstart; 24 | y = ylevel; 25 | z = zend; 26 | textSize(20); 27 | } 28 | 29 | void draw() { 30 | if (moving) { 31 | background(bg); 32 | fill(0); 33 | rect(0,700,500,40); 34 | fill(250,0,0); 35 | text(msg,100,720); 36 | lights(); 37 | 38 | if (forward) { 39 | forwardtravel(); 40 | } 41 | else { 42 | backwardtravel(); 43 | } 44 | } 45 | } 46 | 47 | void forwardtravel() { 48 | if ((z>zstart)&&(x==xstart)) { 49 | z--; 50 | rotateAndDraw(1); 51 | 52 | } 53 | else { if (xzend) {forward = false;}; 60 | } 61 | } 62 | } 63 | 64 | void backwardtravel() { 65 | if ((z>zstart)&&(x>=xend)) { 66 | z--; 67 | rotateAndDraw(4); 68 | } 69 | else { if (x>xstart) { 70 | x--; 71 | rotateAndDraw(5); 72 | } 73 | else { z++; 74 | rotateAndDraw(6); 75 | if (z>zend) {forward = true;}; 76 | } 77 | } 78 | } 79 | 80 | void rotateAndDraw(int p) { 81 | a=a+PI/10; 82 | translate(x,y,z); 83 | switch(p) { 84 | case 1: 85 | rotateX(a); 86 | break; 87 | case 2: 88 | rotateZ(a); 89 | break; 90 | case 3: 91 | rotateX(-a); 92 | break; 93 | case 4: 94 | rotateX(a); 95 | break; 96 | case 5: 97 | rotateZ(-a); 98 | break; 99 | case 6: 100 | rotateX(-a); 101 | break; 102 | } 103 | shape(ball); 104 | } 105 | 106 | void keyPressed() { 107 | moving = !moving; 108 | } -------------------------------------------------------------------------------- /Chapter_10/alhambraShape/data/alhambra.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_10/alhambraShape/data/alhambra.jpg -------------------------------------------------------------------------------- /Chapter_10/alhambraShape/data/flag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_10/alhambraShape/data/flag.png -------------------------------------------------------------------------------- /Chapter_10/annikaFrogFlowersMakeup/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_10/annikaFrogFlowersMakeup/.DS_Store -------------------------------------------------------------------------------- /Chapter_10/annikaFrogFlowersMakeup/annikaFrogFlowersMakeup.pde: -------------------------------------------------------------------------------- 1 | //from Processing documentation 2 | /* @pjs preload="AnnikaFrog.JPG,AnnikaFlowers.JPG,AnnikaMakeup.jpg"; 3 | */ 4 | PImage frog, flowers, makeup; 5 | float rotx = PI/4; 6 | float roty = PI/4; 7 | int last; 8 | int interval = 6000; //time alloted before cube rotates by itself 9 | 10 | void setup() { 11 | size(1000, 1000, P3D); 12 | frog = loadImage("AnnikaFrog.JPG"); 13 | flowers = loadImage("AnnikaFlowers.JPG"); 14 | makeup = loadImage("AnnikaMakeup.jpg"); 15 | textureMode(NORMAL); 16 | last = millis(); 17 | } 18 | 19 | void draw() { 20 | background(0); 21 | textSize(20); 22 | text("Drag using mouse anywhere on screen to rotate cube. If no action, cube will rotate by itself.",17,14); 23 | noStroke(); 24 | translate(width/2.0, height/2.0, -100); 25 | if ((millis()-last) > interval) { 26 | setRotation(); 27 | } 28 | rotateX(rotx); 29 | rotateY(roty); 30 | scale(200); 31 | TexturedCube(frog,flowers,makeup); 32 | } 33 | 34 | void setRotation() { 35 | rotx += PI/400; 36 | roty += PI/400; 37 | } 38 | 39 | void TexturedCube(PImage tex1, PImage tex2, PImage tex3) { 40 | beginShape(QUADS); 41 | texture(tex1); 42 | 43 | // modified code to use 3 images 44 | 45 | // +Z "front" face 46 | vertex(-1, -1, 1, 0, 0); 47 | vertex( 1, -1, 1, 1, 0); 48 | vertex( 1, 1, 1, 1, 1); 49 | vertex(-1, 1, 1, 0, 1); 50 | 51 | // -Z "back" face 52 | vertex( 1, -1, -1, 0, 0); 53 | vertex(-1, -1, -1, 1, 0); 54 | vertex(-1, 1, -1, 1, 1); 55 | vertex( 1, 1, -1, 0, 1); 56 | 57 | endShape(); 58 | 59 | beginShape(QUADS); 60 | texture(tex2); 61 | 62 | 63 | // -Y "top" face 64 | vertex(-1, -1, -1, 0, 0); 65 | vertex( 1, -1, -1, 1, 0); 66 | vertex( 1, -1, 1, 1, 1); 67 | vertex(-1, -1, 1, 0, 1); 68 | 69 | 70 | // +Y "bottom" face 71 | vertex(-1, 1, 1, 0, 0); 72 | vertex( 1, 1, 1, 1, 0); 73 | vertex( 1, 1, -1, 1, 1); 74 | vertex(-1, 1, -1, 0, 1); 75 | 76 | 77 | endShape(); 78 | 79 | beginShape(QUADS); 80 | texture(tex3); 81 | 82 | 83 | // -X "left" face 84 | vertex(-1, -1, -1, 0, 0); 85 | vertex(-1, -1, 1, 1, 0); 86 | vertex(-1, 1, 1, 1, 1); 87 | vertex(-1, 1, -1, 0, 1); 88 | 89 | 90 | // +X "right" face 91 | vertex( 1, -1, 1, 0, 0); 92 | vertex( 1, -1, -1, 1, 0); 93 | vertex( 1, 1, -1, 1, 1); 94 | vertex( 1, 1, 1, 0, 1); 95 | 96 | endShape(); 97 | } 98 | 99 | void mouseDragged() { 100 | float rate = 0.01; 101 | last = millis(); 102 | rotx += (pmouseY-mouseY) * rate; 103 | roty += (mouseX-pmouseX) * rate; 104 | } -------------------------------------------------------------------------------- /Chapter_10/annikaFrogFlowersMakeup/data/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_10/annikaFrogFlowersMakeup/data/.DS_Store -------------------------------------------------------------------------------- /Chapter_10/annikaFrogFlowersMakeup/data/AnnikaFlowers.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_10/annikaFrogFlowersMakeup/data/AnnikaFlowers.JPG -------------------------------------------------------------------------------- /Chapter_10/annikaFrogFlowersMakeup/data/AnnikaFrog.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_10/annikaFrogFlowersMakeup/data/AnnikaFrog.JPG -------------------------------------------------------------------------------- /Chapter_10/annikaFrogFlowersMakeup/data/AnnikaMakeup.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_10/annikaFrogFlowersMakeup/data/AnnikaMakeup.jpg -------------------------------------------------------------------------------- /Chapter_10/annikaFrogFlowersMakeupFunny/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_10/annikaFrogFlowersMakeupFunny/.DS_Store -------------------------------------------------------------------------------- /Chapter_10/annikaFrogFlowersMakeupFunny/annikaFrogFlowersMakeupFunny.pde: -------------------------------------------------------------------------------- 1 | //from Processing documentation 2 | /* @pjs preload="AnnikaFrog.JPG,AnnikaFlowers.JPG,AnnikaMakeup.jpg"; 3 | This is required to work with ProcessingJS 4 | */ 5 | PImage frog, flowers, makeup; 6 | float rotx = PI/4; 7 | float roty = PI/4; 8 | int last; 9 | int interval = 6000; //time alloted before cube rotates by itself 10 | 11 | void setup() { 12 | size(1000, 1000, P3D); 13 | frog = loadImage("AnnikaFrog.JPG"); 14 | flowers = loadImage("AnnikaFlowers.JPG"); 15 | makeup = loadImage("AnnikaMakeup.jpg"); 16 | textureMode(NORMAL); 17 | last = millis(); 18 | } 19 | 20 | void draw() { 21 | background(0); 22 | textSize(20); 23 | text("Drag using mouse anywhere on screen to rotate cube. If no action, cube will rotate by itself.",17,14); 24 | noStroke(); 25 | translate(width/2.0, height/2.0, -100); 26 | if ((millis()-last) > interval) { 27 | setRotation(); 28 | } 29 | rotateX(rotx); 30 | rotateY(roty); 31 | scale(200); 32 | TexturedCube(frog,flowers,makeup); 33 | } 34 | 35 | void setRotation() { 36 | rotx += PI/400; 37 | roty += PI/400; 38 | } 39 | 40 | void TexturedCube(PImage tex1, PImage tex2, PImage tex3) { 41 | beginShape(QUADS); 42 | texture(tex1); 43 | 44 | // modified code to use 3 images 45 | 46 | // +Z "front" face 47 | vertex(-1, -1, 1, 0, 0); 48 | vertex( 1, -1, 1, 1, 0); 49 | vertex( 1, 1, 1, 1, 1); 50 | vertex(-1, 1, 1, 0, 1); 51 | 52 | // -Z "back" face 53 | vertex( 1, -1, -1, 0, 0); 54 | vertex(-1, -1, -1, 1, 0); 55 | vertex(-1, 1, -1, 1, 1); 56 | vertex( 1, 1, -1, 0, 1); 57 | 58 | endShape(); 59 | 60 | beginShape(QUADS); 61 | texture(tex2); 62 | 63 | 64 | // -Y "top" face 65 | vertex(-1, -1, -1, 0, 0); 66 | vertex( 1, -1, -1, 1, 0); 67 | vertex( 1, -1, 1, 1, 1); 68 | vertex(-1, -1, 1, 0, 1); 69 | 70 | 71 | // +Y "bottom" face 72 | vertex(-1, 1, 1, 0, 0); 73 | vertex( 1, 1, 1, 1, 0); 74 | vertex( 1, 1, -1, 1, 1); 75 | vertex(-1, 1, -1, 0, 1); 76 | 77 | 78 | endShape(); 79 | 80 | beginShape(QUADS); 81 | texture(tex3); 82 | 83 | 84 | // -X "left" face 85 | vertex(-1, -1, -1, 0, 0); 86 | vertex(-1, -1, 1, 1, 0); 87 | vertex(-1, 1, 1, 1, 1); 88 | vertex(-1, 1, -1, 0, 1); 89 | 90 | 91 | // +X "right" face 92 | vertex( 1, -1, 1, 0, 0); 93 | vertex( 1, -1, -1, 1, 0); 94 | vertex( 1, 1, -1, 1, 1); 95 | vertex( 1, 1, 1, 0, 1); 96 | 97 | endShape(); 98 | } 99 | 100 | void mouseDragged() { 101 | float rate = 0.01; 102 | last = millis(); 103 | rotx += (pmouseY-mouseY) * rate; 104 | roty += (mouseX-pmouseX) * rate; 105 | } -------------------------------------------------------------------------------- /Chapter_10/annikaFrogFlowersMakeupFunny/data/AnnikaFlowers.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_10/annikaFrogFlowersMakeupFunny/data/AnnikaFlowers.JPG -------------------------------------------------------------------------------- /Chapter_10/annikaFrogFlowersMakeupFunny/data/AnnikaFrog.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_10/annikaFrogFlowersMakeupFunny/data/AnnikaFrog.JPG -------------------------------------------------------------------------------- /Chapter_10/annikaFrogFlowersMakeupFunny/data/AnnikaMakeup.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_10/annikaFrogFlowersMakeupFunny/data/AnnikaMakeup.jpg -------------------------------------------------------------------------------- /Chapter_10/boxFillTest/boxFillTest.pde: -------------------------------------------------------------------------------- 1 | //testing 2 | Boolean noFillB = true; 3 | void setup() { 4 | size(800,600,P3D); 5 | noFill(); 6 | } 7 | 8 | void draw() { 9 | background(200); 10 | translate(width/2,height/2,0); 11 | box(30); 12 | box(100,150,200); 13 | } 14 | 15 | void mouseDragged() { 16 | camera(mouseX, mouseY, (height/2.0) / tan(PI*30.0 / 180.0), width/2.0, height/2.0, 0, 0, 1, 0); 17 | } 18 | 19 | void keyPressed() { 20 | if (noFillB) { 21 | fill(255); 22 | noFillB = false; 23 | } 24 | else { 25 | noFill(); 26 | noFillB = true; 27 | } 28 | } -------------------------------------------------------------------------------- /Chapter_10/dreideladjust/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_10/dreideladjust/.DS_Store -------------------------------------------------------------------------------- /Chapter_10/dreideladjust/data/gimmel.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_10/dreideladjust/data/gimmel.jpeg -------------------------------------------------------------------------------- /Chapter_10/dreideladjust/data/hay.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_10/dreideladjust/data/hay.jpeg -------------------------------------------------------------------------------- /Chapter_10/dreideladjust/data/nun.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_10/dreideladjust/data/nun.jpeg -------------------------------------------------------------------------------- /Chapter_10/dreideladjust/data/shin.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_10/dreideladjust/data/shin.jpeg -------------------------------------------------------------------------------- /Chapter_10/dreideladjust/dreideladjust.pde: -------------------------------------------------------------------------------- 1 | // dreidel 2 | //use of texture to put images on spinning top 3 | //cylinder with facets for peg 4 | //spinning for random amount and does slow down 5 | //undocumented feature to restart spinning using any key 6 | //undocumented feature to rotate in 2 dimensions using mouse 7 | 8 | PImage hay, shin, gimmel, nun; 9 | float roty = 0; //amount to rotate around y axis 10 | // set by spin, mouseDragged 11 | float rotx = 0; //amount to rotate around x axis. Only set by mouseDragged 12 | 13 | int spinCount = 200 + int(random(100)); //initial setting, decremented in spin 14 | float delta = .09; //amount to change roty 15 | Boolean adjust = true; 16 | String[] msgs = { 17 | "Take half.", 18 | "Do nothing.", 19 | "Take all.", 20 | "Put in 1." 21 | }; 22 | void setup() { 23 | size(800,600,P3D); 24 | hay = loadImage("hay.jpeg"); 25 | shin = loadImage("shin.jpeg"); 26 | gimmel = loadImage("gimmel.jpeg"); 27 | nun = loadImage("nun.jpeg"); 28 | textureMode(NORMAL); 29 | frameRate(30); 30 | 31 | } 32 | void draw() { 33 | background(200); //erase screen 34 | spin(); //sets roty 35 | 36 | translate(width/2.0, height/2.0, -100); 37 | rotateX(rotx); 38 | rotateY(roty); 39 | scale(50); 40 | dreidelparts(hay,gimmel,nun,shin); 41 | } 42 | 43 | void spin() { //prepares variables for the rotation, to be done in draw 44 | spinCount--; 45 | 46 | if (spinCount>0) { 47 | 48 | 49 | roty=roty+delta; 50 | delta = .999*delta; //prepares for slowing down next iteration 51 | 52 | } 53 | else { 54 | float turns = roty / HALF_PI; //number of quarter turns 55 | int wturns = int(turns+.5); // round off to closest integer 56 | int ans = wturns % 4; 57 | String msg = msgs[ans]; 58 | if (adjust) { 59 | adjust = false; 60 | roty =wturns*HALF_PI; 61 | println(msg); 62 | 63 | } 64 | } 65 | } 66 | 67 | void keyPressed() { //re-start spinning 68 | roty=0; 69 | spinCount=200+int(random(100)); //200 frames plus random value of frames 70 | delta = .09; 71 | adjust = true; 72 | } 73 | 74 | void dreidelparts(PImage tex1, PImage tex2, PImage tex3, PImage tex4) { 75 | //cube part from https://processing.org/examples/texturecube.html 76 | fill(255,215,0); 77 | pushMatrix(); 78 | translate(0,-1,0); 79 | drawCylinder(24,.2,2.0); 80 | popMatrix(); 81 | 82 | noStroke(); 83 | beginShape(QUADS); 84 | texture(tex1); 85 | 86 | // modified code to use 4 images, not top and bot 87 | 88 | // +Z "front" face 89 | vertex(-1, -1, 1, 0, 0); 90 | vertex( 1, -1, 1, 1, 0); 91 | vertex( 1, 1, 1, 1, 1); 92 | vertex(-1, 1, 1, 0, 1); 93 | endShape(); 94 | 95 | beginShape(); 96 | texture(tex2); 97 | // -Z "back" face 98 | vertex( 1, -1, -1, 0, 0); 99 | vertex(-1, -1, -1, 1, 0); 100 | vertex(-1, 1, -1, 1, 1); 101 | vertex( 1, 1, -1, 0, 1); 102 | 103 | endShape(); 104 | 105 | 106 | beginShape(QUADS); 107 | texture(tex3); 108 | 109 | 110 | // -X "left" face 111 | vertex(-1, -1, -1, 0, 0); 112 | vertex(-1, -1, 1, 1, 0); 113 | vertex(-1, 1, 1, 1, 1); 114 | vertex(-1, 1, -1, 0, 1); 115 | endShape(); 116 | 117 | beginShape(); 118 | texture(tex4); 119 | 120 | // +X "right" face 121 | vertex( 1, -1, 1, 0, 0); 122 | vertex( 1, -1, -1, 1, 0); 123 | vertex( 1, 1, -1, 1, 1); 124 | vertex( 1, 1, 1, 0, 1); 125 | 126 | endShape(); 127 | //top 128 | fill(100,0,100); 129 | 130 | beginShape(); 131 | vertex(-1,-1,1); 132 | vertex(-1,-1,-1); 133 | vertex(1,-1,-1); 134 | vertex(1,-1,1); 135 | vertex(-1,-1,1); 136 | endShape(); 137 | fill(100,100,0); 138 | //bottom triangle from each of the 4 sides to center point 139 | beginShape(); 140 | vertex(-1,1,1); 141 | vertex(-1,1,-1); 142 | vertex(0,2,0); 143 | vertex(-1,1,1); 144 | endShape(CLOSE); 145 | fill(100,0,0); 146 | beginShape(); 147 | vertex(1,1,1); 148 | vertex(1,1,-1); 149 | vertex(0,2,0); 150 | vertex(1,1,1); 151 | endShape(CLOSE); 152 | 153 | fill(0,100,0); 154 | beginShape(); 155 | vertex(-1,1,-1); 156 | vertex(1,1,-1); 157 | vertex(0,2,0); 158 | vertex(-1,1,-1); 159 | endShape(CLOSE); 160 | 161 | fill(0,0,100); 162 | beginShape(); 163 | vertex(-1,1,1); 164 | vertex(1,1,1); 165 | vertex(0,2,0); 166 | vertex(-1,1,1); 167 | endShape(CLOSE); 168 | } 169 | 170 | 171 | //used for the peg at top. Invoked by dreidelparts 172 | //orientaion changed from online example to switch to y from z. 173 | //from Processing http://vormplus.be/blog/article/drawing-a-cylinder-with-processing 174 | // positioned to be at top of cube. 175 | void drawCylinder(int sides, float r, float h) 176 | { 177 | float angle = 360 / sides; 178 | float halfHeight = h / 2; 179 | // draw top shape 180 | 181 | beginShape(); 182 | for (int i = 0; i < sides; i++) { 183 | float x = cos( radians( i * angle ) ) * r; 184 | float z = sin( radians( i * angle ) ) * r; 185 | vertex( x, -halfHeight,z ); 186 | } 187 | endShape(CLOSE); 188 | 189 | // draw bottom shape 190 | beginShape(); 191 | for (int i = 0; i < sides; i++) { 192 | float x = cos( radians( i * angle ) ) * r; 193 | float z = sin( radians( i * angle ) ) * r; 194 | vertex( x, halfHeight,z ); 195 | } 196 | endShape(CLOSE); 197 | beginShape(TRIANGLE_STRIP); 198 | for (int i = 0; i < sides + 1; i++) { 199 | float x = cos( radians( i * angle ) ) * r; 200 | float z = sin( radians( i * angle ) ) * r; 201 | vertex( x, halfHeight, z); 202 | vertex( x, -halfHeight, z); 203 | } 204 | endShape(CLOSE); 205 | 206 | } 207 | 208 | 209 | 210 | //enhancement could be to let player know about the mouse and key features 211 | 212 | void mouseDragged() { 213 | float rate = 0.01; 214 | rotx += (pmouseY-mouseY) * rate; 215 | roty += (mouseX-pmouseX) * rate; 216 | } -------------------------------------------------------------------------------- /Chapter_10/dreidelbase/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_10/dreidelbase/.DS_Store -------------------------------------------------------------------------------- /Chapter_10/dreidelbase/data/gimmel.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_10/dreidelbase/data/gimmel.jpeg -------------------------------------------------------------------------------- /Chapter_10/dreidelbase/data/hay.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_10/dreidelbase/data/hay.jpeg -------------------------------------------------------------------------------- /Chapter_10/dreidelbase/data/nun.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_10/dreidelbase/data/nun.jpeg -------------------------------------------------------------------------------- /Chapter_10/dreidelbase/data/shin.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_10/dreidelbase/data/shin.jpeg -------------------------------------------------------------------------------- /Chapter_10/dreidelbase/dreidelbase.pde: -------------------------------------------------------------------------------- 1 | // dreidel base 2 | 3 | void setup() { 4 | size (600,600,P3D); 5 | translate(width/2, height/2,0); 6 | noStroke(); 7 | scale(100); 8 | fill(100,100,0); 9 | //bottom triangle from each of the 4 sides to center point 10 | beginShape(); 11 | vertex(-1,1,1); 12 | vertex(-1,1,-1); 13 | vertex(0,2,0); 14 | vertex(-1,1,1); 15 | endShape(CLOSE); 16 | fill(100,0,0); 17 | beginShape(); 18 | vertex(1,1,1); 19 | vertex(1,1,-1); 20 | vertex(0,2,0); 21 | vertex(1,1,1); 22 | endShape(CLOSE); 23 | 24 | fill(0,100,0); 25 | beginShape(); 26 | vertex(-1,1,-1); 27 | vertex(1,1,-1); 28 | vertex(0,2,0); 29 | vertex(-1,1,-1); 30 | endShape(CLOSE); 31 | 32 | fill(0,0,100); 33 | beginShape(); 34 | vertex(-1,1,1); 35 | vertex(1,1,1); 36 | vertex(0,2,0); 37 | vertex(-1,1,1); 38 | endShape(CLOSE); 39 | 40 | } -------------------------------------------------------------------------------- /Chapter_10/snowman/snowman.pde: -------------------------------------------------------------------------------- 1 | // snowman 2 | 3 | float firstRadius = 100; 4 | float secondRadius = firstRadius*2/3; 5 | float thirdRadius = secondRadius*2/3; 6 | 7 | void setup() { 8 | size(800,800,P3D); 9 | stroke(200); 10 | 11 | } 12 | 13 | void draw() { 14 | translate(width/2, height/2,0); 15 | sphere(firstRadius); 16 | translate(0,-firstRadius,0); 17 | sphere(secondRadius); 18 | translate(0,-secondRadius,0); 19 | sphere(thirdRadius); 20 | 21 | 22 | } -------------------------------------------------------------------------------- /Chapter_10/snowmanBox/snowmanBox.pde: -------------------------------------------------------------------------------- 1 | // snowman 2 | 3 | float firstRadius = 100; 4 | float secondRadius = firstRadius*2/3; 5 | float thirdRadius = secondRadius*2/3; 6 | 7 | void setup() { 8 | size(800,800,P3D); 9 | stroke(200); 10 | fill(255); 11 | 12 | } 13 | 14 | void draw() { 15 | pushMatrix(); 16 | translate(width/2, height/2,0); 17 | sphere(firstRadius); 18 | translate(0,-firstRadius,0); 19 | sphere(secondRadius); 20 | translate(0,-secondRadius,0); 21 | sphere(thirdRadius); 22 | popMatrix(); 23 | pushMatrix(); 24 | translate(width/2, height/2,0); 25 | translate(0,firstRadius*.75,0); 26 | fill(0,100,0); 27 | box(500,50,500); 28 | fill(255); 29 | popMatrix(); 30 | 31 | } -------------------------------------------------------------------------------- /Chapter_10/solarsystem/solarsystem.pde: -------------------------------------------------------------------------------- 1 | //solar system, based on (inspired by) Lauren Collishaw's final project though I did omit Pluto. 2 | //planaets rotate in a circular orbit around the sun. (These orbits actually are elliptical, though very close to a circle.) 3 | //The sizes and the distances are not proportional. 4 | 5 | //Note the use of pushMatrix and popMatrix. This prevents cumulative effects of transformations. 6 | 7 | int mercury = 0; 8 | int venus = 1; 9 | int earth=2; 10 | int mars=3; 11 | int jupiter=4; 12 | int saturn=5; 13 | int uranus=6; 14 | int neptune=7; 15 | int pluto=8; 16 | Planet[] planets = new Planet[9]; 17 | //orbits are not circles, but do circles for now 18 | int ctrx = 600; 19 | int ctry = 500; 20 | int ctrz = -200; 21 | float time = 0; 22 | //float ptilt = -PI * 17/180; //tilt of plane of Pluto, actual tilt is 17 degrees 23 | float ptilt = -PI/6; //pretend tilt of 30 degrees 24 | 25 | 26 | 27 | void setup() { 28 | size(2500,1000,P3D); 29 | planets[mercury] = new Planet(color(63,67,250),30,350,.2); 30 | planets[venus] = new Planet(color(133,14,170),75,670,0.15); 31 | planets[earth] = new Planet(color(69,140,229),79,920,.12); //squeeze 32 | planets[mars] = new Planet(color(255,0,0),42,1000,0.1); //red planet 33 | planets[jupiter] = new Planet(color(237,175,41),89,1300,.08); 34 | planets[saturn] = new Planet(color(115,41,237),75,1600,0.06); 35 | planets[uranus] = new Planet(color(225,232,54),32,1800,.05); 36 | planets[neptune] = new Planet(color(54,186,255),25,1999,0.05); 37 | 38 | planets[pluto] = new ObPlanet(color(0,200,250),20, 2059,.035,ptilt); //tilted orbit 39 | frameRate(20); 40 | } 41 | void draw() { 42 | background(0); 43 | //directionalLight(800,-500,-500,1,1,1); //Lauren had two lights. This might be a good effect 44 | directionalLight(900, 500, 500,-1, -1, -1); 45 | //sun 46 | fill(245,198,25); 47 | pushMatrix(); 48 | translate(ctrx,ctry,ctrz); 49 | sphere(180); 50 | popMatrix(); 51 | // planets 52 | for(int i=0;i limit) { choices = 3;} 21 | 22 | } 23 | 24 | void polygon(float x, float y, float w, int n) 25 | { 26 | float angle = TWO_PI / n; 27 | float rad = w/2; 28 | for (int i=0;i=width)||(bxs[i]<=0)) {dxs[i] = -dxs[i];} 20 | bys[i] = bys[i] + dys[i]; 21 | if ((bys[i]>=height)||(bys[i]<=0)) {dys[i] = -dys[i];} 22 | } 23 | } -------------------------------------------------------------------------------- /Chapter_3/bouncingPentagon/bouncingPentagon.pde: -------------------------------------------------------------------------------- 1 | //bouncing ball 2 | float bx,by,dx,dy; 3 | int balldiam = 100; 4 | 5 | void setup() { 6 | size(800,600); 7 | bx = width/2; 8 | by = height/2; 9 | dx = 1; 10 | dy = 2; 11 | stroke(255); 12 | } 13 | 14 | void draw(){ 15 | background(0); //erase window 16 | polygon(bx,by,balldiam,5); 17 | bx = bx+dx; 18 | if ((bx>=width)||(bx<=0)) 19 | {dx = -dx;} 20 | by = by + dy; 21 | if ((by>=height)||(by<=0)) 22 | {dy = -dy;} 23 | } 24 | 25 | void polygon(float x, float y, float w, int n) 26 | { 27 | float angle = TWO_PI / n; 28 | float rad = w/2; 29 | for (int i=0;i=width)||(bx<=0)) 19 | {dx = -dx;} 20 | by = by + dy; 21 | if ((by>=height)||(by<=0)) 22 | {dy = -dy;} 23 | } 24 | 25 | void polygon(float x, float y, float w, int n) 26 | { 27 | float angle = TWO_PI / n; 28 | float rad = w/2; 29 | for (int i=0;i=width)||(bx<=0)) 18 | {dx = -dx;} 19 | by = by + dy; 20 | if ((by>=height)||(by<=0)) 21 | {dy = -dy;} 22 | } -------------------------------------------------------------------------------- /Chapter_4/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_4/.DS_Store -------------------------------------------------------------------------------- /Chapter_4/bouncingPolygons/bouncingPolygons.pde: -------------------------------------------------------------------------------- 1 | float bx,by,dx,dy; 2 | int balldiam = 100; 3 | int nsides = 5; 4 | 5 | void setup() { 6 | size(800,600); 7 | bx = width/2; 8 | by = height/2; 9 | dx = 1; 10 | dy = 2; 11 | stroke(255); 12 | } 13 | 14 | void draw(){ 15 | background(0); 16 | polygon(bx,by,balldiam,nsides); 17 | bx = bx+dx; 18 | if ((bx>=width)||(bx<=0)) 19 | {dx = -dx;} 20 | by = by + dy; 21 | if ((by>=height)||(by<=0)) 22 | {dy = -dy;} 23 | } 24 | 25 | void polygon(float x, float y, float w, int n) 26 | { 27 | float angle = TWO_PI / n; 28 | float rad = w/2; 29 | for (int i=0;i=width) || (bx<=0)) {dx = -dx;} 39 | if ((by>=height) || (by<=0)) {dy = -dy;} 40 | } 41 | } -------------------------------------------------------------------------------- /Chapter_4/classyBouncingThingsReverse/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_4/classyBouncingThingsReverse/.DS_Store -------------------------------------------------------------------------------- /Chapter_4/classyBouncingThingsReverse/classyBouncingThingsReverse.pde: -------------------------------------------------------------------------------- 1 | //classy bouncing things, reverse 2 | 3 | Thing[] things = {}; 4 | 5 | void setup() { 6 | things = (Thing[]) append(things,new Ball(width/2,width/2,3,3,20)); 7 | things = (Thing[]) append(things,new Box(width/4,width/3,2,1,40,57)); 8 | things = (Thing[]) append(things,new Picture(width/5,width*.6,2,3,120,100,"annikalookright.jpg","annikalook.jpg")); 9 | things = (Thing[]) append(things,new Ball(width*.75,width/6,1,2,60)); 10 | 11 | size (900,600); 12 | 13 | } 14 | void draw(){ 15 | background(0); //erase window 16 | for (int i=0;i=width) || (bx<=0)) {dx = -dx;} //might consider comparing bx+wdiam 44 | if ((by>=height) || (by<=0)) {dy = -dy;} //might consider comparing by+hdiam 45 | } 46 | void show() { 47 | // will be overridden by inherited objects 48 | } 49 | } 50 | class Ball extends Thing { 51 | // no new variables 52 | Ball (float x, float y, float vx, float vy, int diam) { 53 | super(x,y,vx,vy,diam,diam); //wdiam and hdiam set the same 54 | } 55 | void show(){ 56 | ellipse(bx,by,wdiam,hdiam); 57 | } 58 | } 59 | class Box extends Thing { 60 | // no new variables 61 | Box (float x, float y, float vx, float vy, int w, int h) { 62 | super(x,y,vx,vy,w,h); 63 | } 64 | void show(){ 65 | rect(bx,by,wdiam,hdiam); 66 | } 67 | } 68 | class Picture extends Thing { 69 | PImage pic; 70 | PImage picR; 71 | Picture (float x, float y, float vx, float vy, int w, int h, String imagefilename, String imagefilenameR) 72 | { 73 | super(x,y,vx,vy,w,h); 74 | pic = loadImage(imagefilename); 75 | picR = loadImage(imagefilenameR); 76 | } 77 | void show() { 78 | if (dx>0) { 79 | image(pic,bx,by,wdiam,hdiam);} 80 | else { 81 | image(picR,bx,by,wdiam,hdiam); 82 | } 83 | } 84 | } -------------------------------------------------------------------------------- /Chapter_4/classyBouncingThingsReverse/data/annikalook.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_4/classyBouncingThingsReverse/data/annikalook.jpg -------------------------------------------------------------------------------- /Chapter_4/classyBouncingThingsReverse/data/annikalookright.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_4/classyBouncingThingsReverse/data/annikalookright.jpg -------------------------------------------------------------------------------- /Chapter_4/classyBouncingThingsReverse/data/eigenharpHands.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_4/classyBouncingThingsReverse/data/eigenharpHands.jpg -------------------------------------------------------------------------------- /Chapter_4/jigsaw2D/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_4/jigsaw2D/.DS_Store -------------------------------------------------------------------------------- /Chapter_4/jigsaw2D/data/cubaOldCar.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_4/jigsaw2D/data/cubaOldCar.jpg -------------------------------------------------------------------------------- /Chapter_4/jigsaw2D/data/cubaOldCarR.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_4/jigsaw2D/data/cubaOldCarR.jpg -------------------------------------------------------------------------------- /Chapter_4/jigsaw2D/data/grandcentralstation.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_4/jigsaw2D/data/grandcentralstation.jpg -------------------------------------------------------------------------------- /Chapter_4/jigsaw2D/jigsaw2D.pde: -------------------------------------------------------------------------------- 1 | // rectangular jigsaw: creating pieces by 2 | //breaking up rectangular picture by horizontal 3 | //and vertical lines 4 | Piece[] pieces; 5 | PImage original; 6 | PImage originalA; 7 | int phase = 0; 8 | Button[] buttons; 9 | int NHor = 4; 10 | int NVer = 3; 11 | int NoP = NHor * NVer; 12 | float oriWidth; 13 | float oriHeight; 14 | float oriRatio; 15 | int adjustedWidth; //adjusted dimensions to fit within (.75) of screen dimensions 16 | int adjustedHeight; 17 | int wedgeW; 18 | int wedgeH; 19 | int pieceMoving = -1; 20 | int offsetx; 21 | int offsety; 22 | int tolerance = 20; 23 | int travelBackFrames; 24 | int[] deltaxs = new int[NoP]; //hold amount of horizontal change in Restore animation. Computed in mouseClicked 25 | int[] deltays = new int[NoP]; //hold amount of vertical change in Restore animation. Computed in mouseClicked 26 | void setup(){ 27 | frameRate(30); 28 | travelBackFrames = 30*2; 29 | original = loadImage("cubaOldCarR.jpg"); 30 | 31 | size(displayWidth,displayHeight); 32 | 33 | oriWidth = original.width; 34 | oriHeight = original.height; 35 | oriRatio = oriHeight/oriWidth; 36 | adjustedWidth = round(min(.75 * displayWidth,oriWidth)); 37 | adjustedHeight = round(min(oriRatio * adjustedWidth,.75*displayHeight)); 38 | adjustedWidth = round(adjustedHeight/oriRatio); 39 | //println("adjustedWidth is ",adjustedWidth,"and adjustedHeight is",adjustedHeight); 40 | wedgeH = round(adjustedHeight/NVer); 41 | wedgeW = round(adjustedWidth /NHor); 42 | originalA = createImage(adjustedWidth,adjustedHeight,RGB); 43 | originalA.copy(original,0,0,round(oriWidth),round(oriHeight),0,0,adjustedWidth,adjustedHeight); 44 | makeButtons(); 45 | makePieces(); 46 | } 47 | 48 | void makeButtons() 49 | { 50 | buttons = new Button[2]; 51 | buttons[0] = new Button(50,30,80,40,color(200,0,0),"Mix up"); 52 | buttons[1] = new Button(200,30,80,40,color(0,100,0),"Restore"); 53 | } 54 | 55 | void drawButtons() 56 | { 57 | for (int i=0;i= 0) 106 | { 107 | pieces[pieceMoving].px= mouseX - offsetx; 108 | pieces[pieceMoving].py= mouseY - offsety; 109 | 110 | } 111 | } 112 | 113 | void mouseReleased() //checks if puzzle complete, that is all pieces roughly in position 114 | // relative to first piece 115 | { 116 | 117 | pieceMoving = -1; 118 | //determine position of first piece 119 | int firstx = pieces[0].px; 120 | int firsty = pieces[0].py; 121 | boolean oksofar = true; //assume things are okay. if any one piece not close enough change to false 122 | for (int i=1;itolerance) || (errory>tolerance)) 131 | { oksofar = false; 132 | 133 | break; 134 | } 135 | } 136 | if (oksofar) //only do something if pieces in place. 137 | { 138 | 139 | text("Close enough.You can click Restore or Mix up to try again.",500,20); 140 | phase = 1; 141 | 142 | } 143 | } 144 | 145 | void makePieces() //the Piece constructor will cut out the piece 146 | { 147 | pieces = new Piece[NoP]; 148 | int alli = 0; // index for populating pieces 149 | for (int i=0;i=px) && (mx<=(px+pw)) && (my>=py) && (my<(py+ph))) 287 | { 288 | offsetx = mx - px; //compute offsets so drag proceeds smoothly 289 | offsety = my - py; 290 | return true; 291 | } 292 | else //not over 293 | { 294 | return false; 295 | } 296 | } 297 | void display() // display this piece on screen 298 | { 299 | image(content,px,py,pw,ph); 300 | 301 | } 302 | 303 | 304 | } -------------------------------------------------------------------------------- /Chapter_4/jigsaw2D/sketch.properties: -------------------------------------------------------------------------------- 1 | mode.id=processing.mode.java.JavaMode 2 | mode=Java 3 | -------------------------------------------------------------------------------- /Chapter_4/makePathThenImageTravel/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_4/makePathThenImageTravel/.DS_Store -------------------------------------------------------------------------------- /Chapter_4/makePathThenImageTravel/data/bikerchickWGrant.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_4/makePathThenImageTravel/data/bikerchickWGrant.jpg -------------------------------------------------------------------------------- /Chapter_4/makePathThenImageTravel/makePathThenImageTravel.pde: -------------------------------------------------------------------------------- 1 | //make a path and then follow it 2 | Location[] path = {}; 3 | Boolean pathmade = false; //first phase 4 | //Boolean started = false; 5 | int pathI = 0; //index into path 6 | String instructions = "Press mouse button down, drag, and release to make a path"; 7 | //dimensions of image is 512 x 768 8 | /* 9 | float imageW = 512/3; 10 | float imageH = 768/3; 11 | float half_imageW = imageW/2; 12 | float half_imageH = imageH/2; 13 | */ 14 | float imageW; 15 | float imageH; 16 | float half_imageW; 17 | float half_imageH; 18 | PImage biker; 19 | 20 | 21 | void setup() { 22 | size(900, 600); 23 | background(255); 24 | 25 | biker = loadImage("bikerchickWGrant.jpg"); 26 | imageW = biker.width/3; 27 | imageH = biker.height/3; 28 | half_imageW = imageW/2; 29 | half_imageH = imageH/2; 30 | strokeWeight(3); 31 | 32 | fill(0); 33 | textSize(24); 34 | text(instructions,10,20); 35 | frameRate(30); 36 | } 37 | void draw() 38 | { 39 | 40 | if (pathmade) 41 | { 42 | background(255); 43 | 44 | text(instructions,10,20); 45 | Location p = path[pathI]; 46 | pathI++; 47 | image(biker,p.xp-half_imageW,p.yp-half_imageH,imageW,imageH); 48 | if (pathI>=path.length) {pathI = 0;} 49 | } 50 | //does nothing if path making is in process 51 | 52 | } 53 | void mousePressed(){ 54 | 55 | path = new Location[0]; //resets to be empty 56 | pathI = 0; 57 | pathmade = false; //path making underway. No drawing of image 58 | path = (Location[]) append(path,new Location(mouseX,mouseY)); 59 | 60 | } 61 | void mouseDragged(){ 62 | 63 | path = (Location[]) append(path,new Location(mouseX,mouseY)); 64 | //draw line segment from last location 65 | line(pmouseX,pmouseY,mouseX,mouseY); 66 | 67 | } 68 | void mouseReleased() 69 | { 70 | 71 | pathmade = true; // will now draw image 72 | } 73 | 74 | class Location { 75 | float xp; 76 | float yp; 77 | Location (float x, float y) { 78 | xp = x; 79 | yp = y; 80 | } 81 | 82 | } -------------------------------------------------------------------------------- /Chapter_5/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_5/.DS_Store -------------------------------------------------------------------------------- /Chapter_5/AnnikasInTree/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_5/AnnikasInTree/.DS_Store -------------------------------------------------------------------------------- /Chapter_5/AnnikasInTree/AnnikasInTree.pde: -------------------------------------------------------------------------------- 1 | /* @pjs preload="AnnikasInTree.jpg"; */ 2 | 3 | 4 | // demonstration for using, adding to, and saving a table 5 | // the program displays an image for a set amount of time, 2 seconds. 6 | // it then asks a question, to which the player keys in an answer 7 | // when the answer is set (by a return key), the answer is stored in the table 8 | // as a new row. 9 | // the answer is also checked using the correctanswers string. 10 | // this particular one checks for 10 or ten or Ten. 11 | // After the storing and checking, the player can play again by clicking on the screen. 12 | //The only way to end is to close the screen or click on stop in Processing. 13 | 14 | Table results; //hold table read in, and updated 15 | PImage picture; //holds the image that is the prompt for the question 16 | int startTime; // set in setup and mouseClicked 17 | int duration = 4*1000; //amount of time that image is displayed 18 | float pictureWidth; //used to calculate aspectWoverH 19 | float pictureHeight; // used to calculate aspectWoverH 20 | float setHeight = 900; //set height to display image 21 | float computedWidth; //calculated from the setHeight and aspectWoverH 22 | float aspectWoverH; //calculated from original values 23 | 24 | String prompt="What did you see? "; 25 | String myText = ""; //added to in keyPressed 26 | String answer = ""; //set in keyPressed when return is given 27 | String correctanswers = "(10)|(ten)|(Ten)"; //this is what is called a regular expression 28 | 29 | void setup() { 30 | picture = loadImage("AnnikasInTree.jpg"); 31 | pictureWidth = picture.width; 32 | pictureHeight = picture.height; 33 | aspectWoverH = pictureWidth/pictureHeight; 34 | computedWidth = setHeight * aspectWoverH; 35 | 36 | results = loadTable("results.csv","header"); //rows will be added to the table 37 | size(1000,1000); 38 | startTime = millis(); // current time will be compared to this plus duration 39 | textSize(20); 40 | 41 | } 42 | 43 | void draw() { //either displaying image, asking for response, or writing for click to re-start 44 | background(0); 45 | if ((millis()-startTime)< duration) { //keep displaying image 46 | image(picture,10,10,computedWidth,setHeight); 47 | } 48 | else { //ask question 49 | 50 | text(prompt + myText,100,100); 51 | //keyPressed builds up the input in myText and then puts it in answer 52 | if (answer.length()>0) { 53 | 54 | storeAnswer(); 55 | noLoop(); //stops looping until mouseClicked re-starts process 56 | } 57 | } 58 | } 59 | 60 | void keyPressed() { //standard way to accept keyboard input 61 | if (keyCode == BACKSPACE) { 62 | if (myText.length() > 0 ) { 63 | myText = myText.substring( 0 , myText.length()- 1 ); 64 | } 65 | } else if (keyCode == DELETE) { 66 | myText = "" ; 67 | } else if (keyCode == ENTER) { 68 | answer = myText; 69 | 70 | } else if (keyCode != SHIFT && keyCode != CONTROL && keyCode != ALT) { 71 | myText = myText + str(key); 72 | } 73 | 74 | } 75 | 76 | void storeAnswer(){ //store answer with a time stamp as new row in table 77 | //checks for the presence of 10 or ten 78 | // println("answer is "+answer); 79 | String check = ""; 80 | String ts = month()+"/"+day()+"/"+year()+" "+hour()+":"+minute()+":"+second(); 81 | // I call this a time stamp 82 | TableRow newRow = results.addRow(); //add new row, with 2 or 3 values set 83 | newRow.setString("Time Stamp",ts); 84 | 85 | newRow.setString("Answer",answer); 86 | if (match(answer,correctanswers) !=null) { //there was a match 87 | newRow.setString("Correct","Yes"); 88 | check = " Correct! "; 89 | } 90 | saveTable(results,"data/results.csv"); 91 | background(0); //clear screen 92 | text(check+"Click on screen to play again",200,200); 93 | } 94 | 95 | void mouseClicked() { //re-starts the game by setting startTime as the current time and re-starting looping 96 | myText=""; 97 | answer=""; 98 | startTime = millis(); 99 | loop(); 100 | } -------------------------------------------------------------------------------- /Chapter_5/AnnikasInTree/data/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_5/AnnikasInTree/data/.DS_Store -------------------------------------------------------------------------------- /Chapter_5/AnnikasInTree/data/AnnikasInTree.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_5/AnnikasInTree/data/AnnikasInTree.jpg -------------------------------------------------------------------------------- /Chapter_5/AnnikasInTree/data/results.csv: -------------------------------------------------------------------------------- 1 | Answer,Time Stamp,Correct 2 | I see a lot of Annikas,10/8/17 11:42, 3 | 10 Annikas in a tree,10/8/17 11:42,Yes 4 | ten,10/8/17 11:43,Yes 5 | How did you do this?,10/8/17 11:43, 6 | A lot of girls,10/12/2017 14:48:15, 7 | ten girls,10/12/2017 14:48:25,Yes 8 | girls around a tree,10/12/2017 14:51:12, 9 | A lot of girls,10/12/2017 14:51:19, 10 | 10 girls,10/12/2017 14:51:26,Yes 11 | Annika in a tree,12/3/2017 9:15:1, 12 | There are 10 Annikas,12/13/2017 13:25:50,Yes 13 | a lot of girls,12/13/2017 13:25:59, 14 | a lot of girls,12/13/2017 13:26:38, 15 | 10 annikas,12/13/2017 13:26:47,Yes 16 | -------------------------------------------------------------------------------- /Chapter_5/jMeyerSlingshot/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_5/jMeyerSlingshot/.DS_Store -------------------------------------------------------------------------------- /Chapter_5/jMeyerSlingshot/data/chicken.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_5/jMeyerSlingshot/data/chicken.gif -------------------------------------------------------------------------------- /Chapter_5/jMeyerSlingshot/data/feathers.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_5/jMeyerSlingshot/data/feathers.gif -------------------------------------------------------------------------------- /Chapter_5/jMeyerSlingshot/jMeyerSlingshot.pde: -------------------------------------------------------------------------------- 1 | Slingshot mySlingshot; 2 | Rock myRock; 3 | float rockD = 15; //diameter used for myRock 4 | float horSpeed, verSpeed1, verSpeed2; //to simulate ballistic motion 5 | float gravity = .05; //arbitrary value designed to produce a nice arc 6 | float adjust = 20; //arbitrary scale factor on initial speeds 7 | PImage chicken; 8 | Picture chickenPicture; 9 | PImage feathers; 10 | Picture feathersPicture; 11 | 12 | int targetIndex; 13 | Boolean rockInMotion = false; //rock is in motion in the sling and once released 14 | Boolean slingInMotion = false; // after mouse pressed on the rock and until mouse released 15 | Thing[] scene = {}; //will hold all Thing objects to be displayed 16 | class Thing { 17 | float tx; 18 | float ty; 19 | Thing (float x, float y) { 20 | tx = x; 21 | ty = y; 22 | } 23 | void show() { 24 | // to be over ridden 25 | } 26 | void move(float dx, float dy) { //moves are done incrementally, that is, arguments indicate changes 27 | tx = tx + dx; 28 | ty = ty + dy; 29 | } 30 | } 31 | class Rock extends Thing { 32 | float rDiam; 33 | Rock (float x, float y, float diam) { 34 | super(x,y); 35 | rDiam = diam; 36 | } 37 | void show() { 38 | fill(200,0,200); 39 | ellipse(tx,ty,rDiam, rDiam); 40 | 41 | } 42 | Boolean isOver(float mx, float my) { 43 | return (dist(mx,my,tx,ty)padLeft)&&(xpadTop)&&(y height) { 168 | rockInMotion = false; 169 | noLoop(); 170 | } 171 | } 172 | if (slingInMotion) { 173 | float dx = mouseX - pmouseX; //determine changes 174 | float dy = mouseY - pmouseY; 175 | 176 | mySlingshot.movePocket(dx,dy); 177 | myRock.move(dx,dy); 178 | 179 | } 180 | } 181 | 182 | void mousePressed() { 183 | if (!rockInMotion) { 184 | if (!slingInMotion) { 185 | if (myRock.isOver(mouseX,mouseY)) { //only do something if mouse is over the rock 186 | slingInMotion = true; 187 | 188 | } 189 | } 190 | } 191 | } 192 | void mouseReleased() { 193 | if (slingInMotion) { 194 | slingInMotion = false; 195 | calculateSpeeds(); 196 | rockInMotion = true; 197 | } 198 | } 199 | 200 | void calculateSpeeds() { 201 | float[] speeds = mySlingshot.initSpeeds(); 202 | 203 | horSpeed = speeds[0]; 204 | verSpeed1 = speeds[1]; 205 | //print("horSpeed is "+horSpeed+" verSpeed1 is "+verSpeed1); 206 | } 207 | void simulateRockInAir() { 208 | float dy; 209 | verSpeed2 = verSpeed1 + gravity; 210 | dy = (verSpeed1 + verSpeed2)/2; 211 | //print("in simulateRockInAir, horSpeed is "+horSpeed+" vertical change is "+dy); 212 | myRock.move(horSpeed,dy); 213 | verSpeed1 = verSpeed2; //prepare for next iteration 214 | } -------------------------------------------------------------------------------- /Chapter_5/snake/snake.pde: -------------------------------------------------------------------------------- 1 | // basic snake game: a snake, made up of segments, travels around and consumes food, growing one segmnt 2 | // with each food item. The arrow keys direct the motion. 3 | //You can think of the game as taking place in grid of unit size cells. 4 | //Jeanine Meyer 5 | // use of arrow keys 6 | //classes for snake segments and for food items. 7 | //use of ArrayList for list of Food objects (and array for segments of snake 8 | //Game ends when snake collides with itself or goes off screen or exceeds time limit (use of millis for timing) 9 | float margin = 10; 10 | float cw; 11 | float ch; 12 | int unit; 13 | 14 | 15 | int timeLimit = 30*1000; //30 seconds for game 16 | int timeStart; 17 | int score = 0; 18 | ArrayList foods = new ArrayList(); //Arraylists of objects provide way to remove elements 19 | int amountOfFood = 30; 20 | Seg[] segs; 21 | HeadSeg hseg; 22 | 23 | 24 | void setup() { 25 | size(800,600); 26 | cw = width; 27 | ch = height; 28 | unit = int(min(cw,ch)/30); 29 | ellipseMode(CORNER); //easier to check for snake over circle representing food 30 | placefood(); 31 | buildfirstsegments(5); 32 | //store starting time. Time check done in draw. 33 | timeStart = millis(); 34 | 35 | } 36 | 37 | void endgame(String m) { 38 | fill(0); //set for the message 39 | textSize(30); 40 | int snakeL = segs.length; 41 | text("Game Over: "+m+" Snake size is "+str(snakeL),100,100); 42 | noLoop(); //stop action: keys no longer work. 43 | } 44 | 45 | void draw() { 46 | background(200); //clear screen 47 | //display food, then snake, then check time. 48 | // the foods ArrayList elements are accessed using the get method. 49 | for (int i=0;i(width-unit))||(newHeady<0)||(newHeady>(height-unit))) { 131 | endgame("Out of bounds. "); 132 | } 133 | //see if over food 134 | for (int i=foods.size()-1;i>=0;i--) { //iterates over the foods arraylist backwards 135 | if (closeEnough(newHeadx,newHeady,foods.get(i).fx,foods.get(i).fy)) { 136 | foods.remove(i); //remove is available for ArrayList 137 | growSnake(); 138 | } 139 | } 140 | } 141 | void growSnake() { 142 | int numOfSegs = segs.length; 143 | //needs to look at last 2 segments to get where to put new segment 144 | int lastx = segs[numOfSegs-1].sx; 145 | int lasty = segs[numOfSegs-1].sy; 146 | int overx = segs[numOfSegs-2].sx; 147 | int overy = segs[numOfSegs-2].sy; 148 | //the next element is the same as the last in x or y, but these expressions always work. 149 | int difx = lastx-overx; 150 | int dify = lasty-overy; 151 | int newx = lastx+difx; 152 | int newy = lasty+dify; 153 | Seg newseg = new Seg(newx, newy); 154 | segs = (Seg[])append(segs,newseg); 155 | 156 | } 157 | Boolean closeEnough(int x1,int y1,int x2,int y2) { 158 | return (dist(x1,y1,x2,y2)< margin); 159 | } 160 | 161 | class Seg { 162 | int sx; 163 | int sy; 164 | Seg (int x, int y) { 165 | sx = x; 166 | sy = y; 167 | 168 | } 169 | void display() { 170 | fill(0,250,0); 171 | rect(sx,sy,unit, unit); 172 | } 173 | void moveTo(int nx, int ny) { //move to this new position 174 | sx = nx; 175 | sy = ny; 176 | } 177 | 178 | } 179 | 180 | class HeadSeg extends Seg { 181 | HeadSeg(int x, int y) { 182 | super(x,y); 183 | } 184 | void display() { //the head segment is displayed with a circle on top of a rectangle 185 | fill(0,250,0); 186 | rect(sx,sy, unit, unit); 187 | fill(0,0,200); 188 | ellipse(sx+.2*unit, sy+.2*unit, .60*unit,.60*unit); 189 | } 190 | } 191 | class Food { 192 | int fx; 193 | int fy; 194 | Food (int x, int y) { 195 | fx = x; 196 | fy = y; 197 | 198 | } 199 | void display() { 200 | fill(250,250,0); 201 | ellipse(fx+.1*unit,fy+.1*unit,.8*unit, .8*unit); 202 | } 203 | } -------------------------------------------------------------------------------- /Chapter_6/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_6/.DS_Store -------------------------------------------------------------------------------- /Chapter_6/hexagons/hexagons.pde: -------------------------------------------------------------------------------- 1 | //makes hexagon origami combination at mouse location 2 | //makes filled in polygon 3 | //polygons are NOT regular hexagons 4 | //4 layers 5 | 6 | float fudge = 3; 7 | void setup() 8 | { 9 | size(1000,900); 10 | fill(200,0,100); 11 | textSize(18); 12 | text("Click on screen, press any key to clear the screen",20,20); 13 | // hexShape(400,400,300); 14 | //hexLayer(500,400,300); 15 | // hexCombo(500,500,300); //draws combo over and over, random rotation 16 | } 17 | void draw() 18 | { 19 | } 20 | 21 | void mouseReleased() 22 | { 23 | //draw a combo at mouse location 24 | hexCombo(mouseX,mouseY,200); 25 | } 26 | void hexCombo(float cx, float cy, float startSize) { 27 | float curSize = startSize; 28 | translate(cx,cy); 29 | rotate(random(HALF_PI)); 30 | hexLayer(0,0,curSize); 31 | pushMatrix(); 32 | //translate(0,0); //was translate(cx,cy); 33 | rotate(PI/4); 34 | curSize = curSize/sqrt(2); 35 | hexLayer(0,0,curSize); 36 | rotate(PI/4); 37 | curSize = curSize/sqrt(2); 38 | hexLayer(0,0,curSize); 39 | rotate(PI/4); 40 | curSize = curSize/sqrt(2); 41 | hexLayer(0,0,curSize); 42 | popMatrix(); 43 | } 44 | void hexLayer(float cx, float cy,float layerSize) { 45 | float pctrx, pctry; 46 | float hexSize = layerSize; 47 | fill(200,0,100); //not needed, but keep it just in case I want to change color 48 | pctrx =.5*hexSize+fudge; 49 | pctry = 0; 50 | for (int i=0;i<4;i++){ 51 | pushMatrix(); 52 | translate(cx,cy); 53 | rotate(HALF_PI*i); 54 | hexShape(pctrx,pctry,.5*hexSize); 55 | popMatrix(); 56 | } 57 | 58 | 59 | } 60 | void hexShape(float cx, float cy, float hexSize) 61 | { 62 | //cx and cy are center of circle for which this is 63 | //an inscribed NOT regular hexagon. The hexSize is like radius. 64 | 65 | beginShape(); 66 | vertex(cx+hexSize,cy); 67 | vertex(cx+hexSize*.5,cy-hexSize*.5); 68 | vertex(cx-hexSize*.5,cy-hexSize*.5); 69 | vertex(cx-hexSize,cy); 70 | vertex(cx-hexSize*.5,cy+hexSize*.5); 71 | vertex(cx+hexSize*.5,cy+hexSize*.5); 72 | endShape(CLOSE); 73 | 74 | } 75 | void keyPressed() 76 | {background(200,200,200); 77 | text("Click on screen, press any key to clear the screen",20,20); 78 | } -------------------------------------------------------------------------------- /Chapter_6/imageFromWeb/imageFromWeb.pde: -------------------------------------------------------------------------------- 1 | //acquire image online at specific url. 2 | 3 | PImage original; 4 | Boolean nowOrig = true; 5 | float rfactor = 0.2980; 6 | float gfactor = 0.5870; 7 | float bfactor = 0.1140; 8 | 9 | String url = "http://faculty.purchase.edu/jeanine.meyer/esther.jpg"; 10 | int imgw; 11 | int imgh; 12 | 13 | void setup() { 14 | size(800,800); 15 | original = loadImage(url); 16 | imgw = 2*original.width; 17 | imgh = 2*original.height; 18 | image(original, 0,0,imgw,imgh); 19 | fill(0); 20 | textSize(20); 21 | text("Press any key to toggle between original and grayscale",20,imgh+50); 22 | } 23 | 24 | void draw() { } 25 | 26 | void keyPressed() { 27 | if (nowOrig) { 28 | loadPixels(); 29 | for(int i=0;i0) { 45 | url=answer; 46 | getImage(); 47 | 48 | } 49 | } 50 | 51 | } 52 | 53 | void keyPressed () { 54 | if (original!=null) { 55 | toggle(); 56 | } 57 | else { 58 | getTextInput(); 59 | } 60 | 61 | } 62 | void toggle() { 63 | if (nowOrig) { 64 | loadPixels(); 65 | for(int i=0;i 0 ) { 87 | myText = myText.substring( 0 , myText.length()- 1 ); 88 | } 89 | } else if (keyCode == DELETE) { 90 | myText = "" ; 91 | } else if (keyCode == ENTER) { 92 | answer = myText; 93 | 94 | } else if (keyCode != SHIFT && keyCode != CONTROL && keyCode != ALT) { 95 | myText = myText + str(key); 96 | } 97 | 98 | } -------------------------------------------------------------------------------- /Chapter_6/userEntersURLjustChangePicture1/userEntersURLjustChangePicture1.pde: -------------------------------------------------------------------------------- 1 | //acquire image online at specific url. 2 | 3 | PImage original; 4 | PImage grayed; 5 | Boolean nowOrig = false; 6 | float rfactor = 0.2980; 7 | float gfactor = 0.5870; 8 | float bfactor = 0.1140; 9 | String myText = ""; 10 | String answer = ""; 11 | String prompt ="Type in web address\n"; 12 | String url = ""; 13 | int imgw; 14 | int imgh; 15 | int imgw2; 16 | int imgh2; 17 | 18 | void setup() { 19 | size(800,800); 20 | textSize(20); 21 | fill(0); 22 | } 23 | 24 | void getImage() { 25 | original = loadImage(url); 26 | if (original !=null) { 27 | imgw = original.width; 28 | imgh = original.height; 29 | grayed = createImage(imgw,imgh,RGB); 30 | // grayed.copy(original,0,0,imgw,imgh,0,0,imgw,imgh); 31 | imgw2 = 2*imgw; 32 | imgh2 = 2*imgh; 33 | image(original, 0,0,imgw2,imgh2); 34 | makeGray(); 35 | image(grayed,imgw2+10,0,imgw2,imgh2); 36 | text("Press any key to toggle between original and grayscale",20,imgh+50); 37 | fill(200,0,0); 38 | ellipse(100,700,100,100); 39 | fill(0,200,0); 40 | ellipse(600,700,150,150); 41 | } 42 | else { 43 | myText = ""; 44 | answer=""; 45 | background(200); 46 | prompt = "Bad address for image. Try again.\n"; 47 | } 48 | } 49 | 50 | void draw() { 51 | if (original==null) { 52 | background(200); 53 | text(prompt+myText,100,100); 54 | if (answer.length()>0) { 55 | url=answer; 56 | getImage(); 57 | } 58 | } 59 | } 60 | 61 | void keyPressed () { 62 | if (original!=null) { 63 | toggle(); 64 | } 65 | else { 66 | getTextInput(); 67 | } 68 | } 69 | 70 | void makeGray() { 71 | original.loadPixels(); 72 | grayed.loadPixels(); 73 | for(int i=0;i 0 ) { 100 | myText = myText.substring( 0 , myText.length()- 1 ); 101 | } 102 | } else if (keyCode == DELETE) { 103 | myText = "" ; 104 | } else if (keyCode == ENTER) { 105 | answer = myText; 106 | } else if (keyCode != SHIFT && keyCode != CONTROL && keyCode != ALT) { 107 | myText = myText + str(key); 108 | } 109 | } -------------------------------------------------------------------------------- /Chapter_7/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_7/.DS_Store -------------------------------------------------------------------------------- /Chapter_7/hangman/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_7/hangman/.DS_Store -------------------------------------------------------------------------------- /Chapter_7/hangman/data/words.csv: -------------------------------------------------------------------------------- 1 | muon kerfuffle qat blight nene -------------------------------------------------------------------------------- /Chapter_7/hangman/hangman.pde: -------------------------------------------------------------------------------- 1 | //Hangman 2 | //table of just 5 words 3 | String[] wordlist; 4 | 5 | Table words; 6 | int numWords; 7 | Boolean chosen = false; 8 | String secret; //the current secret word 9 | String blanks = ""; //will hold blanks, some of which are filled in with correct guesses 10 | int wlen; //length of secret word 11 | int nGuessed; //number of correct guesses 12 | String msg = "Press any key to start"; 13 | 14 | int nextStep = 0; //position in the hanging progression 15 | 16 | 17 | void setup() { 18 | size(1000,800); 19 | words = loadTable("words.csv"); 20 | numWords = words.getRowCount(); 21 | wordlist = new String[numWords]; 22 | for (int i = 0;i=wlen) { 86 | //erase old message and put in new one 87 | //set up for re-start 88 | noStroke(); 89 | fill(200); 90 | rect(0,0,width,40); 91 | msg = "You won! Press any key for new game"; 92 | chosen = false; 93 | text(msg,20,30); 94 | nGuessed = 0; 95 | nextStep=0; 96 | } 97 | } 98 | 99 | } 100 | String replace(String base,String sub,int place,int remove){ 101 | String prior = base.substring(0,place); //before insert 102 | String after = base.substring(place+remove); //after 103 | return prior+sub+after; 104 | 105 | } 106 | void advanceHanging() { 107 | //println(" hanging advance "); 108 | switch (nextStep) { 109 | case 0: 110 | strokeWeight(6); 111 | stroke(153,76,0); //brownish for gallows 112 | line(5,200,300,200); 113 | line(10,200, 10,600); 114 | line(5,600,120,600); 115 | break; 116 | case 1: //head 117 | stroke(0); //necessary because may be noStroke for erasing blanks 118 | strokeWeight(2); 119 | fill(255); 120 | ellipse(200,300,40,70); 121 | break; 122 | case 2: //body 123 | stroke(0); 124 | line(200,335,200,450); 125 | break; 126 | case 3: //right arm 127 | stroke(0); 128 | line(200,350,240,380); 129 | break; 130 | case 4: //left arm 131 | stroke(0); 132 | line(200,350,160,380); 133 | break; 134 | case 5: //right leg 135 | stroke(0); 136 | line(200,450,220,550); 137 | break; 138 | case 6: //left leg 139 | stroke(0); 140 | line(200,450,180,550); 141 | break; 142 | case 7: //noose. Set up for re-start 143 | stroke(0); 144 | stroke(255,128,22); //color for rope 145 | line(180,200,200,330); 146 | noFill(); 147 | ellipse(200,340,30,10); 148 | fill(255); 149 | stroke(0); 150 | ellipse(200,300,40,70); 151 | //erase old message and put in new one 152 | noStroke(); 153 | fill(200); 154 | rect(0,0,width,40); 155 | msg = "You lost! Press any key for new game"; 156 | chosen = false; 157 | text(msg,20,30); 158 | nGuessed = 0; 159 | nextStep=0; 160 | break; 161 | } 162 | nextStep++; 163 | } -------------------------------------------------------------------------------- /Chapter_7/makeCard/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_7/makeCard/.DS_Store -------------------------------------------------------------------------------- /Chapter_7/makeCard/Button.pde: -------------------------------------------------------------------------------- 1 | class Button 2 | { 3 | int cx,cy; //center 4 | int bw, bh, bwsq, bhsq; 5 | color col; 6 | String label; 7 | 8 | 9 | Button (int x,int y,int bwid,int bht,color c, String lab) 10 | { 11 | cx = x; 12 | cy = y; 13 | bw = bwid; 14 | bh = bht; 15 | bwsq = bw*bw; 16 | bhsq = bh*bh; 17 | col = c; 18 | label = lab; 19 | 20 | } 21 | boolean isOver(int x,int y) //isOver uses formula for ellipse 22 | { 23 | float disX = cx - x; 24 | float disXsq = disX * disX; 25 | float disY = cy - y; 26 | float disYsq = disY * disY; 27 | float v = (disXsq / bwsq) + (disYsq/bhsq); 28 | return (v<1); 29 | 30 | } 31 | void display() //draw ellipse for button and then label 32 | { 33 | fill(col); 34 | ellipse(cx,cy,bw,bh); 35 | fill(0); 36 | textAlign(CENTER,CENTER); 37 | text (label,cx,cy); 38 | } 39 | } 40 | 41 | class FontButton extends Button { 42 | PFont ft; 43 | FontButton (int x,int y,int bwid,int bht,color c, String lab, PFont fta) { 44 | super(x,y,bwid,bht,c,lab); 45 | ft = fta; 46 | } 47 | void display() { 48 | textFont(ft); 49 | super.display(); 50 | } 51 | } -------------------------------------------------------------------------------- /Chapter_7/makeCard/data/camera-shutter-click-01.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_7/makeCard/data/camera-shutter-click-01.wav -------------------------------------------------------------------------------- /Chapter_7/makeCard/makeCard.pde: -------------------------------------------------------------------------------- 1 | //make card by selecting from file on computer, then picking from a random set of 3 fonts, then entering in a message 2 | //option to take a snapshot of the screen. 3 | 4 | import java.io.File; 5 | import processing.sound.*; 6 | 7 | SoundFile shutter; 8 | PImage original; 9 | float imgw; 10 | float imgh; 11 | float aspect; 12 | String[] fontList; 13 | String[] myListOfFontNames = new String[3]; 14 | //PFont[] myListOfFonts = new PFont[3]; 15 | PFont chosenFont; 16 | FontButton[] fontButtons = new FontButton[3]; 17 | Boolean fontButtonsBuilt = false; 18 | String prompt="Your message: "; 19 | String myText = ""; 20 | String answer = ""; 21 | String message = ""; 22 | PFont firstFont; 23 | Boolean okay = false; 24 | 25 | void setup() { 26 | size(900,800); 27 | shutter = new SoundFile(this,"camera-shutter-click-01.wav"); 28 | firstFont = createFont("Arial",30); 29 | textFont(firstFont); 30 | fill(0); 31 | text("Make a card by choosing a picture, then a font, then a message.\n Click down arrow to take a snap. Reload to try again.",10,50); 32 | fontList = PFont.list(); 33 | selectInput( "Select an image", "imageChosen" ); //prompt does not appear 34 | } 35 | 36 | void buildFontButtons() { 37 | for (int i=0;i<3;i++) { 38 | int ch = int(random(0,fontList.length)); 39 | PFont ft = createFont(fontList[ch],25); 40 | myListOfFontNames[i] = fontList[ch]; 41 | fontButtons[i] = new FontButton(260,500+i*60,400,50,color(200,0,100),fontList[ch],ft); 42 | fontButtons[i].display(); 43 | } 44 | 45 | } 46 | 47 | void draw() { 48 | if (okay) { 49 | if (original!=null) { 50 | background(200); 51 | image(original,10,10,imgw,imgh); 52 | 53 | if (!fontButtonsBuilt) { 54 | buildFontButtons(); 55 | fontButtonsBuilt = true; 56 | noLoop(); 57 | } 58 | else { // won't be back in draw until a mouseClick on a font button 59 | text(prompt+myText,100,imgh+100); 60 | if (answer.length()>0) { 61 | message = answer; 62 | displayAll(); 63 | } 64 | } 65 | } 66 | } 67 | } 68 | 69 | void displayAll() { 70 | background(200); 71 | image(original,10,10,imgw,imgh); 72 | text(message,30,imgh+50); 73 | noLoop(); 74 | } 75 | 76 | void imageChosen( File f ) { 77 | if( f.exists() ) { 78 | original = loadImage( f.getAbsolutePath() ); 79 | imgw = original.width; 80 | imgh = original.height; 81 | aspect = imgw/imgh; 82 | 83 | imgh = min(imgh,400); //resize as needed 84 | imgw = imgh * aspect; //won't change if imgh didn't change 85 | 86 | background(200); 87 | image(original, 10,10,imgw,imgh); 88 | okay = true; 89 | } 90 | } 91 | 92 | void mouseClicked() { 93 | 94 | for (int i=0;i<3;i++) { 95 | if (fontButtons[i].isOver(mouseX,mouseY)) { 96 | chosenFont = fontButtons[i].ft; 97 | textFont(chosenFont); 98 | textAlign(LEFT); 99 | break; 100 | } 101 | } 102 | loop(); 103 | 104 | } 105 | 106 | void getTextInput() { 107 | 108 | if (keyCode == BACKSPACE) { 109 | if (myText.length() > 0 ) { 110 | myText = myText.substring( 0 , myText.length()- 1 ); 111 | } 112 | } else if (keyCode == DELETE) { 113 | myText = "" ; 114 | } else if (keyCode == ENTER) { 115 | answer = myText; 116 | 117 | } else if (keyCode != SHIFT && keyCode != CONTROL && keyCode != ALT) { 118 | myText = myText + str(key); 119 | } 120 | 121 | } 122 | 123 | 124 | void keyPressed() { 125 | 126 | if (keyCode == DOWN) { 127 | shutter.play(); 128 | saveFrame("snaps/card####.png"); 129 | } 130 | else { 131 | getTextInput(); 132 | } 133 | 134 | } -------------------------------------------------------------------------------- /Chapter_7/makeCard/snaps/card2213.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_7/makeCard/snaps/card2213.png -------------------------------------------------------------------------------- /Chapter_7/makeCardAsk/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_7/makeCardAsk/.DS_Store -------------------------------------------------------------------------------- /Chapter_7/makeCardAsk/makeCardAsk.pde: -------------------------------------------------------------------------------- 1 | //acquire image online at specific url. 2 | //pick font 3 | //write message 4 | 5 | PImage original; 6 | 7 | String myText = ""; 8 | String answer = ""; 9 | String prompt ="Type in web address for the picture\n"; 10 | String promptF = "Name a font. \n"; 11 | String promptM ="Write your message.\n"; 12 | String url = ""; 13 | String fontName = ""; 14 | float imgw; 15 | float imgh; 16 | float aspect; 17 | 18 | PFont myFont; 19 | String message = ""; 20 | PFont firstFont; 21 | 22 | void setup() { 23 | size(800,800); 24 | firstFont = createFont("Arial",20); 25 | textFont(firstFont); 26 | fill(0); 27 | } 28 | 29 | 30 | 31 | void draw() { 32 | if (original==null) { 33 | text(prompt+myText,10,100); 34 | if (answer.length()>0) { 35 | url=answer; 36 | getImage(); 37 | } 38 | } 39 | else if (myFont==null) { 40 | text(promptF+myText,20,500); 41 | if (answer.length()>0) { 42 | fontName = answer; 43 | answer = ""; 44 | myText=""; 45 | setFont(); 46 | } 47 | } 48 | else if (message.length()<1) { 49 | text(promptM+myText,20,700); 50 | if (answer.length()>0) { 51 | message = answer; 52 | displayAll(); 53 | } 54 | } 55 | } 56 | 57 | void keyPressed() { 58 | getTextInput(); 59 | 60 | 61 | } 62 | 63 | void getImage() { 64 | original = loadImage(url); 65 | if (original !=null) { 66 | background(200); 67 | imgw = original.width; 68 | imgh = original.height; 69 | aspect = imgw/imgh; 70 | imgh = min(imgh,400); //resize as needed 71 | imgw = imgh * aspect; //won't change if imgh didn't change 72 | image(original, 0,0,imgw,imgh); 73 | myText = ""; 74 | answer = ""; 75 | } 76 | else { 77 | myText = ""; 78 | answer=""; 79 | background(200); 80 | text("Bad address for image. Try again.",20,30); 81 | } 82 | } 83 | 84 | void setFont() { 85 | myFont = createFont(fontName,30); 86 | //need to put in error check for bad font 87 | if (myFont==null) { 88 | myText = ""; 89 | answer=""; 90 | background(200); 91 | image(original,10,10,imgw,imgh); 92 | text("Bad font name. Try again.\n",20,500); 93 | } 94 | 95 | } 96 | 97 | void getMessage() { 98 | if (answer.length()>0) { 99 | message = answer; 100 | } 101 | } 102 | 103 | void displayAll() { 104 | background(200); 105 | image(original,10,10,imgw,imgh); 106 | textFont(myFont); 107 | text(message,10,imgh+50); 108 | text("Down arrow to take snapshot. Up arrow to re-start.",10,imgh+150); 109 | } 110 | 111 | 112 | void getTextInput() { 113 | if (keyCode == UP) { 114 | original = null; 115 | myFont = null; 116 | message = ""; 117 | myText=""; 118 | answer = ""; 119 | textFont(firstFont); 120 | background(200); 121 | } 122 | else if (keyCode == DOWN) { 123 | saveFrame("snaps/card####.png"); 124 | } 125 | else 126 | if (keyCode == BACKSPACE) { 127 | if (myText.length() > 0 ) { 128 | myText = myText.substring( 0 , myText.length()- 1 ); 129 | } 130 | } else if (keyCode == DELETE) { 131 | myText = "" ; 132 | } else if (keyCode == ENTER) { 133 | answer = myText; 134 | } else if (keyCode != SHIFT && keyCode != CONTROL && keyCode != ALT) { 135 | myText = myText + str(key); 136 | } 137 | } -------------------------------------------------------------------------------- /Chapter_7/showFonts/showFonts.pde: -------------------------------------------------------------------------------- 1 | String[] fontList ; 2 | PFont myfont; 3 | void setup() { 4 | size(800, 600); 5 | fill(255,0,0); 6 | fontList = PFont.list(); 7 | println(fontList); 8 | } 9 | 10 | void draw() { 11 | } 12 | 13 | void mousePressed() { 14 | int ch = int(random(0,fontList.length)); 15 | myfont = createFont(fontList[ch],20); 16 | textFont(myfont); 17 | text(fontList[ch],mouseX,mouseY); 18 | 19 | } -------------------------------------------------------------------------------- /Chapter_7/wormsTakeSnapshot/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_7/wormsTakeSnapshot/.DS_Store -------------------------------------------------------------------------------- /Chapter_7/wormsTakeSnapshot/snaps/worms2056.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_7/wormsTakeSnapshot/snaps/worms2056.png -------------------------------------------------------------------------------- /Chapter_7/wormsTakeSnapshot/snaps/worms2924.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_7/wormsTakeSnapshot/snaps/worms2924.png -------------------------------------------------------------------------------- /Chapter_7/wormsTakeSnapshot/wormsTakeSnapshot.pde: -------------------------------------------------------------------------------- 1 | //make a path and then follow it 2 | Location[] path = {}; 3 | Boolean pathmade = false; //first phase 4 | Boolean started = false; 5 | int pathI = 0; //index into path 6 | String instructions = "Press mouse button down, drag, and release to make a path"; 7 | void setup() { 8 | background(255); 9 | size(600,600); 10 | fill(0); 11 | text(instructions,10,20); 12 | fill(255); 13 | 14 | } 15 | void draw() 16 | { 17 | if (pathmade) 18 | { 19 | Location p = path[pathI++]; 20 | ellipse(p.getxp(),p.getyp(),20,20); 21 | if (pathI>=path.length) {pathI = 0;} 22 | } 23 | } 24 | void keyPressed(){ 25 | saveFrame("snaps/worms####.png"); 26 | 27 | } 28 | void mousePressed(){ 29 | started = true; //will add to the path 30 | pathmade = false; 31 | path = (Location[]) append(path,new Location(mouseX,mouseY)); 32 | } 33 | void mouseDragged(){ 34 | if (started){ 35 | path = (Location[]) append(path,new Location(mouseX,mouseY)); 36 | } 37 | } 38 | void mouseReleased() 39 | { 40 | started = false; 41 | pathmade = true; 42 | } 43 | 44 | class Location { 45 | float xp; 46 | float yp; 47 | Location (float x, float y) { 48 | xp = x; 49 | yp = y; 50 | } 51 | float getxp() { 52 | return xp; 53 | } 54 | float getyp() { 55 | return yp; 56 | } 57 | } -------------------------------------------------------------------------------- /Chapter_7/wormsTakeSnapshotErase/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_7/wormsTakeSnapshotErase/.DS_Store -------------------------------------------------------------------------------- /Chapter_7/wormsTakeSnapshotErase/snaps/worms2056.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_7/wormsTakeSnapshotErase/snaps/worms2056.png -------------------------------------------------------------------------------- /Chapter_7/wormsTakeSnapshotErase/snaps/worms2331.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_7/wormsTakeSnapshotErase/snaps/worms2331.png -------------------------------------------------------------------------------- /Chapter_7/wormsTakeSnapshotErase/snaps/worms2924.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_7/wormsTakeSnapshotErase/snaps/worms2924.png -------------------------------------------------------------------------------- /Chapter_7/wormsTakeSnapshotErase/snaps/worms3630.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_7/wormsTakeSnapshotErase/snaps/worms3630.png -------------------------------------------------------------------------------- /Chapter_7/wormsTakeSnapshotErase/wormsTakeSnapshotErase.pde: -------------------------------------------------------------------------------- 1 | //make a path and then follow it 2 | Location[] path = {}; 3 | Boolean pathmade = false; //first phase 4 | Boolean started = false; 5 | int pathI = 0; //index into path 6 | String instructions = "Press mouse button down, drag, and release to make a path.\n" + 7 | "Press c for clear and s for save snapshot."; 8 | void setup() { 9 | background(255); 10 | size(600,600); 11 | fill(0); 12 | text(instructions,10,20); 13 | fill(255); 14 | 15 | } 16 | void draw() 17 | { 18 | fill(0); 19 | text(instructions,10,20); 20 | fill(255); 21 | if (pathmade) 22 | { 23 | Location p = path[pathI++]; 24 | ellipse(p.getxp(),p.getyp(),20,20); 25 | if (pathI>=path.length) {pathI = 0;} 26 | } 27 | } 28 | void keyPressed(){ 29 | switch(key) { 30 | case 'c': 31 | path = new Location[0]; 32 | pathI = 0; 33 | pathmade = false; 34 | started = false; 35 | background(255); 36 | fill(0); 37 | text(instructions, 10,20); 38 | fill(255); 39 | break; 40 | case 's': 41 | saveFrame("snaps/worms####.png"); 42 | break; 43 | } 44 | 45 | } 46 | void mousePressed(){ 47 | started = true; //will add to the path 48 | pathmade = false; 49 | path = (Location[]) append(path,new Location(mouseX,mouseY)); 50 | } 51 | void mouseDragged(){ 52 | if (started){ 53 | path = (Location[]) append(path,new Location(mouseX,mouseY)); 54 | } 55 | } 56 | void mouseReleased() 57 | { 58 | started = false; 59 | pathmade = true; 60 | } 61 | 62 | class Location { 63 | float xp; 64 | float yp; 65 | Location (float x, float y) { 66 | xp = x; 67 | yp = y; 68 | } 69 | float getxp() { 70 | return xp; 71 | } 72 | float getyp() { 73 | return yp; 74 | } 75 | } -------------------------------------------------------------------------------- /Chapter_8/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_8/.DS_Store -------------------------------------------------------------------------------- /Chapter_8/collage6/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_8/collage6/.DS_Store -------------------------------------------------------------------------------- /Chapter_8/collage6/collage6.pde: -------------------------------------------------------------------------------- 1 | import processing.video.*; 2 | 3 | Item[] items = {}; 4 | Item curItem = null; 5 | 6 | void setup() { 7 | size(1000, 1000); 8 | 9 | Item myItem1 = new Item(10,30,100,200,250,0,200); 10 | items = (Item[]) append(items,myItem1); 11 | Item myItem2 = new Item(500,800,200,100,0,100,100); 12 | items = (Item[]) append(items,myItem2); 13 | MovieItem myMovieItem = new MovieItem(250,200,300,200,"snowman.mov",this); 14 | items = (Item[]) append(items,myMovieItem); 15 | ImageItem myImage1 = new ImageItem(10,500,205,154,"pigtails1.JPG"); 16 | items = (Item[]) append(items,myImage1); 17 | ImageItem myImage2 = new ImageItem(600,300,300,400,"climbing.jpg"); 18 | items = (Item[]) append(items,myImage2); 19 | } 20 | 21 | void draw() { 22 | //clear screen, display key commands, display all the items in order 23 | background(255); 24 | text("c for copy, d for delete, t for move to top, p for pause video, r for restart.",5,20); 25 | for (int i=0; i=0) { 98 | curItem = items[i]; 99 | } 100 | 101 | } 102 | 103 | void mouseDragged() { 104 | float dx; 105 | float dy; 106 | if (curItem!=null) { 107 | dx = mouseX - pmouseX; 108 | dy = mouseY - pmouseY; 109 | curItem.move(dx,dy); 110 | } 111 | 112 | } 113 | 114 | void mouseReleased(){ 115 | curItem = null; 116 | } 117 | 118 | // Called every time a new frame is available to read 119 | void movieEvent(Movie m) { 120 | m.read(); 121 | } -------------------------------------------------------------------------------- /Chapter_8/collage6/data/climbing.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_8/collage6/data/climbing.jpg -------------------------------------------------------------------------------- /Chapter_8/collage6/data/pigtails1.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_8/collage6/data/pigtails1.JPG -------------------------------------------------------------------------------- /Chapter_8/collage6/data/snowman.MOV: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_8/collage6/data/snowman.MOV -------------------------------------------------------------------------------- /Chapter_8/collage6/definitions.pde: -------------------------------------------------------------------------------- 1 | class Item { 2 | float xpos; 3 | float ypos; 4 | float iwidth; 5 | float iheight; 6 | int cred; 7 | int cgreen; 8 | int cblue; 9 | 10 | Item(float x,float y,float w,float h,int red,int green, int blue) { 11 | xpos = x; 12 | ypos = y; 13 | iwidth = w; 14 | iheight = h; 15 | cred = red; 16 | cgreen = green; 17 | cblue = blue; 18 | } 19 | 20 | Boolean isOver(float x,float y) { 21 | return ((x>xpos)&&(y>ypos)&&(x<(xpos+iwidth))&&(y<(ypos+iheight))); 22 | } 23 | void removeIt(int i) { 24 | removeFromItemsArray(i); 25 | } 26 | void display() { 27 | fill(cred,cgreen,cblue); 28 | rect(xpos,ypos,iwidth,iheight); 29 | } 30 | 31 | void move(float dx,float dy) { 32 | xpos +=dx; 33 | ypos +=dy; 34 | } 35 | void duplicate() { 36 | Item copy; 37 | copy = new Item(xpos+10, ypos+10,iwidth,iheight,cred,cgreen,cblue); 38 | items = (Item[]) append(items,copy); 39 | } 40 | void restart() { 41 | // no action for Item. 42 | } 43 | void pauseMovie() { 44 | //no action for Item 45 | } 46 | } 47 | 48 | 49 | 50 | 51 | class MovieItem extends Item { 52 | //inherits position and dimension variables, colors set to a default. Adds 2 variables 53 | 54 | Movie imovie; 55 | String movieFileName; 56 | PApplet paref; 57 | MovieItem (float x,float y,float w,float h, String mfn, PApplet par ) { 58 | //call parent constructor to set base variables 59 | super(x,y,w,h,255,255,255); //sets up white rectangle 60 | imovie = new Movie(par,mfn); 61 | movieFileName = mfn; 62 | paref = par; 63 | imovie.loop(); 64 | } 65 | void removeIt(int i) { 66 | imovie.stop(); 67 | imovie = null; //extra precaution to remove link to movie, for garbage collection 68 | super.removeIt(i); 69 | } 70 | 71 | void duplicate() { 72 | Item copy; 73 | copy = new MovieItem(xpos+10, ypos+10,iwidth,iheight,movieFileName,paref); 74 | items = (Item[]) append(items,copy); 75 | } 76 | 77 | void display() { 78 | image(imovie, xpos, ypos,iwidth,iheight); 79 | } 80 | 81 | void restart() { 82 | imovie.jump(0); 83 | imovie.loop(); 84 | } 85 | 86 | void pauseMovie() { 87 | imovie.pause(); 88 | } 89 | } 90 | 91 | class ImageItem extends Item { 92 | //inherits position and dimension variables, colors set to a default. Adds one variable 93 | PImage myImage; 94 | String filename; 95 | 96 | ImageItem (float x,float y,float w,float h, String imagefilename) { 97 | //call parent constructor to set base variables 98 | super(x,y,w,h,255,255,255); //sets up white rectangle 99 | filename = imagefilename; 100 | myImage = loadImage(imagefilename); 101 | } 102 | 103 | void duplicate() { 104 | Item copy; 105 | copy = new ImageItem(xpos+10, ypos+10,iwidth,iheight,filename); 106 | items = (Item[]) append(items,copy); 107 | } 108 | 109 | void display() { 110 | image(myImage, xpos, ypos,iwidth,iheight); 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /Chapter_8/origamifish/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_8/origamifish/.DS_Store -------------------------------------------------------------------------------- /Chapter_8/origamifish/data/cleftlip.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_8/origamifish/data/cleftlip.jpg -------------------------------------------------------------------------------- /Chapter_8/origamifish/data/sink.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_8/origamifish/data/sink.mp4 -------------------------------------------------------------------------------- /Chapter_8/origamifish/data/talk.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_8/origamifish/data/talk.mp4 -------------------------------------------------------------------------------- /Chapter_8/origamifish/data/throat1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_8/origamifish/data/throat1.jpg -------------------------------------------------------------------------------- /Chapter_8/origamifish/data/throat2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_8/origamifish/data/throat2.jpg -------------------------------------------------------------------------------- /Chapter_8/origamifish/origamifish.pde: -------------------------------------------------------------------------------- 1 | //origami talking fish. Converted from version made in HTML5 JavaScript. 2 | //Note the use of a Library. This requires installing the Library using the Processing/Sketch/Install Library... 3 | // and also including the iimport command in the code. 4 | //Demonstrates using different features when needed: for example, videos for certain steps and photos for certain steps 5 | //while using the official origami style line drawings for most of the steps. 6 | 7 | 8 | import processing.video.*; 9 | 10 | Movie sinkVideo; 11 | Movie talkVideo; 12 | boolean sinkPlaying = false; 13 | boolean talkPlaying = false; 14 | PImage cleft; 15 | PImage throat1; 16 | PImage throat2; 17 | PFont myfont; 18 | String direction1 = "Press buttons to advance or go back"; 19 | Button[] buttons; 20 | color backgroundcolor = color(255); 21 | int textx = 250; 22 | int texty = 460; 23 | 24 | void setup() { 25 | size(900,600); 26 | myfont = createFont("Georgia",16); 27 | textFont(myfont); 28 | cleft = loadImage("cleftlip.jpg"); 29 | throat1 = loadImage("throat1.jpg"); 30 | throat2 = loadImage("throat2.jpg"); 31 | sinkVideo = new Movie(this, "sink.mp4"); 32 | talkVideo = new Movie(this, "talk.mp4"); 33 | fill(0); 34 | 35 | text(direction1,textx,texty); 36 | makeButtons(); 37 | showButtons(); 38 | nextstep = 0; 39 | 40 | } 41 | 42 | void draw() { 43 | if (sinkPlaying) { 44 | image(sinkVideo,0,0); 45 | } 46 | else if (talkPlaying) { 47 | image(talkVideo,0,0); 48 | } 49 | } 50 | 51 | void makeButtons() { //all buttons are the same size. 52 | buttons = new Button[2]; 53 | buttons[0] = new Button("GO BACK",250,520,color(200,0,0)); 54 | buttons[1] = new Button("NEXT STEP",400,520,color(0,200,100)); 55 | } 56 | void showButtons() { 57 | for (int i = 0;i=steplabels.length) { 131 | nextstep=steplabels.length-1; 132 | } 133 | //this may be overkill. Stopping videos each time. 134 | talkPlaying = false; 135 | sinkPlaying = false; 136 | talkVideo.stop(); 137 | sinkVideo.stop(); 138 | 139 | background(255); 140 | 141 | switch (nextstep){ //this corresponds to the order of labels in the steplabels array 142 | case 0: 143 | directions(); 144 | break; 145 | case 1: 146 | showkami(); 147 | break; 148 | case 2: 149 | diamond1(); 150 | break; 151 | case 3: 152 | triangleM(); 153 | break; 154 | case 4: 155 | thirds(); 156 | break; 157 | case 5: 158 | rttriangle(); 159 | break; 160 | case 6: 161 | cornerdown(); 162 | break; 163 | case 7: 164 | unfolded(); 165 | break; 166 | case 8: 167 | changedfolds(); 168 | break; 169 | case 9: 170 | precollapse(); 171 | break; 172 | case 10: 173 | playsink(); 174 | break; 175 | case 11: 176 | littleguy(); 177 | break; 178 | case 12: 179 | oneflapup(); 180 | break; 181 | case 13: 182 | bothflapsup(); 183 | break; 184 | case 14: 185 | finsp(); 186 | break; 187 | case 15: 188 | preparelips(); 189 | break; 190 | case 16: 191 | showcleftlip(); 192 | break; 193 | case 17: 194 | lips(); 195 | break; 196 | case 18: 197 | showthroat1(); 198 | break; 199 | case 19: 200 | showthroat2(); 201 | break; 202 | case 20: 203 | rotatefish(); 204 | break; 205 | case 21: 206 | playtalk(); 207 | break; 208 | 209 | } 210 | fill(0); //set text to black 211 | ta = steplabels[nextstep]; 212 | textAlign(LEFT); 213 | text(ta,textx,texty); 214 | showButtons(); 215 | nextstep++; 216 | fill(255); //set back to white 217 | stroke(0); //set back to black 218 | } 219 | void goback() { 220 | nextstep = nextstep -2; 221 | if (nextstep<0) { 222 | nextstep = 0; 223 | } 224 | donext(); 225 | } 226 | 227 | void shortdownarrow(float x,float y) { 228 | beginShape(); 229 | vertex(x,y-20); 230 | vertex(x,y-7); 231 | vertex(x-5,y-12); 232 | vertex(x,y-7); 233 | vertex(x+5,y-12); 234 | vertex(x,y-7); 235 | endShape(); 236 | 237 | 238 | } 239 | float[] proportion(float x1,float y1,float x2,float y2,float p) { 240 | float[] ans = new float[2]; 241 | float xs = x2-x1; 242 | float ys = y2-y1; 243 | ans[0] = x1+ p*xs; 244 | ans[1] = y1 + p* ys; 245 | return ans; 246 | } 247 | 248 | void showcleftlip() { 249 | drawImage(cleft,40,40); 250 | } 251 | 252 | void skinnyline(float x1,float y1,float x2,float y2) { 253 | strokeWeight(1); 254 | line(x1,y1,x2,y2); 255 | } 256 | 257 | 258 | 259 | void curvedarrow(float x1,float y1,float x2,float y2, float px,float py) { 260 | // 261 | float arrowanglestart; 262 | float arrowanglefinish; 263 | float d = dist(x1,y1,x2,y2); 264 | float rad=sqrt(4.25*d*d); 265 | 266 | float ctrx; 267 | float ctry; 268 | float ex; 269 | float ey; 270 | float angdel = atan2(d/2,2*d); 271 | //angdel is .24497 in this sketch, but leave it general 272 | float fromhorizontal; 273 | stroke(255,0,0); 274 | beginShape(); 275 | if (y1==y2) { 276 | arrowanglestart = 1.5*PI-angdel; 277 | arrowanglefinish = 1.5*PI+angdel; 278 | ctrx = .5*(x1+x2) +px; 279 | ctry = y1+2*d +py; 280 | if (x1=wlen) { 73 | noStroke(); 74 | fill(200); 75 | rect(0,0,width,40); 76 | msg = "You won! Press any key for new game"; 77 | chosen = false; 78 | text(msg,20,30); 79 | nGuessed = 0; 80 | nextStep=0; 81 | } 82 | } 83 | } 84 | 85 | String replace(String base,String sub,int place,int remove){ 86 | String prior = base.substring(0,place); //before insert 87 | String after = base.substring(place+remove); //after 88 | return prior+sub+after; 89 | } 90 | 91 | void advanceHanging() { 92 | switch (nextStep) { 93 | case 0: 94 | strokeWeight(6); 95 | stroke(153,76,0); //brownish for gallows 96 | line(5,200,300,200); 97 | line(10,200, 10,600); 98 | line(5,600,120,600); 99 | break; 100 | case 1: //head 101 | stroke(0); //necessary because may be noStroke for erasing blanks 102 | strokeWeight(2); 103 | fill(255); 104 | ellipse(200,300,40,70); 105 | break; 106 | case 2: //body 107 | stroke(0); 108 | line(200,335,200,450); 109 | break; 110 | case 3: //right arm 111 | stroke(0); 112 | line(200,350,240,380); 113 | break; 114 | case 4: //left arm 115 | stroke(0); 116 | line(200,350,160,380); 117 | break; 118 | case 5: //right leg 119 | stroke(0); 120 | line(200,450,220,550); 121 | break; 122 | case 6: //left leg 123 | stroke(0); 124 | line(200,450,180,550); 125 | break; 126 | case 7: //noose. Set up for re-start 127 | stroke(255,128,22); //color for rope 128 | line(180,200,200,330); 129 | noFill(); 130 | ellipse(200,340,30,10); 131 | fill(255); 132 | stroke(0); 133 | ellipse(200,300,40,70); 134 | //erase old message and put in new one 135 | noStroke(); 136 | fill(200); 137 | rect(0,0,width,40); 138 | msg = "You lost! Press any key for new game"; 139 | chosen = false; 140 | text(msg,20,30); 141 | nGuessed = 0; 142 | nextStep=0; 143 | break; 144 | } 145 | nextStep++; 146 | } -------------------------------------------------------------------------------- /Chapter_9/hangmanButtons/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Chapter_9/hangmanButtons/.DS_Store -------------------------------------------------------------------------------- /Chapter_9/hangmanButtons/Button.pde: -------------------------------------------------------------------------------- 1 | class Button { 2 | int bx; 3 | int by; 4 | int bw; 5 | int bh; 6 | char letter; 7 | Boolean removed; 8 | 9 | 10 | 11 | Button (int tx, int ty, int tw, int th, char let) { 12 | bx = tx; 13 | by = ty; 14 | bw = tw; 15 | bh = th; 16 | letter = let; 17 | removed = false; 18 | } 19 | 20 | Boolean isOver (int x, int y) { 21 | if (removed) {return false;} 22 | if ((x>=bx)&&(x<=(bx+bw))&&(y>=by)&&(y<=(by+bh))) 23 | { 24 | removed = true; 25 | //remove this button by drawing over it 26 | noStroke(); 27 | fill(200); 28 | rect(bx,by,bw+3,bh+3); //extra is to erase borders 29 | return true; 30 | } 31 | else {return false;} 32 | } 33 | void display () { 34 | 35 | strokeWeight(1); 36 | stroke(0); 37 | fill(250,0,0); 38 | rect(bx,by,bw,bh); 39 | fill(0); 40 | textSize(20); 41 | text(letter,bx+padding,by+2*padding+1); 42 | 43 | } 44 | } -------------------------------------------------------------------------------- /Chapter_9/hangmanButtons/data/words.csv: -------------------------------------------------------------------------------- 1 | muon kerfuffle qat blight nene -------------------------------------------------------------------------------- /Chapter_9/hangmanButtons/hangmanButtons.pde: -------------------------------------------------------------------------------- 1 | //Hangman buttons 2 | //table of just 5 words 3 | //should probably use monospace font for alphabet buttons 4 | String[] wordlist; 5 | Table words; 6 | int numWords; 7 | Boolean chosen = false; 8 | String secret; //the current secret word 9 | String blanks = ""; //will hold blanks, some of which are filled in with correct guesses 10 | int wlen; //length of secret word 11 | int nGuessed; //number of correct guesses 12 | String msg = "Press any key to start"; 13 | int nextStep = 0; //position in the hanging progression 14 | 15 | Button[] buttons = {}; 16 | float padding = 8; //padding for letter within box in button 17 | 18 | void setup() { 19 | size(1000,800); 20 | words = loadTable("words.csv"); 21 | numWords = words.getRowCount(); 22 | wordlist = new String[numWords]; 23 | for (int i = 0;i=wlen) { 119 | //erase old message and put in new one 120 | //set up for re-start 121 | noStroke(); 122 | fill(200); 123 | rect(0,0,width,40); 124 | msg = "You won! Press any key for new game"; 125 | resetAlphabetButtons(); 126 | chosen = false; 127 | text(msg,20,30); 128 | nGuessed = 0; 129 | nextStep=0; 130 | } 131 | } 132 | 133 | 134 | String replace(String base,String sub,int place,int remove){ 135 | String prior = base.substring(0,place); //before insert 136 | String after = base.substring(place+remove); //after 137 | return prior+sub+after; 138 | } 139 | 140 | void advanceHanging() { 141 | //println(" hanging advance "); 142 | switch (nextStep) { 143 | case 0: 144 | strokeWeight(6); 145 | stroke(153,76,0); //brownish for gallows 146 | line(5,200,300,200); 147 | line(10,200, 10,600); 148 | line(5,600,120,600); 149 | break; 150 | case 1: //head 151 | stroke(0); //necessary because may be noStroke for erasing blanks 152 | strokeWeight(2); 153 | fill(255); 154 | ellipse(200,300,40,70); 155 | break; 156 | case 2: //body 157 | stroke(0); 158 | line(200,335,200,450); 159 | break; 160 | case 3: //right arm 161 | stroke(0); 162 | line(200,350,240,380); 163 | break; 164 | case 4: //left arm 165 | stroke(0); 166 | line(200,350,160,380); 167 | break; 168 | case 5: //right leg 169 | stroke(0); 170 | line(200,450,220,550); 171 | break; 172 | case 6: //left leg 173 | stroke(0); 174 | line(200,450,180,550); 175 | break; 176 | case 7: //noose. Set up for re-start 177 | stroke(255,128,22); //color for rope 178 | line(180,200,200,330); 179 | noFill(); 180 | ellipse(200,340,30,10); 181 | fill(255); 182 | stroke(0); 183 | ellipse(200,300,40,70); 184 | //erase old message and put in new one 185 | noStroke(); 186 | fill(200); 187 | rect(0,0,width,40); 188 | msg = "You lost! Press any key for new game"; 189 | resetAlphabetButtons(); 190 | chosen = false; 191 | text(msg,20,30); 192 | nGuessed = 0; 193 | nextStep=-1; 194 | break; 195 | } 196 | nextStep++; 197 | } -------------------------------------------------------------------------------- /Contributing.md: -------------------------------------------------------------------------------- 1 | # Contributing to Apress Source Code 2 | 3 | Copyright for Apress source code belongs to the author(s). However, under fair use you are encouraged to fork and contribute minor corrections and updates for the benefit of the author(s) and other readers. 4 | 5 | ## How to Contribute 6 | 7 | 1. Make sure you have a GitHub account. 8 | 2. Fork the repository for the relevant book. 9 | 3. Create a new branch on which to make your change, e.g. 10 | `git checkout -b my_code_contribution` 11 | 4. Commit your change. Include a commit message describing the correction. Please note that if your commit message is not clear, the correction will not be accepted. 12 | 5. Submit a pull request. 13 | 14 | Thank you for your contribution! -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Freeware License, some rights reserved 2 | 3 | Copyright (c) 2018 Jeanine Meyer 4 | 5 | Permission is hereby granted, free of charge, to anyone obtaining a copy 6 | of this software and associated documentation files (the "Software"), 7 | to work with the Software within the limits of freeware distribution and fair use. 8 | This includes the rights to use, copy, and modify the Software for personal use. 9 | Users are also allowed and encouraged to submit corrections and modifications 10 | to the Software for the benefit of other users. 11 | 12 | It is not allowed to reuse, modify, or redistribute the Software for 13 | commercial use in any way, or for a user’s educational materials such as books 14 | or blog articles without prior permission from the copyright holder. 15 | 16 | The above copyright notice and this permission notice need to be included 17 | in all copies or substantial portions of the software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | SOFTWARE. 26 | 27 | 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Apress Source Code 2 | 3 | This repository accompanies [*Programming 101*](http://www.apress.com/9781484236963) by Jeanine Meyer (Apress, 2018). 4 | 5 | [comment]: #cover 6 | ![Cover image](9781484236963.jpg) 7 | 8 | Download the files as a zip using the green button, or clone the repository to your machine using Git. 9 | 10 | ## Releases 11 | 12 | Release v1.0 corresponds to the code in the published book, without corrections or updates. 13 | 14 | ## Contributions 15 | 16 | See the file Contributing.md for more information on how you can contribute to this repository. -------------------------------------------------------------------------------- /Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/programming-101/fe232bd2694afcc2efd8b8dbc57ec63a399ea5a1/Thumbs.db --------------------------------------------------------------------------------