/** The Basics of Processing Defaults are size(100,100);, background(200);, strokeWeight(1);, and stroke(0);. use forward slash + astorisk + astorisk to start typing a document within your code. use astorisk + astorisk + forward slash to end documents. use forward slash + astorisk to start commenting out large portions of code. use astorisk + forward slash to end comments. use forward slash + forward slash + dash + dash to comment out small parts of code. use forward slash + forward slash to comment what your code does. to line up comments for what your code does, do //-----(text) **/ boolean do0 = true, do1, do2, do3, do4, do5, do6, do7, do8, do9; void setup ( ) { //set up frame size, etc. size(600,400); } void draw ( ) { //draw the next frame startPage ( ); //-------------------instructions aboutBackground ( ); //-------------draws background and text colors ( ); points ( ); lines ( ); triangles ( ); shapes ( ); modes ( ); ball ( ); action ( ); } void startPage ( ) { //draw instruction page textSize ( 20 ); text ( "This is a slideshow.", width / 2 - 75, height / 2 - 30 ); text ( "Press 1 then 2 then 3 all the way up to 9.", width / 2 - 175, height / 2 ); rectMode ( CORNER ); ellipseMode ( CENTER ); } void aboutBackground ( ) { //draw background & show what background does if ( ! do1 ) return; background ( 255 ); //----------------White background background ( 200 ); //----------------Gray background fill ( 0 ); //------------------------Black foreground textSize ( 15 ); text ( "Background wipes out all previous drawing.", width / 4, 200 ); fill ( 200 ); //----------------------Gray foreground } void colors ( ) { //colors if ( ! do2 ) return; background ( 255, 220, 220 ); //--------RED,GREEN,BLUE textSize ( 10 ); fill ( 255, 127, 0 ); text ( "RGB colors", 50, 90 ); textSize ( 16 ); fill ( 255, 0, 0 ); text ( "Red", 20, 20 ); fill ( 0, 255, 0 ); text ( "Green", 20, 40 ); fill ( 0, 0, 255 ); text ( "Blue", 20, 60 ); fill ( 255, 255, 0 ); text ( "Yellow", 100, 30 ); fill ( 0, 255, 255 ); text ( "Cyan", 100, 50 ); fill ( 255, 0, 255 ); text ( "Magenta", 100, 70 ); fill ( 0, 0, 0 ); text ( "Black", 200, 10 ); fill ( 255, 255, 255 ); text ( "White", 200, 90); fill ( 50, 50, 50 ); text ( "Various", 250, 20 ); fill ( 100, 100, 100 ); text ( "shades", 250, 40 ); fill ( 150, 150, 150 ); text ( "of", 250, 60 ); fill ( 200, 200, 200 ); text ( "gray", 250, 80 ); } void points ( ) { //points if ( ! do3 ) return; fill ( 0, 0, 255 ); textSize ( 12 ); text ( "points:", 10, 120 ); stroke ( 0, 0, 255 ); //----------------blue strokeWeight ( 1 ); point ( 20, 130 ); point ( 30, 130 ); point ( 40, 130 ); point ( 50, 130 ); stroke ( 255, 0, 255); //--------------fat magenta points strokeWeight ( 3 ); point ( 60, 150 ); point ( 65, 140 ); point ( 70, 130 ); point ( 75, 120 ); strokeWeight ( 1 ); //----------------restore normal stroke weight } void lines ( ) { //lines if ( ! do4 ) return; fill ( 255, 0, 0 ); //------------------red text ( "and lines:", 100, 130 ); stroke ( 0 ); strokeWeight ( 1 ); line ( 0, 100, width, 100 ); stroke ( 255, 0, 0 ); //----------------red strokeWeight ( 1 ); line ( 120, 140, 180, 135 ); strokeWeight ( 4 ); line ( 180, 120, 220, 150 ); strokeWeight ( 1 ); //----------------restore normal stroke weight } void triangles ( ) { //triangles if ( ! do5 ) return; fill ( 255, 0, 255 ); //----------------magenta text ( "some triangles:", 250, 130 ); stroke ( 255, 0, 255 ); strokeWeight ( 8 ); fill ( 0, 255, 255 ); triangle ( 350, 150, 400, 160, 430, 110 ); strokeWeight ( 1 ); //----------------restore normal stroke weight fill ( 255, 255, 0 ); //----------------yellow fill stroke ( 255, 127, 0); strokeWeight ( 2 ); triangle ( 420, 140, 460, 120, 470, 160 ); triangle ( 470, 140, 490, 130, 490, 150 ); triangle ( 495, 140, 500, 135, 500, 145 ); strokeWeight ( 1 ); //----------------restore normal stroke weight noStroke ( ); triangle ( 510, 140, 550, 130, 550, 150 ); fill ( 255, 0, 0 ); //------------------red fill triangle (510, 140, 550, 130, 550, 150 ); strokeWeight ( 1 ); //----------------restore normal stroke weight noStroke ( ); fill ( 0, 255, 0 ); triangle ( 560, 140, 570, 120, 580, 160 ); strokeWeight ( 1 ); //----------------restore normal stroke weight } void shapes ( ) { //shapes if ( ! do6 ) return; stroke ( 0 ); strokeWeight ( 1 ); line ( 0, 100, width, 100 ); line ( 50, 170, width - 50, 170 ); rectMode ( CORNER ); ellipseMode ( CENTER ); //------------restore default ellipseMode fill ( 0 ); text ( "Shapes: rect(), ellipse(), ...", 10, 200 ); fill ( 255 ); ellipse ( 20, 250, 20, 10 ); rect ( 20, 220, 20, 10 ); int x, y; x = 20; y = 220; //rectangle and ellipse fill ( 0, 255, 0 ); //------------------green rectangle rect ( x+50, y, 50, 30 ); fill ( 255, 0, 0 ); rect ( x + 50, y, 4, 4 ); //---------------corner //ellipse (default is CENTER) fill ( 0, 255, 0 ); ellipse ( x + 50, y + 50, 60, 30 ); //-------green ellipse fill ( 255, 0, 0 ); ellipse ( x + 50, y + 50, 4, 4 ); //---------red center } void modes ( ) { //modes if ( ! do7 ) return; fill ( 0 ); text ( "... Modes:", 200, 190 ); stroke ( 0 ); strokeWeight ( 1 ); line ( 180, 180, 180, 300 ); float x, y; //CORNER x = 200; y = 220; rectMode ( CORNER ); ellipseMode ( CORNER ); text ( "CORNER", x, y - 10 ); fill ( 0, 255, 0 ); //------------------green rectangle rect ( x, y, 50, 30 ); fill ( 255, 0, 0 ); rect ( x, y, 4, 4 ); //------------------corner //ellipse (default is CENTER) y = y + 50; fill ( 0, 255, 0 ); ellipse ( x, y, 50, 30 ); //-------------green ellipse fill ( 255, 0, 0 ); ellipse ( x, y, 4, 4 ); //---------------red center //CORNERS x = 300; y = 220; rectMode ( CORNERS ); ellipseMode ( CORNERS ); text ( "CORNERS", x, y - 10 ); float x2, y2; x2 = x + 50; y2 = y + 30; fill ( 0, 255, 0); //------------------green rectangle rect (x, y, x2, y2 ); fill ( 255, 0, 0 ); rect ( x, y, x + 4, y + 4 ); //--------------corners rect ( x2, y2, x2 - 4, y2 - 4 ); //----------corners //ellipse (default is CENTER) y = y + 50; y2 = y + 30; fill ( 0, 255, 0 ); ellipse ( x, y, x2, y2 ); //-------------green ellipse fill ( 255, 0, 0 ); ellipse ( x, y, x + 4, y + 4 ); //-----------red center ellipse ( x2, y2, x2 - 4, y2 - 4 ); //-------red center //CENTER x = 400; y = 220; rectMode ( CENTER ); ellipseMode ( CENTER ); text ( "CENTER", x - 20, y - 20 ); fill ( 0, 255, 0 ); //------------------green rectangle rect ( x, y, 50, 30 ); fill ( 255, 0, 0 ); rect ( x, y, 4, 4 ); //------------------corner //ellipse (default is CENTER) y = y + 50; fill ( 0, 255, 0 ); ellipse ( x, y, 50, 30 ); //-------------green ellipse fill ( 255, 0, 0 ); ellipse ( x, y, 4, 4 ); //---------------red center //RADIUS x = 500; y = 220; rectMode ( RADIUS ); ellipseMode ( RADIUS ); text ( "RADIUS", x - 30, y - 35 ); fill ( 0, 255, 0 ); //------------------green rectangle rect ( x, y, 50, 30 ); fill ( 255, 0, 0 ); rect ( x, y, 4, 4 ); //------------------corner //ellipse (default is CENTER) y = y + 50; fill ( 0, 255, 0 ); ellipse ( x, y, 50, 30 ); //-------------green ellipse fill ( 255, 0, 0 ); ellipse ( x, y, 4, 4 ); //---------------red center } int counter = 0; void action ( ) { if ( ! do8 ) return; fill ( 255, 127, 0 ); line ( 0, 310, width, 310 ); if ( ( counter / 30 ) %2 == 0 ) { textSize ( 15 ); text ( "Move the mouse!", 10, 375 ); //-----flashing message textSize ( 12 ); } counter++; rectMode ( CENTER ); noStroke ( ); rect ( mouseX, mouseY, 50, 90 ); ellipseMode ( RADIUS ); fill ( 255 ); ellipse ( mouseX - 12, mouseY - 30, 10, 10 ); ellipse ( mouseX + 12, mouseY - 30, 10, 10 ); fill ( 0, 0, 255 ); ellipse ( mouseX - 12, mouseY - 30, 5, 5 ); ellipse ( mouseX + 12, mouseY - 30, 5, 5 ); fill ( 255, 0, 0 ); text ( "Mickey", mouseX - 20, mouseY + 30 ); } float boxX = 150, boxY = 320, boxW = 300, boxH = 60; float ballX = 10, ballY = 10, ballDX = 5, ballDY = 9; float ballR, ballG, ballB; void ball ( ) { if ( ! do9 ) return; fill ( 0 ); text ( "Click inside box,\n for a new ball.", 10, 330 ); text ( "Frame number" + counter, 470, 370 ); fill ( 220, 230, 255 ); stroke ( 0 ); strokeWeight ( 4 ); rectMode ( CORNER ); rect ( 150, 320, 300, 60 ); ballX += ballDX; ballY += ballDY; if ( ballX < 0 || ballX > boxW ) ballDX = -ballDX; if ( ballY < 0 || ballY > boxH ) ballDY = -ballDY; fill ( ballR, ballG, ballB ); noStroke ( ); ellipseMode ( CENTER ); ellipse ( 160 + ballX, 320 + ballY, 15, 15 ); } boolean within ( float x, float y, float left, float right, float top, float bottom ) { //True if x,y within boundaries return x > left && x < right && y > top && y < bottom; } //EVENT HANDLERS void mousePressed ( ) { if ( within ( mouseX, mouseY, boxX, boxX + boxW, boxY, boxY + boxH ) ) { //Start new ball here ballX = mouseX - boxX; ballY = mouseY - boxY; ballDX = random ( 10 ); ballDY = random ( 4 ); ballR = random ( 255 ); ballG = random ( 255 ); ballB = random ( 255 ); counter = 0; //Zero out the frame count } } void keyPressed ( ) { //event handler for keyboard do1 = do2 = do3 = do4 = do5 = do6 = do7 = do8 = false; switch ( key ) { case '9': do9 = true; case '8': do8 = true; case '7': do7 = true; case '6': do6 = true; case '5': do5 = true; case '4': do4 = true; case '3': do3 = true; case '2': do2 = true; case '1': do1 = true; } if ( key == 'q' ) exit ( ); }