// (c) Alex McLean 2005 // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. class Thing { LinkedList spots = new LinkedList(); private color colour; private float age; private float maxAge; private float intensity; private float direction; private String directionEnv; private float childishness; private float speed; private String speedEnv; private PImage image; private String source; private int spotSize = 3; private float volume, width, length; private float x, y; private Envelope brightEnvelope; private int reverb; private float curve; public Thing(float x, float y, float speed, float direction, float volume, float width, float length, int reverb, float curve, Envelope brightEnvelope, String imageFn ) { age = 0; maxAge = 30; setSpeed(speed); setDirection(direction); this.x = x; this.y = y; this.volume = volume; this.width = width; this.reverb = reverb; this.curve = curve; this.length = length; this.brightEnvelope = brightEnvelope; if (! imageFn.equals("")) { image = (PImage) images.get(imageFn); if (image == null) { image = loadImage("/home/alex/Desktop/input/" + imageFn + ".jpg"); images.put(imageFn, image); } } addSpot(x, y, volume); } public void tick() { move(); age++; } public void draw() { float point = age / maxAge; Iterator iterator = spots.iterator(); float bright = brightEnvelope.value(point); int spotSize = spots.size(); //println(spotSize); for (int i = 0; i < spotSize; ++i) { color colour = image2colour(float(i) / spotSize); int r = int(red(colour) * bright); int g = int(green(colour) * bright); int b = int(blue(colour) * bright); //println(bright); colour = color(r, g, b); fill(colour); Spot spot = (Spot) iterator.next(); spot.draw(); } } public float getX () { return(this.x); } public float getY () { return(this.y); } public void setX(float x) { this.x = x; } public void setY(float y) { this.y = y; } public Spot spot () { return((Spot) spots.getLast()); } private Spot addSpot(float x, float y, float spotSize) { Spot spot = new Spot(x, y, int(spotSize)); spots.add(spot); if (spots.size() >= reverb) { spots.removeFirst(); } return(spot); } public void move () { float hyp = speed; float opp = sin(direction) * hyp; float adj = cos(direction) * hyp; x += opp; y += adj; float offset = sin((PI / length) * age); float offdir = sin(direction + PI / 2); float spotX = x + sin(offdir) * width * offset; float spotY = y + cos(offdir) * width * offset; addSpot(spotX, spotY, volume); direction += curve; } public color image2colour(float offset) { color result; if (image != null) { float point = age / maxAge; float x = int(point * (image.width - 1)); float y = int(offset * (image.height - 1)); result = image.get(int(x), int(y)); } else { result = color(255); } return(result); } public void setSpeed(float speed) { this.speed = speed; this.speedEnv = null; } public void setSpeed(String speed) { this.speedEnv = speed; this.speed = 0; } public void setMaxAge(float maxAge) { this.maxAge = maxAge; } public void setIntensity(float intensity) { this.intensity = intensity; } public void setChildishness(float childishness) { this.childishness = childishness; } public void setDirection(float direction) { this.direction = direction; this.directionEnv = null; } public boolean isExpired() { return(age > maxAge); } }