class FunnelRight { private float x, y, w, h, shootY, iEdgeLength, OLEdgeLength, OREdgeLength; FunnelRight(float _x, float _y, float _w) { x = _x; y = _y; w = _w; h = 60; shootY = y + (h-5); iEdgeLength = dist(x - w/2, y, x, shootY); OLEdgeLength = dist(x - w/2, y, x, y + h); OREdgeLength = dist(x + w/2, y, x, y + (h-10)); } void collide(Pebble peb) { float distILS = dist(peb.x(), peb.y(), x - w/2, y) + dist(peb.x(), peb.y(), x, shootY); float distIRS = dist(peb.x(), peb.y(), x + w/2, y) + dist(peb.x(), peb.y(), x, shootY); float distOLS = dist(peb.x(), peb.y(), x - w/2, y) + dist(peb.x(), peb.y(), x - 5, y + h); float distORS = dist(peb.x(), peb.y(), x + w/2, y) + dist(peb.x(), peb.y(), x + 5, y + h); // if peb is too close to the edge, move it to the center of the funnel if ( distILS - iEdgeLength < 5 || distIRS - iEdgeLength < 5 ) { peb.moveTo(x, peb.y()); peb.setVelocity(0, peb.vy()); } if ( distOLS - OLEdgeLength < 3 || distORS - OREdgeLength < 3 ) { peb.setVelocity(-peb.vx()*2, peb.vy()); } // if peb is close enough to the joint, move to the edge of the spout and // send it flying if ( dist(peb.x(), peb.y(), x, shootY) < 5 ) { peb.moveTo(x + 25, shootY); peb.setVelocity(20, 0); } } void move(int d) { float s = 5; switch(d) { case 1: y -= s; break; case 2: x += s; break; case 3: y += s; break; case 4: x -= s; break; } if ( x < w/2 ) x = w/2; else if ( x > width - w/2 ) x = width - w/2; if ( y < 0 ) y = 0; else if ( y > height - h ) y = height - h; shootY = y + (h-5); } void render() { stroke(0); fill(68, 99, 99, 128); beginShape(); vertex(x + w/2, y); vertex(x + 5, y + (h - 10)); vertex(x + 25, y + (h - 10)); vertex(x + 25, y + h); vertex(x - 5, y + h); vertex(x - w/2, y); endShape(); } } class FunnelLeft { private float x, y, w, h, shootY, iEdgeLength, OLEdgeLength, OREdgeLength; FunnelLeft(float _x, float _y, float _w) { x = _x; y = _y; w = _w; h = 60; shootY = y + (h-5); iEdgeLength = dist(x - w/2, y, x, shootY); OREdgeLength = dist(x - w/2, y, x, y + h); OLEdgeLength = dist(x + w/2, y, x, y + (h-10)); } void collide(Pebble peb) { float distIRS = dist(peb.x(), peb.y(), x - w/2, y) + dist(peb.x(), peb.y(), x, shootY); float distILS = dist(peb.x(), peb.y(), x + w/2, y) + dist(peb.x(), peb.y(), x, shootY); float distORS = dist(peb.x(), peb.y(), x - w/2, y) + dist(peb.x(), peb.y(), x - 5, y + h); float distOLS = dist(peb.x(), peb.y(), x + w/2, y) + dist(peb.x(), peb.y(), x + 5, y + h); // if peb is too close to the edge, move it to the center of the funnel if ( distILS - iEdgeLength < 5 || distIRS - iEdgeLength < 5 ) { peb.moveTo(x, peb.y()); peb.setVelocity(0, peb.vy()); } if ( distOLS - OLEdgeLength < 3 || distORS - OREdgeLength < 3 ) { peb.setVelocity(-peb.vx()*2, peb.vy()); } // if peb is close enough to the joint, move to the edge of the spout and // send it flying if ( dist(peb.x(), peb.y(), x, shootY) < 5 ) { peb.moveTo(x - 25, shootY); peb.setVelocity(-20, 0); } } void move(int d) { float s = 5; switch(d) { case 1: y -= s; break; case 2: x += s; break; case 3: y += s; break; case 4: x -= s; break; } if ( x < w/2 ) x = w/2; else if ( x > width - w/2 ) x = width - w/2; if ( y < 0 ) y = 0; else if ( y > height - h ) y = height - h; shootY = y + (h-5); } void render() { stroke(0); fill(68, 99, 99, 128); beginShape(); vertex(x - w/2, y); vertex(x - 5, y + (h - 10)); vertex(x - 25, y + (h - 10)); vertex(x - 25, y + h); vertex(x + 5, y + h); vertex(x + w/2, y); endShape(); } }