Tuesday, May 5, 2009

Project 3: Boids


For project 3, I decided to implement the 3-d boids algorithm. This allows objects to simulate natural flocking behavior using the 3 rules of alignment, cohesion, and separation. My boids represent fish in a fish tank that travel as a school. I also introduced a predator to the tank which the "fish" avoid. I could not get the obj loader library from processing to work, so they are representsed as cubes for now. Here is a screen shot.

Project 2: OBJ Viewer

For project 2, we had to implement a program that would read and display an OBJ file and allow the user to control the camera using OpenGL and C++. Here are some screen shots:































Thursday, March 26, 2009

Wednesday, March 25, 2009

First OpenGL Assignment

After reading the articles posted, I love the way that OpenGL takes advantage of the graphics card by directly accessing its memory and, therefore saving the processor a good amount of work. While this may not be evident in the smaller assignments and projects that we are currently doing, any way to relieve the processor and speed up a program is certainly going to help if programming a game that must use search trees for its AI or any other very time consuming operation. Another great thing about OpenGL seems to be its versatility. It seems rather rare in my limited experience to find a library that can be used in a variety of languages as OpenGL is. Python is hopefully the language that I plan on learning next so I am somewhat excited that what I learn about OpenGL I will be able to use in Python as well. The fact that OpenGL ES can be used for mobile devices further exhibits this versatility, making it a very useful library to know since it can be used in so many platforms. From what I have read, it also appears that many of the commands are relatively straightforward and easy to use. All of this combined has made me excited to learn more.

The second part of this assignment was to create a Bezier curve in OpenGL. The curve rotates when you hit the arrow button.
















Finally, I created a multi-colored 3-d cube. This also rotates when the arrows are pushed. I plan on expanding this tomorrow, but I have this so far so might as well post it.











The basic outline of a house using 3d OpenGGL commands.

Friday, March 6, 2009

Compiling and Running glut on my PC

Here is the simple.cpp program running on my personal computer. (Proof I can get it to work I guess)

Thanks to Michael for the easy to follow step by step instructions.

Project 1: Circles


The purpose of project 1 was to replicate an image by Anthony Mattox that included circles placed within a circular border. Next we had to come up with a variation of that image of our own. The first 3 images are replications, followed by a variety of variations made by creating different color or saturation functions that changed based on the circles position in the image. It took a few days to get this posted due to trying to upload .pdfs of the images with no success, but here they are as .jpegs.







































































































import processing.pdf.*;

float borderDiam=700;
int numCircs=1000000;//change back to at least 1000000
boolean overlap;
int count=0;
Circ[] balls = new Circ[numCircs];
int diameter;
void setup(){
background(255);

size(700,700);
noLoop();
beginRecord(PDF, "T2BRainbow1.pdf");
// stroke(100);
smooth();
//ellipse(350,350,700,700);
noStroke();
int count=0;

for (int i=0;i float x=random(borderDiam);
float y=random(borderDiam);
float diameter=(random(borderDiam/10)+10);
Circ temp=new Circ(x,y,diameter);
if (inBorder(x,y,diameter)&&collide(x,y,diameter,count)){
balls[count]=temp;
count++;
}
}
for (int i=count;i float x=random(borderDiam);
float y=random(borderDiam);
float diameter=(random(borderDiam/20)+10);
Circ temp=new Circ(x,y,diameter);
if (inBorder(x,y,diameter)&&collide(x,y,diameter,count)){
balls[count]=temp;
count++;
}
}
for (int i=count;i float x=random(borderDiam);
float y=random(borderDiam);
float diameter=(random(borderDiam/30)+5);
Circ temp=new Circ(x,y,diameter);
if (inBorder(x,y,diameter)&&collide(x,y,diameter,count)){
balls[count]=temp;
count++;
}
}
for (int i=count;i float x=random(borderDiam);
float y=random(borderDiam);
float diameter=(random(borderDiam/30)+2);
Circ temp=new Circ(x,y,diameter);
if (inBorder(x,y,diameter)&&collide(x,y,diameter,count)){
balls[count]=temp;
count++;
}
}

System.out.println(count);
for (int i = 0; i < count; i++){
balls[i].display();
}
endRecord();

}
void draw(){

}
boolean inBorder(float x, float y, float diameter){
float distToCenter=dist(x,y,borderDiam/2,borderDiam/2);
float distToEdge= distToCenter+diameter/2;
if (distToEdge>borderDiam/2){
return false;
}
else return true;


}
boolean collide(float x, float y, float d, int numCircles){
int diameter=(int)d;
for (int i = 0; i < numCircles; i++){
float distance = dist(x, y, balls[i].x, balls[i].y);
float minDist = balls[i].diameter/2 + diameter/2;
if (distance < minDist){
return false;
}

}
return true;
}

class Circ{
float x, y;
float diameter;
int id;

boolean display = true;
boolean inBorder=true;
float col;
float sat;
float bright;
float gray;
Circ(float xin, float yin, float diameter){
x = xin;
y = yin;
this.diameter = diameter;
//blue 195
//cool green 145
//pink 300
//red 340
//yellow green 60
//0 red orange
//for a rainbow coloring
//col=((dist(borderDiam/2,borderDiam/2,x,y))/(borderDiam/720));
//col= ((borderDiam/2-dist(x,y,borderDiam/2,borderDiam/2))/(borderDiam/720));
//col=+(random(20));
col=y/(borderDiam/360)+random(40);
sat=((dist(borderDiam/2,borderDiam/2,x,y))/(borderDiam/200));
bright=((borderDiam/2-dist(x,y,borderDiam/2,borderDiam/2))/(borderDiam/100));
gray=(borderDiam/2-dist(x,y,borderDiam/2,borderDiam/2))/1.2;

}

void display(){
colorMode(HSB,360,100,100);
fill(col,sat,100);
//fill(gray);
ellipse(x, y, diameter, diameter);
}
}









Tuesday, February 24, 2009

Rotating Triangles

The final part of this assignment was to use the pushMatrix() and popMatrix() commands along with shape translations to create a design.











void setup(){
size(720, 480);
background(0);
stroke(255);
//top
fill(230,245,255);
triangle(0,0,720/4,0,720/2,480/2);
fill(175,225,255);
triangle(720/2,0,720/4,0,720/2,480/2);
fill(80,195,255);
triangle(720/2,0,(720/4)*3,0,720/2,480/2);
fill(20,175,255);
triangle(720,0,(720/4)*3,0,720/2,480/2);
//bottom
fill(5,5,5);
triangle(0,480,720/4,480,720/2,480/2);
fill(30,40,45);
triangle(720/2,480,720/4,480,720/2,480/2);
fill(30,60,70);
triangle(720/2,480,(720/4)*3,480,720/2,480/2);
fill(25,65,85);
triangle(720,480,(720/4)*3,480,720/2,480/2);
//right--need to change stroke
fill(25,70,100);
triangle(720,0,720,480/4,720/2,480/2);
triangle(720,480/2,720,480/4,720/2,480/2);
triangle(720,480/2,720,(480/4)*3,720/2,480/2);
triangle(720,480,720,(480/4)*3,720/2,480/2);
//left--need to change stroke
triangle(0,0,0,480/4,720/2,480/2);
triangle(0,480/2,0,480/4,720/2,480/2);
triangle(0,480/2,0,(480/4)*3,720/2,480/2);
triangle(0,480,0,(480/4)*3,720/2,480/2);
pushMatrix();
for (int i=0;i<30;i++){
pushMatrix();
fill(random(100),random(200),255);
translate(random(150),random(100));
scale(.9);
ellipse(2,2,100,100);
}
for (int i=0;i<30;i++)
popMatrix();
pushMatrix();
translate(750,0);
for (int i=0;i<30;i++){
pushMatrix();
fill(random(100),random(200),255);
translate(random(150)-150,random(100));
scale(.9);
ellipse(2,2,80,80);
}
for (int i=0;i<30;i++)
popMatrix();
popMatrix();
translate(720/2,480/2);
for (int i=0;i<10;i++){


translate(2,2);
scale(1.4);
fill((i+1)*25);
rect(0,0,10,10);
rotate(PI/30);
pushMatrix();



}
for (int i=0;i<10;i++){
popMatrix();
}

translate(-10,-10);
for (int j=0;j<10;j++){


translate(-2,-6);
scale(1.3);
fill(20,random(255),255);
rect(0,0,10,10);

stroke(random(255));
scale(1.3);
fill(random(255),255,255);
translate(-2,-6);
ellipse(5,5,10,10);
rotate(PI/30);
pushMatrix();



}
for (int i=0;i<10;i++)
popMatrix();
translate(0,-20);


}
void draw(){}




The second part of assignment 4 is to use our rotating triangles function to create an interesting image using only rotating triangles.











void setup()
{
size(720, 480);
background(0);
stroke(255);
int x1=0;
int x2=0;
int x3=20;
int y1=0;
int y2=20;
int y3=0;
int x4=720;
int y4=480;
int x5=720;
int y5=460;
int x6=700;
int y6=480;
int x11=0;
int x12=0;
int x13=20;
int y11=480;
int y12=460;
int y13=480;
int x14=720;
int y14=0;
int x15=720;
int y15=20;
int x16=700;
int y16=0;
int r1=255;
int g1=255;
int b1=255;
int r2=0;
int g2=0;
int b2=0;
stroke(r1,g1,b1);
int ang1=0;
int ang2=0;
myTriangle(x1,y2,x2,y2,x3,y3);
for (int i=0;i<300;i++){
ang1=ang1+20;
ang2=ang2-20;
x1=x1+3;
y1=y1+2;
x2=x2+3;
y2=y2+2;
x3=x3+3;
y3=y3+2;
x4=x4+3;
x5=x5+3;
x6=x6+3;
y4=y4+2;
y5=y5+2;
y6=y6+2;
x11=x11-3;
y11=y11-2;
x12=x12-3;
y12=y12-2;
x13=x13-3;
y13=y13-2;
x14=x14-3;
x15=x15-3;
x16=x16-3;
y14=y14-2;
y15=y15-2;
y16=y16-2;
r1=r1-2;
g1=g1-3;
b1=b1-4;
r2=r2+4;
g2=g2+3;
b2=b2+2;
stroke(r1,g1,b1);
Point p1=new Point(x1, y1);
Point p2=new Point(x2 ,y2);

Point p3=new Point(x3 ,y3);
rotateTri(p1,p2,p3,ang1);
stroke(b1,g1,r1);
Point p4=new Point(x4, y4);
Point p5=new Point(x5 ,y5);

Point p6=new Point(x6 ,y6);
rotateTri(p3,p4,p5,ang2);
stroke(r2,g2,b2);
Point p11=new Point(x11, y11);
Point p12=new Point(x12 ,y12);

Point p13=new Point(x13 ,y13);
//rotateTri(p11,p12,p13,ang1);
stroke(b2,g2,r2);
Point p14=new Point(x14, y14);
Point p15=new Point(x15 ,y15);

Point p16=new Point(x16 ,y16);
rotateTri(p16,p14,p15,ang2);
}
}
void draw(){}
void myTriangle(int x1,int y1,int x2, int y2, int x3, int y3){
line(x1,y1, x2,y2);
line(x2,y2, x3,y3);
line(x3,y3,x1,y1);
}
void rotateTri(Point p1, Point p2, Point p3, float angle){
//draw original triangle

float rad=radians(angle);
Point center=new Point(((p1.x+p2.x+p3.x)/3),((p1.y+p2.y+p3.y)/3));
Point temp1=new Point(p1.x-center.x, p1.y-center.y);
Point temp2=new Point(p2.x-center.x, p2.y-center.y);
Point temp3=new Point(p3.x-center.x, p3.y-center.y);
p1=rotatePnt(temp1, rad);
p2=rotatePnt(temp2, rad);
p3=rotatePnt(temp3, rad);
p1=new Point(p1.x+center.x, p1.y+center.y);
p2=new Point(p2.x+center.x, p2.y+center.y);
p3=new Point(p3.x+center.x, p3.y+center.y);

myTriangle(p1.x,p1.y,p2.x,p2.y,p3.x,p3.y);
}
Point rotatePnt(Point pnt, float angle)
{
float[][] homoCoord = new float[1][3];
float[][] homoCoord2= new float[1][3];
float[][] transformMat= new float[3][3];
float cosine=cos(angle);
float sine=sin(angle);
Point temp=new Point();


homoCoord[0][0]=pnt.x;
homoCoord[0][1]=pnt.y;
homoCoord[0][2]=1;

transformMat[0][0]=cosine;
transformMat[0][1]=sine;
transformMat[0][2]=0;
transformMat[1][0]=-sine;
transformMat[1][1]=cosine;
transformMat[1][2]=0;
transformMat[2][0]=0;
transformMat[2][1]=0;
transformMat[2][2]=1;

homoCoord2=multMat(homoCoord, transformMat);
temp.x=(int)homoCoord2[0][0];
temp.y=(int)homoCoord2[0][1];
return temp;

}
float[][] multMat(float[][] m1,float[][] m2){
float[][]newMatrix=new float[1][3];
for(int i = 0; i < 1; i++) {
for(int j = 0; j < 3; j++) {
for(int k = 0; k < 3; k++){
newMatrix[i][k]+=m1[i][j]*m2[j][k];
}
}
}
return newMatrix;
}




This assignment involved writing a function in processing that takes in the 3 points of a triangle and its angle of rotation and draws both the original triangle and the triangle rotated by the angle parameter. In this example, the original triangle (light gray) is rotated by 90 degrees (white).








void setup()
{
size(720, 480);
background(0);
stroke(255);
Point p1=new Point(100,240);
Point p2=new Point(500,240);
Point p3=new Point(300,100);
rotateTri(p1,p2,p3,90);
}
}
void draw(){}
void myTriangle(int x1,int y1,int x2, int y2, int x3, int y3){
line(x1,y1, x2,y2);
line(x2,y2, x3,y3);
line(x3,y3,x1,y1);
}
void rotateTri(Point p1, Point p2, Point p3, float angle){
//draw original triangle
myTriangle(p1.x,p1.y,p2.x,p2.y,p3.x,p3.y);
float rad=radians(angle);
Point center=new Point(((p1.x+p2.x+p3.x)/3),((p1.y+p2.y+p3.y)/3));
Point temp1=new Point(p1.x-center.x, p1.y-center.y);
Point temp2=new Point(p2.x-center.x, p2.y-center.y);
Point temp3=new Point(p3.x-center.x, p3.y-center.y);
p1=rotatePnt(temp1, rad);
p2=rotatePnt(temp2, rad);
p3=rotatePnt(temp3, rad);
p1=new Point(p1.x+center.x, p1.y+center.y);
p2=new Point(p2.x+center.x, p2.y+center.y);
p3=new Point(p3.x+center.x, p3.y+center.y);

myTriangle(p1.x,p1.y,p2.x,p2.y,p3.x,p3.y);
}
Point rotatePnt(Point pnt, float angle)
{
float[][] homoCoord = new float[1][3];
float[][] homoCoord2= new float[1][3];
float[][] transformMat= new float[3][3];
float cosine=cos(angle);
float sine=sin(angle);
Point temp=new Point();


homoCoord[0][0]=pnt.x;
homoCoord[0][1]=pnt.y;
homoCoord[0][2]=1;

transformMat[0][0]=cosine;
transformMat[0][1]=sine;
transformMat[0][2]=0;
transformMat[1][0]=-sine;
transformMat[1][1]=cosine;
transformMat[1][2]=0;
transformMat[2][0]=0;
transformMat[2][1]=0;
transformMat[2][2]=1;

homoCoord2=multMat(homoCoord, transformMat);
temp.x=(int)homoCoord2[0][0];
temp.y=(int)homoCoord2[0][1];
return temp;

}
float[][] multMat(float[][] m1,float[][] m2){
float[][]newMatrix=new float[1][3];
for(int i = 0; i < 1; i++) {
for(int j = 0; j < 3; j++) {
for(int k = 0; k < 3; k++){
newMatrix[i][k]+=m1[i][j]*m2[j][k];
}
}
}
return newMatrix;
}



Sunday, February 1, 2009

Assignment 4: Triangles and Line Clipping

Assignment 4 involves:
1. Creating an applet that creates a cubic Bezier curve based on points created when the user clicks on the applet
2. Creating a function that takes 3 sets of coordinates and draws a triangle
3. Adding to the triangle function to create 5 triangles with random coordinates on a 720 x 480 image
4. To be continued....

1. Bezier curve using user input:

**Still working on embedding the applet here.











int count=0;
int x1=0;
int x2=0;
int x3=0;
int x4=0;
int y1=0;
int y2=0;
int y3=0;
int y4=0;

void setup(){
size(200,200);
background(0);
stroke(255);
}
void draw(){}
void mousePressed(){

if (count==0){
x1=mouseX;
y1=mouseY;
point(x1,y1);
count++;
}
else if (count==1){
x2=mouseX;
y2=mouseY;
point(x2,y2);
count++;
}
else if (count==2){
x3=mouseX;
y3=mouseY;
point(x3,y3);
count++;

}
else if (count==3){
background(0);
x4=mouseX;
y4=mouseY;
cubBesCurve(x1,y1,x2,y2,x3,y3,x4,y4);
count++;
}
else if (count==4){
background(0);
count=0;
}
}

void parLine(int x1, int y1, int x2, int y2){
for (float t=0;t<1;t=t+.001){
point(x1+t*(x2-x1),y1+t*(y2-21));
}
}
void quadBesCurve(int x1, int y1, int x2, int y2, int x3, int y3){
for (float t=0;t<1;t=t+.001){
point((sq(1-t)*x1+2*(1-t)*t*x2+sq(t)*x3),(sq(1-t)*y1+2*(1-t)*t*y2+sq(t)*y3));
}
}
void cubBesCurve(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4){
for (float t=0;t<1;t=t+.001){
point ((pow((1-t),3)*x1+3*sq(1-t)*t*x2+3*(1-t)*sq(t)*x3+pow(t,3)*x4),
(pow((1-t),3)*y1+3*sq(1-t)*t*y2+3*(1-t)*sq(t)*y3+pow(t,3)*y4));
}
}

2. Drawing Triangles:

The first step to this part was to create a function to draw 1 triangle, then I created another function to draw 5 triangles in random positions



Here is a shot after implementing a line clipping algorithm:





















Source Code:
int XMAX=540;
int XMIN=180;
int YMAX=360;
int YMIN=120;

void setup(){
size(720,480);
stroke(255);
background(0);
fill(50);

rect(XMIN,YMIN,360,240);

myRandomTriangles(5);

}
void draw(){

}
void myRandomTriangles(int numTriangles){

for (int i=0;i int r=(int)random(255);
int g=(int)random(255);
int b=(int)random(255);
int x1=(int)random(720);
int x2=(int)random(720);
int x3=(int)random(720);
int y1=(int)random(480);
int y2=(int)random(480);
int y3=(int)random(480);
stroke(r,g,b);
myTriangle(x1,y1,x2,y2,x3,y3);
}
}
void drawLine(int x1,int y1,int x2,int y2){
int code1=getLocationCode(x1,y1);
int code2=getLocationCode(x2,y2);
if ((code2==0)&&(code1==0)){
line(x1,y1,x2,y2);
}
else if ((code1&code2)!=0){
}
else {
clipLine(x1,y1,x2,y2);
}
}
void myTriangle(int x11,int y11,int x12, int y12, int x13, int y13){
int x1=x11;
int x2=x12;
int x3=x13;
int y1=y11;
int y2=y12;
int y3=y13;

drawLine(x1,y1, x2,y2);
drawLine(x2,y2, x3,y3);
drawLine(x1,y1,x3,y3);

}
void clipLine(int x1, int y1,int x2, int y2){
int code1=getLocationCode(x1, y1);
int code2=getLocationCode(x2,y2);
double m=((double)(y2-y1)/(x2-x1));
double b=y2-m*x2;
if( (code1&1)!=0){

x1 = (int)((YMIN-b)/m);
y1 = YMIN;
code1=getLocationCode(x1,y1);
}
else if ((code1 & 2)!= 0){

x1= (int)((YMAX-b)/m);
y1 = YMAX;
code1=getLocationCode(x1,y1);
}
if((code1 & 4)!= 0){

y1 =(int)(m*XMAX+b);
x1 = XMAX;
code1=getLocationCode(x1,y1);
}
else if((code1 & 8)!=0){

y1 = (int)(m*XMIN+b);
x1 = XMIN;
code1=getLocationCode(x1,y1);
}
if( (code2&1)!=0){

x2 = (int)((YMIN-b)/m);
y2 = YMIN;
code2=getLocationCode(x2,y2);
}
else if ((code2 & 2)!= 0){

x2= (int)((YMAX-b)/m);
y2 = YMAX;
code2=getLocationCode(x2,y2);
}
if((code2 & 4)!= 0){

y2 =(int)(m*XMAX+b);
x2 = XMAX;
code2=getLocationCode(x2,y2);
}
else if((code2 & 8)!=0){

y2 = (int)(m*XMIN+b);
x2 = XMIN;
code2=getLocationCode(x2,y2);
}

line(x1,y1,x2,y2);
}
int getLocationCode(int x, int y){
int code=0;
if (x>XMAX)
code=code+4;
if (x code=code+8;
if (y code=code+1;
if (y>YMAX)
code=code+2;
return code;
}

Thursday, January 22, 2009

Assignment 3: Bezier Curves






Assignment 3 involves implementing a parametric line function, a quadratic Bezier curve implementation, and a cubic Bezier curve implementation.

void setup(){
size(200,200);
background(0);
stroke(255);
}
void draw(){
parLine(10,10,190,50);
quadBesCurve(10,60,150,60,100,100);
cubBesCurve(10,90, 40, 120, 130, 90, 140, 140);
}
//Draws a line parametrically

void parLine(int x1, int y1, int x2, int y2){
for (float t=0;t<1;t=t+.001){
point(x1+t*(x2-x1),y1+t*(y2-21));
}
}

//Draws a quadratic Bezier curve

void quadBesCurve(int x1, int y1, int x2, int y2, int x3, int y3){
for (float t=0;t<1;t=t+.001){
point((sq(1-t)*x1+2*(1-t)*t*x2+sq(t)*x3),(sq(1-t)*y1+2*(1-t)*t*y2+sq(t)*y3));
}
}

//Draws a cubic Bezier curve

void cubBesCurve(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4){
for (float t=0;t<1;t=t+.001){
point ((pow((1-t),3)*x1+3*sq(1-t)*t*x2+3*(1-t)*sq(t)*x3+pow(t,3)*x4),
(pow((1-t),3)*y1+3*sq(1-t)*t*y2+3*(1-t)*sq(t)*y3+pow(t,3)*y4));
}
}
<

Monday, January 12, 2009

Assignment 2

1. The first part of Assignment 2 is to write a function in processing that draws a straight line from one point to another using only point commands, creating a line by drawing to individual pixels using Bresenham's line algorithm.







Source:

void setup(){
size(150,150);
background(0);
stroke(255);
}
void draw(){
linePix(10,10,10,100);
linePix(20,10,110,10);
linePix(20,20,40,100);
linePix(30,20,100,100);
linePix(40,20,100,40);
}
void linePix(int x0, int y0, int x1, int y1){
int dy=y1-y0;
int dx=x1-x0;
int xstep, ystep;


if (dy < 0){
dy=-dy;
ystep=-1;
}
else {
ystep=1;
}
if (dx < 0){
dx=-dx;
xstep=-1;
}
else{
xstep=1;
}
point(x0,y0);
if (dx > dy){
int e = 2*dy-dx;
while (x1!=x0){
if (e > 0){
y0=y0+ystep;
e=e-2*dx;
}
x0=x0+xstep;
e=e+2*dy;
point(x0,y0);
}
}
else{
int e=2*dx-dy;
while (y0!=y1){
if (e > =0){
x0=x0+xstep;
e=e-2*dy;
}
y0=y0+ystep;
e=e+2*dx;
point(x0,y0);
}
}

}



2. The second part of the assignment is to create a function in processing that takes in a number of lines as a parameter and creates a "web" consisting of that number of straight lines.









Source:

void setup(){
size(150,150);
background(0);
stroke(255);
}
void draw(){
drawWeb(10);
}
void drawWeb(int numLines){
int xAxis=numLines;
int yAxis=1;

for (int i=0;i < numLines;i++){
line(10,(xAxis+1)*10,10+yAxis*10,10);
xAxis--;
yAxis++;
}
}


3. Draw a circle when given a point and a radius using only point commands. I wrote 2: one when giving the center of the circle and one when giving the upper left coordinate of the bounding rectangle.










void setup(){
size(150,150);
background(0);
stroke(255);
}
void draw(){
circlePixCenter(75,75,20);
circlePixUpperLeft(75,75,20);

}
void circlePixCenter(int x0, int y0, int radius){
int f = 1-radius;
int ddFx=1;
int ddFy=-2*radius;
int x=0;
int y=radius;

point(x0,y0+radius);
point(x0, y0-radius);
point(x0+radius, y0);
point(x0-radius, y0);

while(x < y){
if (f > =0){
y--;
ddFy+=2;
f+=ddFy;
}
x++;
ddFx+=2;
f+=ddFx;
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);

}
}
void circlePixUpperLeft(int x1, int y1, int radius){
int f = 1-radius;
int ddFx=1;
int ddFy=-2*radius;
int x=0;
int y=radius;
int x0=x1+radius;
int y0=y1+radius;
point(x0,y0+radius);
point(x0, y0-radius);
point(x0+radius, y0);
point(x0-radius, y0);

while(x < y){
if (f > =0){
y--;
ddFy+=2;
f+=ddFy;
}
x++;
ddFx+=2;
f+=ddFx;
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);

}
}

Thursday, January 8, 2009

Assignment 1


This is my first assignment and first attempt using Processing.

Source Code:

size(400,400);
background(70,200,200);
noStroke();
fill(235,235,50);
//head
rect(100,50,200,200);

//neck
rect(100, 250,140, 80);

//Hair
triangle(100,30,100,50,110,50);
triangle(110,50,130,50,120,30);
triangle(130,50,150,50,140,30);
triangle(150,50,170,50,160,30);
triangle(170,50,190,50,180,30);
triangle(190,50,210,50,200,30);
triangle(210,50,230,50,220,30);
triangle(230,50,250,50,240,30);
triangle(250,50,270,50,260,30);
triangle(270,50,290,50,280,30);
triangle(290,50,300,50,300,30);
stroke(0);

//Outline of head
line(100,30, 100, 330);
line(300,30,300,250);
line(240,250,240,330);
line(100,30,110,50);
line(120,30,130,50);
line(140,30,150,50);
line(160,30,170,50);
line(180,30,190,50);
line(200,30,210,50);
line(220,30,230,50);
line(240,30,250,50);
line(260,30,270,50);
line(280,30,290,50);
line(120,30,110,50);
line(140,30,130,50);
line(160,30,150,50);
line(180,30,170,50);
line(200,30,190,50);
line(220,30,210,50);
line(240,30,230,50);
line(260,30,250,50);
line(280,30,270,50);
line(300,30,290,50);
line(100,330,240,330);

//Mouth
stroke(0);
ellipseMode(CORNER);
arc(120,220,180,60,0,3*PI/4);
line(147,268,142,273);

//Eyes
fill(255);
ellipse(260,137,65,60);
ellipse(190,135,80,65);
fill(0);
ellipse(225,160,5,5);
ellipse(295, 160, 5,5);

//Nose
fill(235,235,50);
arc(250,190,40,20,1.5*PI,PI);

//Ear
arc(85,220,30,25,1*PI/8,7*PI/4);
arc(90,225,20,15,PI,7*PI/4);