//example from dusters_holes in processing class at MachineProject // class definition class PinWheel { float x, y; float w, h; float fade; float speedX; float speedY; int life; int geo; //integer selection of 3 different shapes (triangle, ellipse, rectangle) int colorOpt; ////integer selection of 3 different colors (green, orange, magenta) float rotation; float shapeScale; float difX = 0; //variable for mouse distance from the center of the shape float difY = 0; //variable for mouse distance from the center of the shape float entryX = 0; //variable for mouse position when shape is "touched" float entryY = 0; //variable for mouse position when shape is "touched" int triggerDist = 30; //max distance from shape center that counts as a touch (defines a square around center) int fanMulti = 1; // counter variable for speed of fanning out, but not good method int fanSpeed = 50; // controls the speed of fanning out, but not good method int fanPetals = 12; // number of petals in the fan/flower float xPinWheel, yPinWheel; // class declaration PinWheel (float ix, float iy, float iGeo, float iRotation, float iColor, float iScale, float iPetals) { xPinWheel = ix; yPinWheel = iy; x = ix; y = iy; w = 5; h = 5; speedX = (bgwidth/2-ix)/(bgheight/2-iy); speedY = (bgheight/2-iy)/(bgwidth/2-ix); life = 1; fade = 90; geo = round(iGeo); //converts float 0-2 to integers rotation = iRotation; //rotation value from 0-TWO_PI colorOpt = round(iColor); //converts float 0-2 to integers shapeScale = .75 + iScale; //make scale go from .75-1.5 fanPetals = round(iPetals); //sets petal numbers from 7 to 12 as integers } // main function void update() { if (fanPetals==8){ fanPetals = 9; //removes 8 petal option } if (life == 1) { defaultDraw(); //move(); checkImpact(); } if (life == 2) { flower(); //move(); } if (life == 2) { die(); } /* //Draw test Shapes rectMode(CENTER); stroke(0,0,255); noFill(); //rect(xPinWheel-23, yPinWheel-10, triggerDist, triggerDist); rect(x, y, triggerDist, triggerDist); //xRotated-xPinWheel-23) bgheight/2*bgheight/2 - (y-bgheight/2)*(y-bgheight/2))) { //adjusted to be relative to center of screen speedX = speedX*-1; } if (((y-bgheight/2)*(y-bgheight/2) > bgheight/2*bgheight/2 - (x-bgwidth/2)*(x-bgwidth/2))) { //adjusted to be relative to center of screen speedY = speedY*-1; } // update position x = x + speedX; y = y + speedY; if (((xPinWheel-bgwidth/2)*(xPinWheel-bgwidth/2) > bgheight/2*bgheight/2 - (yPinWheel-bgheight/2)*(yPinWheel-bgheight/2))) { //adjusted to be relative to center of screen speedX = speedX*-1; } if (((yPinWheel-bgheight/2)*(yPinWheel-bgheight/2) > bgheight/2*bgheight/2 - (xPinWheel-bgwidth/2)*(xPinWheel-bgwidth/2))) { //adjusted to be relative to center of screen speedY = speedY*-1; } // update position xPinWheel = xPinWheel + speedX; yPinWheel = yPinWheel + speedY; } void defaultDraw() { // draw with SVG style pushMatrix(); //temporary transformation matrix translate(x, y); //move origin to current X,Y position rotate(rotation); //rotate transformation matrix scale(shapeScale); //scale the shape up from 1 to 2 translate(-5, 5); //move origin to current X,Y position shapeMode(CENTER); //draws shape from center, not upper left corner noStroke(); //fill(255,255,255,(76); //White Fill - 30% transparent fill(255,255,255,(25*pow(shapeScale,2.5))); //White Fill - 30% transparent but altered by scale (more extreme change) switch(geo) { case 0: t.disableStyle(); //removes SVG style and lets sketch override shape(t, 0, 0); //draw shape break; //needed for Switch/Case case 1: e.disableStyle(); //removes SVG style and lets sketch override shape(e, 0, 0); //draw shape break; //needed for Switch/Case case 2: r.disableStyle(); //removes SVG style and lets sketch override shape(r, 0, 0); //draw shape break; //needed for Switch/Case } popMatrix(); //reset transformation matrix //Construction Lines for DeBugging /* //Draw polar conversion of Mouse Position, translated from the bg center stroke(128,0,0); strokeWeight(1); ellipseMode(CENTER); ellipse(xRotated,yRotated, 10,10); */ } void checkImpact() { difX = abs(xRotated-xPinWheel); //how far horizontally is the mouse from the center of the shape? difY = abs(yRotated-yPinWheel); //how far vertically is the mouse from the center of the shape? if ((abs(xRotated-xPinWheel) 1){ switch(colorOpt) { //ignored if enablestyle, chooses color case 0: //fill(175,188,33,70); //GREEN, ignored if enablestyle fill(175,188,33,(25*pow(shapeScale,2))*12/fanPetals); //GREEN, ignored if enablestyle, transparency altered by scale (more extreme change) break; //needed for Switch/Case case 1: //fill(232,109,31,70); //ORANGE, ignored if enablestyle fill(232,109,31,(25*pow(shapeScale,2))*12/fanPetals); //ORANGE, ignored if enablestyle, transparency altered by scale (more extreme change) break; //needed for Switch/Case case 2: //fill(201,0,108,70); //MAGENTA, ignored if enablestyle fill(201,0,108,(25*pow(shapeScale,2))*12/fanPetals); //MAGENTA, ignored if enablestyle, transparency altered by scale (more extreme change) break; //needed for Switch/Case } }else{ switch(colorOpt) { //ignored if enablestyle, chooses color case 0: //fill(192,227,218,70); //BLUE, ignored if enablestyle fill(192,227,218,(25*pow(shapeScale,2))*12/fanPetals); //BLUE, ignored if enablestyle, transparency altered by scale (more extreme change) break; //needed for Switch/Case case 1: //fill(115,197,160,70); //GREEN, ignored if enablestyle fill(115,197,160,(25*pow(shapeScale,2))*12/fanPetals); //GREEN, ignored if enablestyle, transparency altered by scale (more extreme change) break; //needed for Switch/Case case 2: //fill(211,18,69,70); //RED, ignored if enablestyle fill(211,18,69,(25*pow(shapeScale,2))*12/fanPetals); //RED, ignored if enablestyle, transparency altered by scale (more extreme change) break; //needed for Switch/Case } } noStroke(); //ignored if enablestyle if(fanMulti 0) { fade = fade - 1; } else { life = 0; } fill (255,fade); ellipse(x,y,w,h); */ } }