import javax.imageio.ImageIO; import java.awt.*; import java.awt.image.*; import java.io.File; import java.io.IOException; class Main { static final int X = 512, Y = 512; static final double pi = Math.PI; static BufferedImage I = new BufferedImage(X, Y, BufferedImage.TYPE_BYTE_GRAY); static int shd(int n){if(n<144) return 0; if(n<160) return (n-144)*0x101010; if(n<305) return 0xffffff; return (320-n)*0x101010;} static public void main( String[] args ){ int deep = Integer.parseInt(args[0]); for (int i = 0; i0) if((n&1)>0) s += Math.cos(n*x)*Math.cos(n*t)/(n*n); int sx = (int)(8./(pi*pi)*s*12*320); I.setRGB(i, j, shd(sx % 320));} Frame f = new Frame( "plucked string" ); f.add("Center", new MainCanvas()); f.setSize(new Dimension(X,Y+22)); f.setVisible(true); if(args.length > 1) try { File file = new File(args[1]); ImageIO.write(I, "png", file );} catch (IOException e) {System.err.println("image not saved.");} }} class MainCanvas extends Canvas{ public void paint(Graphics g){ g.drawImage(Main.I, 0, 0, Color.red, null);}}