// Rose.java - from Gaffer.org import java.applet.Applet; import java.awt.Event; public class Rose extends tinyptc { public Rose () {_scale = 1.0F; _xRot = 0.0F; _yRot = 0.0F;} public String convert (double d, int i) { StringBuffer sb = new StringBuffer (); sb.insert (0, d); if (sb.length () > i) sb.setLength (i); for (; sb.length () < i; sb.append ('0')); return sb.toString (); } public void main (int w, int h) { int pxl [] = new int [w * h]; Render render = new Render (pxl, w, h); Pipeline pipe = new Pipeline (render); pipe.viewport (0.0F, 0.0F, 1.0F, 1.0F); Vertex av [] = new Vertex [8]; av [0] = new Vertex (-1F, -1F, -1F); av [1] = new Vertex ( 1F, -1F, -1F); av [2] = new Vertex ( 1F, 1F, -1F); av [3] = new Vertex (-1F, 1F, -1F); av [4] = new Vertex (-1F, -1F, 1F); av [5] = new Vertex ( 1F, -1F, 1F); av [6] = new Vertex ( 1F, 1F, 1F); av [7] = new Vertex (-1F, 1F, 1F); int ai [] = new int [8*3]; ai [0] = 0; ai [1] = 1; ai [2] = 1; ai [3] = 2; ai [4] = 2; ai [5] = 3; ai [6] = 3; ai [7] = 0; ai [8] = 4; ai [9] = 5; ai [10] = 5; ai [11] = 6; ai [12] = 6; ai [13] = 7; ai [14] = 7; ai [15] = 4; ai [16] = 0; ai [17] = 4; ai [18] = 1; ai [19] = 5; ai [20] = 2; ai [21] = 6; ai [22] = 3; ai [23] = 7; Color black = new Color (0F, 0F, 0F); Color col = new Color (0.08F, 0.05F, 0.05F); WireMesh mesh = new WireMesh (av, ai, col); Timer timer = new Timer (); timer.start (); float f0 = 0.0F; while (true) { for (int k = 0; k < 10; k++) { f0 += 0.01F; float f1 = f0 + 0.02F * (float)( Math.cos ((double)f0 * 0.41D + 0.123D) + Math.cos ((double)f0 * 0.51D + 0.234D) + Math.cos ((double)f0 * 0.61D + 0.623D) + Math.cos ((double)f0 * 0.21D + 0.723D)); float f2 = 0.5F; float f3 = 0.05F * (float)(0.90D + 0.16D * ( Math.cos ((double)f0 * 0.41D + 0.0123D) + Math.cos ((double)f0 * 0.51D + 0.0234D) + Math.cos ((double)f0 * 0.61D + 0.0623D) + Math.cos ((double)f0 * 0.021D + 1.723D))); render.clear (black.pack ()); pipe.additive (true); for (int j1 = 0; j1 < 150; j1++) { pipe.identity (); pipe.projection (-1F, 1.0F, -1F, 1.0F, 1.0F, 10F); pipe.translate (0.0F, 0.0F, 3F); pipe.rotateX (f1 * 0.9F + _xRot); pipe.rotateY (f1 * 1.1F + _yRot); pipe.rotateZ (f1 * 1.2F); pipe.scale (f2 * _scale); mesh.draw (pipe); f1 -= f3; f2 += ((1.2F - 0.5F) / (float)150); } update (pxl); } showStatus (convert ((double)10 / timer.delta (), 5) + " fps"); } } public boolean mouseDown (Event event, int x, int y) { _x = x; _y = y; return true; } public boolean mouseDrag (Event ev, int x, int y) { int dx = x - _x; int dy = y - _y; if (! ev.metaDown ()) { _xRot -= (float)dy * 0.01F; _yRot -= (float)dx * 0.01F; } else { _scale += (float)dy * 0.001F; if (_scale > 1.0F) _scale = 1.0F; if (_scale < 0.6F) _scale = 0.6F; } _x = x; _y = y; return true; } int _x, _y; float _xRot, _yRot, _scale; }