/////////////////////////////////////////////////////// /////////////////////////////////////////////////////// ///////////////////// Portal Turret /////////////////// ////////////////////// Annie Wang ///////////////////// /////////////////////////////////////////////////////// /////////////////////////////////////////////////////// //set up the base of the drawing void setup () { size (400, 400); //canvas size: 400x400 strokeWeight (3); //stroke thickness = 3 rectMode (CORNERS); //draw rectangles with coordinates of opposite corners println ("I see you. Target acquired."); //prints text when drawing launches } //draw components of the drawing, continuously redrawn void draw () { //BACKGROUND background (240); //walls noStroke (); fill (220); rect (0, 0, 75, 400); rect (325, 0, 400, 400); //floor fill (200); rect (75, 325, 325, 400); triangle (75, 325, 75, 400, 0, 400); triangle (325, 325, 325, 400, 400, 400); //shadow under turret fill (150); ellipse (200, 400, 130, 70); //PORTALS //orange portal fill(255, 100, 10, brightness(200-mouseX/2)); ellipse (0, 170, 90, 310); fill (240, brightness(200-mouseX/2)); ellipse (0, 170, 70, 290); //blue portal fill (50, 50, 255, brightness(mouseX/2)); ellipse (400, 170, 90, 310); fill (240, brightness (mouseX/2)); ellipse (400, 170, 70, 290); //portals are more visible when the mouse is closer to their side //they disappear when the mouse is on the opposite portal //TURRET //back leg stroke (0); //outline: black fill(50); rect (195, 300, 205, 360); ellipse (200, 360, 10, 40); //leg tip noStroke (); rect (197, 300, 204, 360); //cover outline stroke //front legs stroke(0); fill (70); quad (169, 339, 158, 339, 150, 400, 160, 400); quad (231, 339, 242, 339, 250, 400, 240, 400); //front leg caps fill(255); arc(170, 340, 26, 70, radians(180), radians(300)); arc(230, 340, 26, 70, radians(-120), radians(0)); //outline of front leg caps line (170, 340, 182, 285); line (230, 340, 218, 285); line (170, 340, 157, 340); line(230, 340, 243, 340); //turret body base fill (255); ellipse (200, 200, 100, 240); //turret body middle line line (200, 80, 200, 320); //cover turret sides noStroke(); fill(240); rect (100, 80, 170, 295); rect (300, 80, 230, 295); //GUNS //gun base stroke(0); fill(50); rect (150-mouseY/12, 190, 170, 210); rect (230, 190, 250+mouseY/12, 210); //gun holes noStroke (); fill (5); //left ellipse (193-mouseY/12, 200, 10, 10); ellipse (180-mouseY/12, 200, 10, 10); //right ellipse (207+mouseY/12, 200, 10, 10); ellipse (220+mouseY/12, 200, 10, 10); //guns are pulled out when the mouse is pulled down //guns are hidden when the mouse is at the top of the canvas //cover guns so they dont cover the body fill(255); rect (170, 190, 199, 210); rect(230, 190, 199, 210); //BODY DETAILS //body side outlines stroke(0); line (170, 105, 170, 295); line (230, 105, 230, 295); //indent circle fill (180); ellipse (200, 200, 40, 40); fill (230); arc (200, 200, 39, 39, radians(0), radians (180)); //shadow //red circle stroke (0); fill (255, 0, 0); ellipse (200, 200, 25, 25); //red inside noStroke (); fill (250, 75, 75); ellipse (200, 200, 17, 17); //black centre where the laser comes out, also centre of canvas fill (0); ellipse (200, 200, 10, 10); //TURRET ARMS //arm body stroke (0); fill(255); arc (170-mouseY/12, 200, 40, 190, radians (90), radians (270)); arc (230+mouseY/12, 200, 40, 190, radians (-90), radians (90)); //rectangles on arms fill(0); rect(150-mouseY/12, 195, 160-mouseY/12, 197); rect(240+mouseY/12, 195, 250+mouseY/12, 197); //arm outlines line (170-mouseY/12, 105, 170-mouseY/12, 295); line (229+mouseY/12, 105, 229+mouseY/12, 295); //arms are pulled out when the mouse is pulled down //arms close when the mouse is at the top of the canvas //ANTENNA line (190, 82, 190, 62); line (180, 90, 180, 60); line (180, 60, 190, 50); line (190, 50, 190, 30); } //LASER void mousePressed () //draws when mouse button is pressed { stroke (255, 0, 0); //red stroke line (mouseX, mouseY, 200, 200); //draws a line from the centre of the turret eye to the mouse frameRate (20); //slows the frame rate so the line is visible longer println ("Activated. Preparing to dispense product."); //prints text when laser is fired }