« Processing HW: | Main | So, how secure is the new generation of passports? »

541 Homework, part 2

here's more of this week's 541 homework. Set the variables true and run to see the outputs for each example. I removed my code for 6 and i don't know what will happen if multiple are set to true. but enjoi. hope it all works :}

code after the jump...

//exercises page 179
boolean ex1 = false;
boolean ex2 = false;
boolean ex3 = false;

//exercises page 194
boolean ex4 = false;
boolean ex5 = false;
boolean ex6 = false;

int frameSize = 300; //size of the window
int counter1 = 0;
int rectX = 0;
int tCenter = 150;
float sizeScale = .25; //scaling the T

void setup(){
size (frameSize, frameSize);
background(128);
}

void draw(){
if(ex1){
frameRate(3);
println(counter1+1);
counter1++;
if (counter1 >= 4){ counter1 = 0;}
}//end if for ex1

if(ex2){
if(rectX < frameSize){
background(128); //clear the frame
rect(rectX, 25, 50, 50);
rectX++;
}
else rectX = 0;
}//end if for ex2

if(ex3){
noLoop();
rect(frameSize/4, frameSize/4, frameSize/2, frameSize/2);
}//end if for ex3

if(ex4){
drawT(tCenter);
tCenter++;
if (tCenter > (frameSize+ (frameSize/8))){tCenter = 0;}
}//end if for ex4

if(ex5){
drawT(tCenter, sizeScale);
tCenter++;
if (tCenter > (1/sizeScale)*(frameSize+ (frameSize/8))){tCenter = 0;}
}//end if for ex5

if (ex6){
println("no six for you tonight");
}//end if for ex6
}

void drawT(int center){
background(128); //clear the frame
for(int x=0; x < 4; x++){
stroke(255-50*x);
strokeWeight(2*(5-x));
/* debug
line(center-(frameSize/8)+4*x, center-(frameSize/8)+4*x, center+(frameSize/8)+4*x, center-(frameSize/8)+4*x);
line(center+4*x, center-(frameSize/8)+4*x, center+4*x, center+(frameSize/8)+4*x);
println("line1X1:" + (center-(frameSize/8)+4*x) +" line1Y1:"+ (center-(frameSize/8)+4*x) +" line1X2:"+ (center+(frameSize/8)+4*x)
+" line1Y2: " + (center-(frameSize/8)+4*x));
println("line2X1:"+ (center+4*x) +" line2Y1:"+ (center-(frameSize/8)+4*x) +" line2X2:"+ (center+4*x) +" line2Y2:"+ (center+(frameSize/8)+4*x));
*/ //end debug
}//end of for loop
}

void drawT(int center, float scaleNum){
background(128); //clear the frame
for(int x=0; x<4; x++){
stroke(255-50*x);
strokeWeight(2*(5-x));
line((scaleNum)*(center-(frameSize/8)+4*x), (scaleNum)*(center-(frameSize/8)+4*x), (scaleNum)*(center+(frameSize/8)+4*x), (scaleNum)*(center-(frameSize/8)+4*x));
line((scaleNum)*(center+4*x), (scaleNum)*(center-(frameSize/8)+4*x), (scaleNum)*(center+4*x), (scaleNum)*(center+(frameSize/8)+4*x));
/*
println("line1X1:" + (scaleNum)*(center-(frameSize/8)+4*x) +" line1Y1:"+ (scaleNum)*(center-(frameSize/8)+4*x)
+" line1X2:"+ (scaleNum)*(center+(frameSize/8)+4*x) +" line1Y2: " + (scaleNum)*(center-(frameSize/8)+4*x));
println("line2X1:"+ (scaleNum)*(center+4*x) +" line2Y1:"+ (scaleNum)*(center-(frameSize/8)+4*x)
+" line2X2:"+ (scaleNum)*(center+4*x) +" line2Y2:"+ (scaleNum)*(center+(frameSize/8)+4*x));
*/
}//end of for loop
}

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

This page contains a single entry from the blog posted on November 13, 2006 10:52 PM.

The previous post in this blog was Processing HW:.

The next post in this blog is So, how secure is the new generation of passports?.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.31