Assignment 1
Assignment 2
Assignment 2
size (400,400);
strokeWeight (4);
line (200,0,0,200);
line (0,200,200,400);
line (400,200,200,0);
line (400,200,200,400);
line (100,0,400,300);
line (0,100,300,400);
line (300,0,0,300);
line (400,100,100,400);
saveFrame();
Assignment 3
size (400,400);
background (225,185,248);
fill (0,0,0,0);
strokeWeight (4);
rectMode (CENTER);
rect (200,200,100,100);
rect (200,200,200,200);
rect (200,200,300,300);
ellipse (50,50,35,35);
ellipse (50,350,35,35);
ellipse (350,350,35,35);
ellipse (350,50,35,35);
saveFrame ();
Assignment 4
size (500,500);
rectMode (CORNERS);
float x=(random(50,200));
float y=(random (50,200));
fill (242,185,142);
rect (200,200,300,300);
rect (x,y,200,200);
float a=width-x;
rect (a,y,300,200);
float c=height-y;
rect (x,c,200,300);
rect (a,c,300,300);
line (x,y,0,0);
line(a,c,500,500);
line (x,c,0,500);
line (500,0,a,y);
line (200,200,0,200);
line (200,200,200,0);
line (200,300,0,300);
line (200,300,200,500);
line (300,200,500,200);
line (300,300,300,500);
line (200,300,200,500);
line (300,200,300,200);
line (300,200,300,0);
line (500,300,0,300);
saveFrame();
Assignment 5
size(500,500);
background(255);
float x=random(0,400);
fill(45,210,99);
rectMode(CENTER);
rect(width/2,(height/2)-(x/2),x,x/2);
rect(width/2,(height/2)+(x/2),x,x/2);
rect((width/2)+(x/2),height/2,x/2,x);
rect((width/2)-(x/2),height/2,x/2,x);
rect(width/2-x/4,height/2-x/4,x/2,x/2);
rect(width/2+x/4,height/2-x/4,x/2,x/2);
rect(width/2-x/4,height/2+x/4,x/2,x/2);
rect(width/2+x/4,height/2+x/4,x/2,x/2);
Assignment 6
size (500,500);strokeWeight (2);
background (225,225,225);
line (50,100,125,100);
line (50,100,50,450);
line (50,450,325,450);
line (325,450,325,350);
line (325,350,450,350);
line (450,350,450,50);
line (450,50,150,50);
line (200,50,150,100);
strokeWeight (2);
line (200,50,200,350);
line (200,350,325,360);
line (200,355,200,400);
line (355,200,400,200);
line (329,200,240,200);
strokeWeight (0);
line (300,225,300,200);
line (275,200,100,200);
line (320,200,320,225);
line (320,225,325,230);
line (300,225,325,250);
rectMode (CORNERS);
rect (290,190,330,200);
ellipse (340,200,15,15);
rect (400,25,300,50);
line (125,100,150,80);
rect (50,300,30,200);
fill (0,0,0);
textSize (15);
strokeWeight (4);
PFont f=loadFont("ArialNarrow-BoldItalic-48.vlw");
text ("ENTER",70,100);
text ("BEDROOM",300,150);
text ("BATHROOM",350,200);
text ("KITCHEN",250,400);
text ("LIVING ROOM",250,300);
text ("GARDERN",80,280);
ellipse (300,100,50,25);
saveFrame ();
Assignment 7
size (400,400);
background (225,185,248);
fill (0,0,0,0);
strokeWeight (4);
rectMode (CENTER);
rect (200,200,100,100);
rect (200,200,200,200);
rect (200,200,300,300);
ellipse (50,50,35,35);
ellipse (50,350,35,35);
ellipse (350,350,35,35);
ellipse (350,50,35,35);
saveFrame ();
Assignment 8
size (400,400);
rectMode (CENTER);
rect (200,200,300,200);
rect (120,120,100,39);
line (100,170,300,170);
line (100,200,300,200);
line (100,230,300,230);
line (100,260,300,260);
fill (245,17,36);
textSize (20);
PFont f=loadFont("BerlinSansFB-Reg-48.vlw");
text ("IBA",100,125);
textSize (15);
PFont g=loadFont("BlackadderITC-Regular-48.vlw");
text ("Maria Fatima",150,168);
text ("Muhammad Mohsin Ali",160,198);
text ("BS-CS",190,228);
fill (0,0,0);
strokeWeight (2);
text ("NAME:",100,168);
text ("F.NAME:",100,198);
text ("CLASS:",100,228);
saveFrame();
Assignment 9
float x,y,vx,r,vy;
void setup(){;
size(400,400);
fill(200,0,0);
frameRate (100);
x=-5;
y=width/2;
r=width/10;
vx=5;
vy=4;
}
void draw(){;
background(50);
stroke(255);
strokeWeight(2);
ellipse(x+r,y,r,r);
x+=vx;
if(x>=width-1.5*r||x<-15)
vx*=-1;
println( " " + x + " " + y );
y+=vy;
if (y>380)
vy*=-1;
if (y<20)
vy*=-1;
}
Assignment 10
float x,y,r,vx,vy;
void setup(){
size(400,400);
fill(200,0,0);
frameRate(5);
x=0;
y=width/2;
r=width/50;
vx=5;
vy=0;
}
void draw(){
background(255);
ellipse(x,y,r,r);
x+=vx;
}
Assignment 11
float x,y,r,vx,vy;
void setup(){
size(400,400);
fill(200,0,0);
frameRate(5);
x=0;
y=width/2;
r=width/50;
vx=5;
vy=0;
}
void draw(){
background(255);
ellipse(x,y,r,r);
x+=vx;
}
Assignment 12
float x,y,r,vx,vy,dx,dy;
void setup(){
size(400,400);
fill(200,0,0);
frameRate(30);
x=0;
y=width/2;
r= width/5;
vx=5;
vy=0;
//dx=1;
//dy=-1;
}
void draw(){
background(255);
println( " " + x + ", " + y);
ellipse(x+40,y,r,r);
x=x+vx;
if(x>= width-80|| x<=0){
vx*=-1;
}
}
Assignment 13
float mx, my;
void setup() {
size(400, 400);
mx = width/2;
my = height/2;
fill(0, 180, 0);
background(255);
}
//mouseX
void draw() {
ellipse(mx,my,100,100);
if(mx-50 <= mouseX & mouseX <= mx+50)
if(my-50 <= mouseY & mouseY <= my+50)
fill(180,0,0);
else
fill (0,180,0);
else
fill (0,180,0);
}
Assignment 14
float x, y, d;
float dx, dy;
//status variables for the obstacle boxes
boolean b1, b2, b3, b4;
int shape;
void setup() {
size(400, 400);
x=width/2;
y=height/2;
d=random(11, 21);
dx= d;
dy=d;
shape = 1;
//initially they are all going to be displayed
b1=b2=b3=b4=true;
fill(200, 0, 0);
noStroke();
background(255);
// frameRate(1);
}
void draw() {
background(255);
//North Side
if (b1) {
rectMode(CENTER);
rect(width/2, 0, 50, 30);
}
//South Side
if (b2) {
rectMode(CENTER);
rect(width/2, height, 50, 30);
}
//East Side
if (b3) {
rectMode(CENTER);
rect(width, height/2, 30, 50);
}
//West Side
if (b4) {
rectMode(CENTER);
rect(0, height/2, 30, 50);
}
if (shape == 1) {
rectMode(CENTER);
rect(x, y, d, d);
}
if (shape == 2)
ellipse(x, y, d, d);
if (x>=width)
x-=width;
if (x<=0)
x+=width;
if (y>=height)
y -= height;
if (y<=0)
y+=height;
}
void keyPressed() {
// collision detection in North
if (x>=175 && x <=225 && y<=30) {
b1=false;
}
// collision detection in South
if (x>=175 && x <=225 && y>=height-30) {
if (b1==false)
b2=false;
}
// collision detection in East
if (y >= 175 && y <= 225 && x >= width-30) {
if (b1 ==false && b2 == false)
b3=false;
}
// collision detection in West
if (y >= 175 && y <= 225 && x <= 30) {
if (b1 == false && b2 == false && b3 ==false)
b4=false;
}
// move left i.e. west
if (key == '4')
x-=dx;
// move right i.e. east
if (key == '6')
x+=dx;
// move up i.e. north
if (key == '8')
y-=dy;
// move down i.e. south
if (key == '2')
y+=dy;
if (key == '5')
{
background(255);
x=width/2;
y=height/2;
}
//change shape
if (key=='s')
shape = 1 ;
if (key == 'c')
shape = 2;
if (key == 'x')
shape = 3;
//zoom shape
if (key=='z')
d-=2;
if (key=='Z')
d+=2;
//change color
if (key =='r')
fill(random(255), 0, 0);
if (key =='g')
fill(0, random(255), 0);
if (key =='b')
fill(0, 0, random(255));
}
Assignment 15
float mx,my;
void setup ()
{ size (400,400);
mx=width/2;
my=height/2;
fill(0,180,0);
background(255);
}
//mouseX
void draw (){
background (200);
if(mouseX > mx){
rect(mx,0,width,height);
}
else{
background(200);}
if (mouseY<my){
rect(0,0,my,height);
}
saveFrame ();
}
Assignment 16