Processing Forum
The constructor (MYsketchName.Cover, String) is undefined.
code below (highlighted changed/added parts):
- /**
- Quick Cover Flow in Processing
- by Adrià Navarro http://adrianavarro.net
- USING: 3D (openGL), events (controlp5) and animation (ani)
- TODO: image resize, background image loading
- */
- import controlP5.*;
- import processing.opengl.*;
- import de.looksgood.ani.*;
- import java.io.*;
- import java.util.Arrays;
- import java.util.Comparator;
- import gifAnimation.*;
- ControlP5 controlP5;
- Button bNext, bPrev;
- Slider slider;
- //image path where all images are stored
- String path = "../images/";
- //create Arraylist of covers
- ArrayList<Cover> covers;
- PImage imgMask;
- PImage imgShadow;
- Ani coverAnimation;
- float ANI_TIME = 0.5;
- int selectedCover = 0;
- /* -------------- INIT -------------- */
- void setup() {
- size(800, 400, OPENGL);
- smooth();
- noStroke();
- //read filepath
- File folder = new File(dataPath(path));
- //filters jpgs
- File[] initialfiles = folder.listFiles(jpgFilter);
- //sorts files by modification date
- Comparator<File> byModificationDate = new ModificationDateCompare();
- Arrays.sort(initialfiles, byModificationDate);
- imgMask = loadImage("mask.png");
- imgShadow = loadImage("shadow.png");
- // Init interface controlP5
- controlP5 = new ControlP5(this);
- bPrev = controlP5.addButton("Prev",-1, 20, 360, 80, 20); // ((theName, theValue, theX, theY, theW, theH);
- bNext = controlP5.addButton("Next", 1, width-100, 360, 80, 20);
- //slider = controlP5.addSlider("slider", 0, 200, selectedCover, 120, 360, width - 240, 20); // (theName, theMin, theMax, theDefaultValue, theX, theY, theW, theH);
- //slider.setLabelVisible(false);
- //controlP5.setAutoDraw(false);
- // Init Ani
- Ani.init(this);
- // Init covers
- covers = new ArrayList<Cover>();
- //Add covers to from initialfiles
- for (int i=0; i<initialfiles.length; i++ ) {
- covers.add(new Cover(initialfiles[i].getAbsolutePath()));
- }
- //println(covers);
- initCovers();
- }
- /* -------------- DRAW LOOP -------------- */
- void draw() {
- background(0);
- hint(ENABLE_DEPTH_TEST);
- boolean newimage = checkForImage(covers.size());
- if (newimage) {
- newimage = false;
- }
- // move to the center to have easier coordinates
- pushMatrix();
- translate(width / 2, 200 );
- for( int i=0; i<covers.size(); i++ ) {
- covers.get(i).drawCover();
- }
- popMatrix();
- // disable depth test to draw control interface on top of everything
- hint(DISABLE_DEPTH_TEST);
- image(imgShadow, 0.0, 0.0);
- //controlP5.draw(); //needed if we draw with p3d
- }
- /* -------------- EVENT MANAGEMENT -------------- */
- public void controlEvent(ControlEvent theEvent) {
- // Check where the event comes from
- if (theEvent.controller().name() == "slider" ) { // slider
- selectedCover = round(theEvent.controller().value());
- }
- else { // buttons
- selectedCover += (int) theEvent.controller().value();
- //slider.setValue(selectedCover);
- }
- //println(names);
- // Lock buttons if we are in the first or last cover
- if ( selectedCover == covers.size() ) {
- selectedCover --;
- bNext.lock();
- }
- else if ( selectedCover < 0 ) {
- selectedCover ++;
- bPrev.lock();
- }
- else {
- bNext.unlock();
- bPrev.unlock();
- }
- //Call Animation
- moveCovers();
- }
- /* -------------- ANIMATION TWEENS -------------- */
- public void initCovers() {
- covers.get(0).position.set(0.0 - 0.0, 0.0, 75.0);
- covers.get(0).rotationY = 0.0;
- for (int i=1; i<covers.size(); i++ ) {
- covers.get(i).position.set(150.0 + 25.0*i, 0.0, 0.0);
- covers.get(i).rotationY = -QUARTER_PI;
- }
- }
- public void moveCovers() {
- // left covers
- for (int i=0; i<selectedCover; i++ ) {
- Ani.to(covers.get(i).position, ANI_TIME, "x", -150.0 - 25.0*(selectedCover-i), Ani.CIRC_OUT);
- Ani.to(covers.get(i).position, ANI_TIME, "y", 0.0, Ani.CIRC_OUT);
- Ani.to(covers.get(i).position, ANI_TIME, "z", 0.0, Ani.CIRC_OUT);
- Ani.to(covers.get(i), ANI_TIME, "rotationY", QUARTER_PI, Ani.CIRC_OUT);
- }
- // central cover
- coverAnimation = Ani.to(covers.get(selectedCover).position, 0.5, "x", 0.0, Ani.CIRC_OUT);
- Ani.to(covers.get(selectedCover).position, ANI_TIME, "y", 0.0, Ani.CIRC_OUT);
- Ani.to(covers.get(selectedCover).position, ANI_TIME, "z", 75.0, Ani.CIRC_OUT);
- Ani.to(covers.get(selectedCover), ANI_TIME, "rotationY", 0.0, Ani.CIRC_OUT);
- // right covers
- for (int i=selectedCover + 1; i<covers.size(); i++ ) {
- Ani.to(covers.get(i).position, ANI_TIME, "x", 150.0 + 25.0*(i-selectedCover), Ani.CIRC_OUT);
- Ani.to(covers.get(i).position, ANI_TIME, "y", 0.0, Ani.CIRC_OUT);
- Ani.to(covers.get(i).position, ANI_TIME, "z", 0.0, Ani.CIRC_OUT);
- Ani.to(covers.get(i), ANI_TIME, "rotationY", -QUARTER_PI, Ani.CIRC_OUT);
- }
- }
- boolean checkForImage(int number) {
- File folder = new File(dataPath(path));
- File[] files = folder.listFiles(jpgFilter);
- //sorts files by modification date
- Comparator<File> byModificationDate = new ModificationDateCompare();
- Arrays.sort(files, byModificationDate);
- if (files.length > number) {
- for (int i=number; i<files.length; i++ ) {
- covers.add(new Cover(files[i].getAbsolutePath()));
- }
- return true;
- }
- else {
- return false;
- }
- }
- class ModificationDateCompare implements Comparator<File> {
- public int compare(File f1, File f2) {
- return Long.valueOf(f1.lastModified()).compareTo(f2.lastModified());
- }
- }
- FilenameFilter jpgFilter = new FilenameFilter() {
- boolean accept(File dir, String name) {
- return name.toLowerCase().endsWith(".gif");
- }
- };
and the Cover Class:
- /**
- Quick Cover Flow in Processing
- by Adrià Navarro http://adrianavarro.net
- USING: 3D (openGL), events (controlp5) and animation (ani)
- TODO: image resize, background image loading
- */
- class Cover {
- PVector position;
- float rotationY;
- int transparency;
- //PImage img;
- Gif img;
- Cover( String name ) {
- this.position = new PVector(0.0, 0.0, 0.0);
- this.rotationY = 0.0;
- this.transparency = 255;
- // this.img = loadImage(name); /* original working line */
- img = new Gif(this, name);
- img.loop();
- img.play();
- }
- public void drawCover() {
- pushMatrix();
- translate(position.x, position.y, position.z);
- rotateY(rotationY);
- // Main quad
- noTint();
- beginShape();
- textureMode(NORMAL);
- texture(img);
- vertex(-100, -100, 0, 0, 0);
- vertex(100, -100, 0, 1, 0);
- vertex(100, 100, 0, 1, 1);
- vertex(-100, 100, 0, 0, 1);
- endShape();
- // Reflection
- tint(50);
- beginShape();
- textureMode(NORMAL);
- texture(img);
- vertex(-100, 100, 0, 0, 1);
- vertex(100, 100, 0, 1, 1);
- vertex(100, 300, 0, 1, 0);
- vertex(-100, 300, 0, 0, 0);
- endShape();
- noTint();
- popMatrix();
- }
- // Function to call if images are not square
- // Not being used at the moment, might need some tweaking
- public void resizeImage(PImage img) {
- float ratio = 0.0;
- int newWidth = 0;
- int newHeight = 0;
- ratio = (float)img.width / (float)img.height;
- if( ratio > 1 ) { // img is wider than tall
- newWidth = 255;
- newHeight = (int) (255.0/ratio);
- }
- else { // img is taller than wide
- newHeight = 255;
- newHeight = (int)(255.0*ratio);
- }
- println ("width: " + newWidth + "height: " + newHeight + "ratio: " + ratio);
- img.resize(newWidth,newHeight);
- }
- }
- loadPixels();
- // Loop through every pixel column
- for (int x = 0; x < width; x++) {
- // Loop through every pixel row
- for (int y = 0; y < height; y++) {
- // Use the formula to find the 1D location
- int loc = x + y * width;
- if (x % 2 == 0) { // If we are an even column
- pixels[loc] = color(255);
- } else { // If we are an odd column
- pixels[loc] = color(0);
- }
- }
- }
- updatePixels()
I was thinking of this, but just unclear on how to just get a general average of all