void setup(){ Tree tree = new Tree(this); } class Tree{ public Tree(PApplet sketch){ float x = sketch.random(100); } }
/** * Randomize the list order using the random() function from the specified * sketch, allowing shuffle() to use its current randomSeed() setting. */ public void shuffle(PApplet sketch) { int num = count; while (num > 1) { int value = (int) sketch.random(num); num--; float temp = data[num]; data[num] = data[value]; data[value] = temp; } }
/** * Randomize the list order using the random() function from the specified * sketch, allowing shuffle() to use its current randomSeed() setting. */ public void shuffle(PApplet sketch) { int num = count; while (num > 1) { int value = (int) sketch.random(num); num--; int temp = data[num]; data[num] = data[value]; data[value] = temp; } }
/** * Randomize the list order using the random() function from the specified * sketch, allowing shuffle() to use its current randomSeed() setting. */ public void shuffle(PApplet sketch) { int num = count; while (num > 1) { int value = (int) sketch.random(num); num--; float temp = data[num]; data[num] = data[value]; data[value] = temp; } }
/** * Randomize the list order using the random() function from the specified * sketch, allowing shuffle() to use its current randomSeed() setting. */ public void shuffle(PApplet sketch) { int num = count; while (num > 1) { int value = (int) sketch.random(num); num--; int temp = data[num]; data[num] = data[value]; data[value] = temp; } }
/** * Randomize the list order using the random() function from the specified * sketch, allowing shuffle() to use its current randomSeed() setting. */ public void shuffle(PApplet sketch) { int num = count; while (num > 1) { int value = (int) sketch.random(num); num--; String temp = data[num]; data[num] = data[value]; data[value] = temp; } }
/** * Randomize the list order using the random() function from the specified * sketch, allowing shuffle() to use its current randomSeed() setting. */ public void shuffle(PApplet sketch) { int num = count; while (num > 1) { int value = (int) sketch.random(num); num--; String temp = data[num]; data[num] = data[value]; data[value] = temp; } }
/** * Return a random number in the range [howsmall, howbig). * <p/> * The number returned will range from 'howsmall' up to * (but not including 'howbig'. * <p/> * If howsmall is >= howbig, howsmall will be returned, * meaning that random(5, 5) will return 5 (useful) * and random(7, 4) will return 7 (not useful.. better idea?) */ public final float random(float howsmall, float howbig) { if (howsmall >= howbig) return howsmall; float diff = howbig - howsmall; return random(diff) + howsmall; }
import processing.core.*; public class Site { public static final int COUNT = 8; public static final int MAX_VEL = 2; public static final int MARKER_SIZE = 6; PApplet parent; float x, y; PVector vel; int c; Site(PApplet p) { parent = p; vel = new PVector( parent.random(-MAX_VEL, MAX_VEL), parent.random(-MAX_VEL, MAX_VEL) ); } }
value = random(diff) + low; } while (value == high); return value;
/** * Make a new 3D unit vector with a random direction * @return the random PVector */ static public PVector random3D(PVector target, PApplet parent) { float angle; float vz; if (parent == null) { angle = (float) (Math.random()*Math.PI*2); vz = (float) (Math.random()*2-1); } else { angle = parent.random(PConstants.TWO_PI); vz = parent.random(-1,1); } float vx = (float) (Math.sqrt(1-vz*vz)*Math.cos(angle)); float vy = (float) (Math.sqrt(1-vz*vz)*Math.sin(angle)); if (target == null) { target = new PVector(vx, vy, vz); //target.normalize(); // Should be unnecessary } else { target.set(vx,vy,vz); } return target; }
/** * Make a new 2D unit vector with a random direction * @return the random PVector */ static public PVector random2D(PVector target, PApplet parent) { if (parent == null) return fromAngle((float)(Math.random()*Math.PI*2),target); else return fromAngle(parent.random(PConstants.TWO_PI),target); }
void initScreenPoints() { screenPoints = new PVector[nbScreenPoints]; pw = this.getDisplay().getWidth(); ph = this.getDisplay().getHeight(); // 1 in each quadrant. // 2 random screenPoints[0] = new PVector(pw / 2, ph / 2, 0); screenPoints[1] = new PVector( parent.random(deadZone, pw / 2 - deadZone), parent.random(deadZone, ph / 2 - deadZone), parent.random(HALF_PI)); screenPoints[2] = new PVector( parent.random(pw / 2 + deadZone, pw - deadZone), parent.random(deadZone, ph / 2 - deadZone), parent.random(HALF_PI)); screenPoints[3] = new PVector( parent.random(deadZone, pw / 2 - deadZone), parent.random(ph / 2 + deadZone, ph - deadZone), parent.random(HALF_PI)); screenPoints[4] = new PVector( parent.random(pw / 2 + deadZone, pw - deadZone), parent.random(ph / 2 + deadZone, ph - deadZone), parent.random(HALF_PI)); for (int i = 5; i < nbScreenPoints; i++) { screenPoints[i] = createRandomPoint(); } }
/** * Make a new 2D unit vector with a random direction. Pass in the parent * PApplet if you want randomSeed() to work (and be predictable). Or leave * it null and be... random. * @return the random PVector */ static public PVector random2D(PVector target, PApplet parent) { return (parent == null) ? fromAngle((float) (Math.random() * Math.PI*2), target) : fromAngle(parent.random(PConstants.TAU), target); }
/** * Make a new 3D unit vector with a random direction * @return the random PVector */ static public PVector random3D(PVector target, PApplet parent) { float angle; float vz; if (parent == null) { angle = (float) (Math.random()*Math.PI*2); vz = (float) (Math.random()*2-1); } else { angle = parent.random(PConstants.TWO_PI); vz = parent.random(-1,1); } float vx = (float) (Math.sqrt(1-vz*vz)*Math.cos(angle)); float vy = (float) (Math.sqrt(1-vz*vz)*Math.sin(angle)); if (target == null) { target = new PVector(vx, vy, vz); //target.normalize(); // Should be unnecessary } else { target.set(vx,vy,vz); } return target; }
float g = ((float) out[1] - y) / mag + 0.5f;// / frameHeight; mapImg.pixels[k++] = parent.color(r, g, parent.random(1f));