import processing.core.*; 
import processing.xml.*; 

import java.applet.*; 
import java.awt.*; 
import java.awt.image.*; 
import java.awt.event.*; 
import java.io.*; 
import java.net.*; 
import java.text.*; 
import java.util.*; 
import java.util.zip.*; 
import java.util.regex.*; 

public class AtanTex3 extends PApplet {


//import processing.opengl.*;

 

int W = 400;
int H = 400;
int SIZE = W * H;

int pointNum = 7;
Point[] points = new Point[pointNum];

int col = 0;
int[] oxp = new int[SIZE];
int[] oyp = new int[SIZE];
float[] angp = new float[SIZE*pointNum];

public void setup(){
  size(400, 400, P3D);
  
  for (int i = 0; i<pointNum; i++) points[i] = new Point(random(width), random(height));
  
   int inc = 0;
   for (int i = 0; i < SIZE; i++){
    oxp[i] = i / width;
    oyp[i] = i % width;
    
    col = 0;
    for (int j = 0; j < points.length; j++){
      angp[inc] = atan2(oyp[i] - points[j].y, oxp[i] - points[j].x);
      inc++;
    }
  }
  
}

public void draw(){
  loadPixels();
   
  int inc = 0;
  
  float mx = 1 / Math.max(.0001f,mouseX);
  
  for (int i = 0; i < SIZE; i++){
   
    
    col = 0;

    
     float a1 = (oxp[i]) * mx;
     col += Math.max(0, 255 * Math.cos(angp[inc] * a1)) ; 
     inc++;
       col += Math.max(0, 255 * Math.cos(angp[inc] * a1)) ;
     inc++;
       col += Math.max(0, 255 * Math.cos(angp[inc] * a1)) ;
     inc++;
       col += Math.max(0, 255 * Math.cos(angp[inc] * a1)) ;
     inc++;
       col += Math.max(0, 255 * Math.cos(angp[inc] * a1))  ;
     inc++;
       col += Math.max(0, 255 * Math.cos(angp[inc] * a1)) ; 
     inc++;
       col += Math.max(0, 255 * Math.cos(angp[inc] * a1)) ;
     inc++;
   
     
     col *= .1f;
      
     
    pixels[i] = 0xFF000000 | col << 16 | col << 8 | col;
  }
  
  
  updatePixels();
  
}

class Point{
 float x=0;
 float y=0; 
 
 Point(){};
 
 Point(float x, float y){
   this.x = x;
   this.y = y;
 }
}

/*var outcoord:Point = new Point();
var col:int, i:int, j:int;
 
var a:Number = 0;
var s:int = 1000;
var points:Vector.<Point> = new Vector.<Point>();
for (i = 0; i<5; i++) points.push(new Point(int(Math.random()*s),int(Math.random()*s)));

var canvas:BitmapData = new BitmapData(s,s, false, 0xFF0000);
addChild(new Bitmap(canvas, "auto", true));

var size:int = canvas.width * canvas.height;
for (i  = 0; i<size; i++){
	outcoord.x = i % canvas.width;
	outcoord.y = i / canvas.width;
	
	col = 0
	for (j= 0; j<points.length; j++){
		a = Math.atan2(outcoord.y - points[j].y, outcoord.x - points[j].x) ;
		col += Math.max(0,255 * Math.cos(a*outcoord.y/50) );
	}
	 
	 col /= points.length;

	
	 canvas.setPixel(outcoord.x, outcoord.y,  col << 16 |  col << 8|  col);
}*/

  static public void main(String args[]) {
    PApplet.main(new String[] { "--bgcolor=#ffffff", "AtanTex3" });
  }
}
