Monday, February 16, 2009

Homework #4


For this program, I already had a MyMatrix class for Scientific Computing that I made that could handle the matrix multiplication, so I used that.
import processing.core.*;
public class Homework4 extends PApplet{
int x0=100;
int y0=100;
int x1=200;
int y1=175;
int x2=330;
int y2=175;
double rotDeg = 20;
MyMatrix test;

public void setup(){
size(410,410);
background(255);
stroke(0,0,0);
//triangle(x0,y0,x1,y1,x2,y2);
//myRotate(rotDeg);
//triangle(x0,y0,x1,y1,x2,y2);

for(int i = 0; i < 18; i++){
triangle(x0,y0,x1,y1,x2,y2);
myRotate(rotDeg);
}
}
public int[] centrePoint(int cx0, int cy0, int cx1, int cy1, int cx2, int cy2){
int[] result = new int[2];

result[0] = Math.round((1f/3f)*(x0+x1+x2));

result[1] = Math.round((1f/3f)*(y0+y1+y2));
return result;
}

public void draw(){

}

public void myRotate(double theta){

theta = (theta/360.)*(2*Math.PI);

float[][] m = new float[2][2];
int [] cp = centrePoint(x0,y0,x1,y1,x2,y2);
m[0][0] = Float.parseFloat((Double.toString(Math.cos(theta))));
m[0][1] = Float.parseFloat((Double.toString(Math.sin(theta))));
m[1][1] = Float.parseFloat((Double.toString(Math.cos(theta))));
m[1][0] = Float.parseFloat((Double.toString(-1.0*Math.sin(theta))));



MyMatrix rotMat = new MyMatrix(m.clone());
//rotMat.print();
MyMatrix vector;
MyMatrix temp;
float [][] arr = new float[2][1];
//p0
arr[0][0] = x0-cp[0];
arr[1][0] = y0-cp[1];

vector = new MyMatrix(arr.clone());
temp = new MyMatrix(rotMat.multiply(vector).theMatrix.clone());

x0 = Math.round(temp.theMatrix[0][0])+cp[0];
y0 = Math.round(temp.theMatrix[1][0])+cp[1];
//System.out.println(x0+","+y0);
//p1
arr[0][0] = x1-cp[0];
arr[1][0] = y1-cp[1];

vector = new MyMatrix(arr.clone());
temp = new MyMatrix(rotMat.multiply(vector).theMatrix.clone());

x1 = Math.round(temp.theMatrix[0][0])+cp[0];
y1 = Math.round(temp.theMatrix[1][0])+cp[1];
//System.out.println(x1+","+y1);
//p2
arr[0][0] = x2-cp[0];
arr[1][0] = y2-cp[1];

vector = new MyMatrix(arr.clone());
temp = new MyMatrix(rotMat.multiply(vector).theMatrix.clone());

x2 = Math.round(temp.theMatrix[0][0])+cp[0];
y2 = Math.round(temp.theMatrix[1][0])+cp[1];
//System.out.println(x2+","+y2);

}

}

Thursday, February 5, 2009

Homework #3

I have yet to figure out posting java applets on blogger, although I have heard from my colleagues that that isn't really done here. I'll try to look into it some more, but for now, I have my .class files posted on a Google Groups page. The link is here:

http://groups.google.com/group/bjy3120csc340/files?hl=en


As of this post, I am still working on the line clipping exercise. After some debugging, I have found that a lot of my problems probably extend (at least partially) from confusion from translating the algorithm to work with the upside-down way that drawing in Processing works.

As for my project proposal:

I am interested in using recursion to draw and create pattern. I would like the user to be able to interact with the program to change how the program recurses, perhaps by moving their mouse or pressing keys; I want to make something that makes people want to play with it and try to figure out what each button they press or action they perform with their mouse will do.

Here are a few Processing projects I liked:

http://www.flickr.com/photos/lennyjpg/744505138/
http://www.youtube.com/watch?v=dJfIMPREQ8A
http://www.flickr.com/photos/njmcgee/456231707/