Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // CFI - Drawing Machines - Janny, Ji
- // Texture Text Machine
- ArrayList<JannysMinionClass> JannysMinionClassList;
- //int totalNumberOfJannysMinionClasss = 100;
- PGraphics jannysForegroundPGraphic;
- PGraphics jannysBackgroundPGraphic;
- PImage jannysForegroundPImage;
- PImage jannysBackgroundPImage;
- int myBackgroundTextureID = 3; // set this to 1-5
- Boolean showBackground = false;
- //int myOverallAnimationSpeed = 100; // set this between 1 to 100 ish
- color jannysCheckPixelColor;
- color jannysCheckColor = color(0);
- float jannysGridSpacing;
- float distanceToMouse;
- // Minions
- float minionSize = 0.7;
- float minionEasingSlow = .05;
- float minionEasingFast = .2;
- float minionSizeMin = 0.5; // CHANGE THIS to adjust default minimum module scale
- float minionSizeMax = 100; // CHANGE THIS to adjust default maximum module scale
- PVector minionVelocity = new PVector(0, 0);
- int jannysGridOffsetY = 0;
- int jjGridOffsetX = 0;
- int jjColumns = 150; //47
- void setup() {
- size(960, 540);
- colorMode(HSB, 255, 255, 255, 100);
- jannysGridSpacing = width/jjColumns;
- minionVelocity = new PVector(1, 1);
- frameRate(1000); // change the frame rate to change the speed
- // this graphic holds the background image
- switch(myBackgroundTextureID) {
- case 2:
- jannysBackgroundPImage = loadImage("texture2.png");
- break;
- case 3:
- jannysBackgroundPImage = loadImage("texture5.png");
- break;
- default:
- jannysBackgroundPImage = loadImage("texture1.png");
- break;
- }
- jannysBackgroundPGraphic = createGraphics(width, height);
- jannysBackgroundPGraphic.beginDraw();
- jannysBackgroundPGraphic.image(jannysBackgroundPImage, 0, 0);
- jannysBackgroundPGraphic.endDraw();
- // this holds the vector graphic of the minions
- jannysForegroundPGraphic = createGraphics(width, height);
- jannysForegroundPGraphic.noStroke();
- // this holds the pixel image of the minions
- jannysForegroundPImage = loadImage("texture5.png");
- // Create an empty ArrayList (will store JannysMinionClass objects)
- JannysMinionClassList = new ArrayList<JannysMinionClass>();
- // add the modules using a loop
- for (float y = jannysGridOffsetY; y < height; y+= jannysGridSpacing) {
- for (float x = jjGridOffsetX; x < width; x+= jannysGridSpacing) {
- jannysCheckPixelColor = jannysBackgroundPGraphic.get(int(x), int(y));
- if (jannysCheckPixelColor != jannysCheckColor) {
- JannysMinionClassList.add(new JannysMinionClass(x, y));
- }
- }
- }
- }
- void draw() {
- background(0);
- if (showBackground) image(jannysBackgroundPGraphic, 0, 0);
- for (JannysMinionClass jannysMod : JannysMinionClassList) {
- jannysMod.myUpdate();
- jannysMod.myDisplay();
- }
- jannysForegroundPGraphic.clear();
- //jannysForegroundPGraphic.filter(BLUR, 3);
- image(jannysForegroundPGraphic, 0, 0);
- }
- // --------------------------------------------------------
- // --------------------------------------------------------
- // --------------------------------------------------------
- // --------------------------------------------------------
- class JannysMinionClass {
- float myAge;
- PVector myOrigin, myPosition, myVelocity, myTarget, myDistance, myRotate; // (x,y) myOrigin.x /myPosition.y
- float mySize = minionSize;
- int myHue = 255;
- int mySaturation = 0;
- float myBrightness = 255;
- color checkColor;
- // Contructor (similar to SETUP. Only runs once when the instance is "born")
- JannysMinionClass(float xTemp, float yTemp) {
- myAge = 0;
- myOrigin = new PVector(xTemp, yTemp);
- myPosition = new PVector(xTemp, yTemp);
- myTarget = new PVector(xTemp, yTemp);
- myDistance = new PVector(0, 0);
- //myVelocity = new PVector(0, 0); // no velocity
- myVelocity = new PVector(random(-100,100), random(-100,100));
- mySize = minionSize;
- myHue = 255;
- mySaturation = 0;
- myBrightness = 255;
- }
- // Custom method for updating the variables
- void myUpdate() {
- //myRandomGray();
- //myVelocity();
- //myGrow();
- //if (myNearMouse()) myRandomGray();
- //if (myNearMouse()) myGrow(); else myShrink(); //janny testing silky
- //if (myNearMouse()) myGrow(); else myGoHome();
- if (myNearMouse()) myVelocity();
- //if (myNearMouse()) mySize = random(1,30); else myGoHome();
- if (myNearMouse()) myGrow(); else myGoHome(); //how to rotate each element?
- //if (myNearMouse()) mySize =random(1,70); else myShrink(); // janny testing
- //jmgSaveFrames();
- myAge++;
- checkColor = jannysBackgroundPGraphic.get(int(myPosition.x), int(myPosition.y));
- }
- // Custom method for drawing the object
- void myDisplay() {
- jannysForegroundPGraphic.beginDraw();
- jannysForegroundPGraphic.noStroke();
- jannysForegroundPGraphic.fill(myBrightness);
- jannysForegroundPGraphic.rect(myPosition.x, myPosition.y, 2*mySize, mySize);
- jannysForegroundPGraphic.rotate(PI/2.0);//janny try to rotate
- jannysForegroundPGraphic.endDraw();
- }
- void myRandomGray() {
- myBrightness = int(random(255));
- }
- void myVelocity() {
- myPosition.x += myVelocity.x;
- myPosition.y += myVelocity.y;
- }
- Boolean myNearMouse() {
- distanceToMouse = dist(myPosition.x, myPosition.y, mouseX, mouseY);
- if (distanceToMouse < 90) {
- return true;
- } else {
- return false;
- }
- }
- ///////////////
- void myGrow() {
- //if (mySize>minionSizeMax) mySize = minionSizeMax;
- if (mySize>50) mySize = 50;//janny testing silky
- else mySize++;
- }
- void myShrink() {
- //if (mySize<minionSizeMin) mySize = minionSizeMin;
- if (mySize<50) mySize = 50;//janny testing silky
- else mySize--;
- }
- // This function moves the Module away from the mouse
- // if it is within a certain distance
- void myAvoidMouse() {
- myTarget.x = mouseX;
- myDistance.x = myTarget.x - myPosition.x;
- myPosition.x -= myDistance.x * minionEasingSlow;
- myTarget.y = mouseY;
- myDistance.x = myTarget.y - myPosition.y;
- myPosition.y -= myDistance.x * minionEasingSlow;
- }
- // This function moves the Module back towards it's point of orgin
- void myGoHome() {
- myTarget.x = myOrigin.x;
- myDistance.x = myTarget.x - myPosition.x;
- myPosition.x += myDistance.x * minionEasingFast;
- myTarget.y = myOrigin.y;
- myDistance.x = myTarget.y - myPosition.y;
- myPosition.y += myDistance.x * minionEasingFast;
- }
- }
- //// This function saves a png of the current frame. Calling this
- //// function on everyframe will give you all the frames you need
- //// to make a video using Processing's "Movie Maker"
- //void jjSaveFrames(){
- // saveFrame("frames/####.png");
- //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement