1 16 17 package com.j2biz.pencil.examples.simpleClient; 18 19 import java.awt.Canvas ; 20 import java.awt.Color ; 21 import java.awt.Frame ; 22 import java.awt.Graphics ; 23 import java.awt.image.BufferedImage ; 24 25 import com.j2biz.log.LOG; 26 27 32 public class PlasmaAnimation extends Canvas { 33 34 35 static { 36 String className = PlasmaAnimation.class.getName(); 37 LOG.trace( "initialize plazma-class: ${className}" ); 38 } 39 40 private static final int MAXX = 199; 41 42 private static final int MAXY = 199; 43 44 47 private static double C = 100; 48 49 private static double F = 67; 50 51 private static double I = 32; 52 53 private static double L = 8; 54 55 private double time1 = C; 56 57 private double time2 = F; 58 59 private double time3 = I; 60 61 private double time4 = L; 62 63 private double angle3 = time3; 64 65 private double angle4 = time4; 66 67 private double angle1 = time1; 68 69 private double angle2 = time2; 70 71 Thread t; 72 73 private double[] cosTable = new double[256]; 74 75 { 76 LOG.debug( "prepare color-table" ); 77 78 for (int i = 0; i < cosTable.length; i++) { 79 double colorValue = 32 + 32 * Math.cos(i * 2 * Math.PI / 256); 80 cosTable[i] = colorValue; 81 LOG.trace( "index[${i}] == ${colorValue}" ); 82 } 83 } 84 85 public void start() { 86 t = new Thread () { 87 88 91 public void run() { 92 try { 93 while (true) { 94 PlasmaAnimation.this.repaint(); 95 Thread.sleep(100); 96 } 97 } catch (InterruptedException e) { 98 e.printStackTrace(); 99 System.exit(-1); 100 } 101 } 102 }; 103 104 t.start(); 105 } 106 107 public static void main(String args[]) { 108 LOG.trace(""); 109 110 int mod = 4 % 2; 111 112 114 Frame frame = new Frame ("plasme, baby!"); 115 frame.setSize(MAXX + 1, MAXY + 1); 116 117 PlasmaAnimation anim = new PlasmaAnimation(); 118 frame.add(anim); 119 frame.setVisible(true); 120 121 anim.start(); 122 } 123 124 BufferedImage img = new BufferedImage ( MAXX+1, MAXY+1,BufferedImage.TYPE_INT_RGB ) ; 125 126 129 private void paintImg(Graphics g) { 130 angle3 = time3; 131 angle4 = time4; 132 133 for (int y = 0; y <= MAXY; y++) { 134 angle1 = time1; 135 angle2 = time2; 136 for (int x = 0; x <= MAXX; x++) { 137 double color = this.cosTable[(int) Math.round(angle1) & 255] + this.cosTable[(int) Math.round(angle2) & 255] 138 + cosTable[(int) Math.round(angle3) & 255] + cosTable[(int) Math.round(angle4) & 255]; 139 140 g.setColor( new Color ((int) color) ); 141 g.drawLine( x, y, x, y); 142 angle1 += A; 143 angle2 += D; 144 } 145 146 angle3 += G; 147 angle4 += J; 148 } 149 150 time1 += B; 151 time2 += E; 152 time3 += H; 153 time4 += K; 154 } 155 156 159 public void paint(Graphics g) { 160 paintImg( g ); 163 } 164 165 private static double A = 12; 166 private static double D = 4; 167 private static double J = 46; 168 private static double B = 123; 169 private static double E = 67; 170 private static double H = 76; 171 private static double K = 12; 172 private static double G = 3; 173 174 } | Popular Tags |