///////////////////////////////////////////////////////////// // // polygon screensaver // // -= by =- // // miles zarathustra // ///////////////////////////////////////////////////////////// // // after an algorithm shown to me by david kaufman at // the "people's computer center" in the 1970's. // the basic program was then called: "dangling string." // // these names are used throughout: // // sides: how many sides the polygon has // // center: center of gravity // gravity: amount of pull exerted by center // 0 color changes about every // th time. // // delay: delay in milliseconds // import java.applet.*; import java.awt.*; import java.net.*; import java.util.*; // a point which orbits 1-dimensionally around its center // class orbiter { // predictable position & motion protected int center, here; protected double velocity, acceleration, gravity; // random factor, & limiting protected double maxVel,minVel; protected double jostling; // gravity will typically be 0 < g < 1 // orbiter(int center, int here, double gravity, double jostling, double maxVel) { this.center=center; this.here=here; this.gravity=gravity; this.velocity=0; this.jostling=jostling; this.maxVel=Math.abs(maxVel); this.minVel= -maxVel; accelerate(); } orbiter() { center=0; here=0; gravity=0; velocity=0; acceleration=0; jostling=0; maxVel=0; minVel=0; } // standard velocity formula. // the properties of this "gravity" are our own invention. protected void move() { here += velocity; } protected void gravitate() { acceleration = (center - here) * gravity; } protected void accelerate() { velocity += acceleration; } // randomize, in a controlled way protected void jostle() { acceleration *= jostling*Math.random()+ .5*jostling; } protected void govern() { if (velocitymaxVel) velocity=maxVel; } int nextVal() { move(); gravitate(); jostle(); accelerate(); govern(); return here; } // java 'memcpy' void copy(orbiter o) { acceleration =o.acceleration; center =o.center; gravity =o.gravity; here =o.here; jostling =o.jostling; maxVel =o.maxVel; minVel =o.minVel; velocity =o.velocity; } } // a polygon (solar system?) of orbiters // class planets { Color color; double colorChange; orbiter x[],y[]; int sides; planets(int sides, int center, double gravity, double jostling, double maxVel, double colorChange, Color color) { this.sides=sides; x=new orbiter[sides]; y=new orbiter[sides]; for (int i=0; i0; --i) { ary[i].copy(ary[i-1]); } } // draw next one, & undraw last void next(Graphics g) { planets last=ary[howmany-1]; last.color=poly.bgcolor; last.paint(g); shift(); ary[0].next(g); } // redraw all void paint(Graphics g) { for (int i=0; i