import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.io.IOException;
import java.util.Random;

public class PattPPM {
  
  static Random rng = new Random();
  

  
  public static void main(String[] args) throws IOException {
    
    int xRes=256, yRes=256;
    
    
    File f = new File("C:\\temp\\patt.ppm");
    FileOutputStream fout = new FileOutputStream(f);
    PrintStream out = new PrintStream(fout);
    
    // header
    out.println("P3\r\n" + xRes + " " + yRes + "\r\n255\r\n"); // P2 xres yres maxval
    
    // pixel data: RGB triplets, each value 0..255
    for(int y=0;y<yRes;y++) {
      for(int x=0;x<xRes;x++) {
               
        Pixel pxl = new Pixel();
        pxl.r = (x+y)%256;
        
        // uncomment each block below in sequence,
        // watch a pattern build up!
        
        /*double sn = Math.sin(0.1*x+y);
        sn = 255*(1+sn)*0.5;
        pxl.r = (int) sn;*/
        
        /*double sn2 = Math.sin(-0.1*x+y);
        sn2 = 255*(1+sn2)*0.5;
        pxl.g = (int) sn2;*/
        
        /*double sn3 = Math.sin(0.1*x-0.2*y);
        sn3 = 255*(1+sn3)*0.5;
        pxl.b = (int) sn3;*/
        
        // output to file
        out.println(pxl.r + " " + pxl.g + " " + pxl.b);
        
      }// next x
    }// next y
    
    // done, close
    out.close();
  }// main()
  
  // static inner class 
  private static class Pixel {
    int r=0, g=0, b=0;
  }// class Pixel
  
}// class PattPPM


