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 FK extends PApplet {


Sprite s;
public void setup(){
  size(500,500,P3D);
  
  noStroke();
  setupLibrary();
  
  s = new Sprite();
 
  s.point(-50, -50);
  s.point(50, -50);
  s.point(50, 50);
  s.point(-50, 50);
  
}

public void draw(){
   
  background(0);
  
  fill(0xFF000000);
  
  s.x = mouseX;
  s.y = mouseY;
  s.rotationZ += .1f;
  
  fill(255,0,0);
  s.render();
  
}
int SIZE = 0;

public void setupLibrary(){
  SIZE = width * height;
}

public void bg(int col){
 loadPixels();
 for (int i = 0; i < SIZE; i++){
   pixels[i] = col;
 }
 updatePixels(); 
}

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

class Sprite {
 
 // translate
 float x=0;
 float y=0;
 float z=0;
  
 // rotate
 float rotationX=0;
 float rotationY=0;
 float rotationZ=0;
 
 // scale
 float scaleX=1;
 float scaleY=1;
 float scaleZ=1;
 
 PImage img;
 
 boolean tex;
 
 Vector points = new Vector();
 
 Sprite(){
   tex = false;
 }
 
 Sprite(PImage t){
  tex = true; 
  img = t;
 }
 
 public void point(float x, float y){
  points.add(new Point(x, y)); 
 }
 
 public void render(){
  pushMatrix();
  translate(x, y, z);
  rotateX(rotationX);
  rotateY(rotationY);
  rotateZ(rotationZ);
  scale(scaleX, scaleY, scaleZ);
 
  beginShape();
   
   if (tex){
     texture(img);
   }
   for (int i = 0; i<points.size(); i++){
    Point p  = (Point) points.get(i);
    vertex(p.x, p.y);
   }
   
   endShape(CLOSE);
 
  popMatrix();
 }
 
 
}

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