


Finally got OpenGL to work. Reinstalled Eclipse and downloaded a different C compiler. Still can't get gltools to work.
A blog of my coursework for CSC 370 (Computer Graphics) at UNCW.
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);
}
}
public void setup(){
size(250,300);
background(0);
}
public void draw(){
stroke(0,255,0);
myCurve(25, 100, 50, 210, 200, 100, 200, 30, 0.01);
stroke(255,0,0);
myCurve(50, 210, 200, 100, 200, 30, 0.01);
stroke(0,0,255);
myCurve(200, 100, 200, 30, 0.01);
}
public void myCurve(int x0, int y0, int x1, int y1, int x2, int y2, double t){
//Quadratic
double x = x0;
double y = y0;
point(x0, y0);
for(double i = t; i <= 1; i+=t){
//System.out.println(i);
x = Math.pow((1.0-i),2)*x0 + 2.0*(1.0-i)*i*x1 + i*i*x2;
y = Math.pow((1.0-i),2)*y0 + 2.0*(1.0-i)*i*y1 + i*i*y2;
point(Math.round(x),Math.round(y));
}
point(x2,y2);
}
public void myCurve(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3, double t){
//cubic
double x = x0;
double y = y0;
point(x0, y0);
for(double i = t; i <= 1; i+=t){
x = Math.pow((1.0-i),3)*x0 + Math.pow((1-i),2)*3*i*x1 + Math.pow((1-i),2)*3*i*i*x2 + i*i*i*x3;
y = Math.pow((1.0-i),3)*y0 + Math.pow((1-i),2)*3*i*y1 + Math.pow((1-i),2)*3*i*i*y2 + i*i*i*y3;
point(Math.round(x),Math.round(y));
}
point(x3, y3);
}
public void myCurve(int x0, int y0, int x1, int y1, double t){
//linear
double x = x0;
double y = y0;
point(x0, y0);
for(double i = 0; i <= 1; i+=t){
x += (x1-x0)*t;
y += (y1-y0)*t;
point(Math.round(x),Math.round(y));
}
point(x1, y1);
}
public void myLine(int x0, int y0, int x1, int y1, double t){
double x = x0;
double y = y0;
for(double i = 0; i <= 1; i+=t){
if(i == 0){
point(x0, y0);
}else if (i == 1){
point(x1, y1);
}else{
x+= (x1-x0)*t;
y+= (y1-y0)*t;
point(Math.round(x),Math.round(y));
}
}
}
//Programmed by Brett J. Young
//Creates a house
import processing.core.*;
public class Driver extends PApplet{
public void setup(){
size(250,300);
background(0,100,210);
}
public void draw(){
stroke(255);
myLine(20,230,100,120);
stroke(100);
myWeb(135,7);
stroke(0);
myCircle(150,150,20);
}
public void myCircle(int x0, int y0, int rad){
int f = 1 - rad;
int dx = 1;
int dy = -2 * rad;
int x = 0;
int y = rad;
point(x0, y0 + rad);
point(x0, y0 - rad);
point(x0 + rad, y0);
point(x0 - rad, y0);
while(xif(f >= 0){
y--;
dy += 2;
f += dy;
}
x++;
dx += 2;
f += dx;
point(x0 + x, y0 + y);
point(x0 - x, y0 + y);
point(x0 + x, y0 - y);
point(x0 - x, y0 - y);
point(x0 + y, y0 + x);
point(x0 - y, y0 + x);
point(x0 + y, y0 - x);
point(x0 - y, y0 - x);
}
}
public void myWeb(int size, int step){
for(int i = 0; i < size; i+=step){
int q = size - i;
myLine(0,q,i,0);
}
}
public void myLine(int xa, int ya, int xb, int yb){
int x0 = xa;
int x1 = xb;
int y0 = ya;
int y1 = yb;
boolean steep = (Math.abs(y1 - y0) > Math.abs(x1 - x0));
if(steep){
//swap(x0, y0)
x0 = ya;
y0 = xa;
//swap (x1,y1)
x1 = yb;
y1 = xb;
if(x0>x1){
//swap(x0,x1)
x0 = yb;
x1 = ya;
//swap (y0,y1)
y0 = xb;
y1 = xa;
}
}
else if(x0>x1){
//swap(x0,x1)
x0 = xb;
x1 = xa;
//swap (y0,y1)
y0 = yb;
y1 = ya;
}
int deltax = x1 - x0;
int deltay = Math.abs(y0 - y1);
double error = 0;
double deltaerror = (Double)(1.0 * deltay) / deltax;
int ystep;
int y = y0;
if(y0 < y1){
ystep = 1;
}else{
ystep = -1;
}
for(int x = x0; x < x1; x++){
if(steep){
point(y,x);
}else{
point(x,y);
}
error += deltaerror;
if(error >= 0.5){
y += ystep;
error -= 1.0;
}
}
}
}