float[] R = new float[5];
void setup(){
rnd();
}
void rnd(){
for(int i = 0; i < R.length; i++){
R[i] = random(-10 , 10);
println("Random array "+i+" = "+R[i]);
}
}
Thursday, 25 September 2014
Tuesday, 23 September 2014
Lab 3 cont 3
int al = 10;
int[] R = new int[al];
int max = 5;
int j,k;
void setup(){
rnd(2);
}
void rnd(int d){
for(int i = 0; i < R.length ; i++){
R[i] = round(random(0 , max));
if(R[i] != d){
j = 0;
k = 0;
for(j = i;j > 0;j--){
if(R[j-1] == R[i]){
k++;
}
}
if(k > 0){
i--;
}
}
}
for(int i = 0; i < R.length ; i++){
println("Random array "+i+" = "+R[i]);
}
}
int[] R = new int[al];
int max = 5;
int j,k;
void setup(){
rnd(2);
}
void rnd(int d){
for(int i = 0; i < R.length ; i++){
R[i] = round(random(0 , max));
if(R[i] != d){
j = 0;
k = 0;
for(j = i;j > 0;j--){
if(R[j-1] == R[i]){
k++;
}
}
if(k > 0){
i--;
}
}
}
for(int i = 0; i < R.length ; i++){
println("Random array "+i+" = "+R[i]);
}
}
Lab 3 cont
int K[] = { 4, 8, 5};
void setup(){
check(5);
check(4);
check(9);
}
void check(int j){
int c = 0;
for(int i = 0; i < K.length; i++){
if( j == K[i]){println(j+" has index = "+i+" in K"); c++;} }
for(int i = 0; i < K.length; i++){
if( j != K[i] && c == 0){println(j+" is not in K"); c++;} }
}
void setup(){
check(5);
check(4);
check(9);
}
void check(int j){
int c = 0;
for(int i = 0; i < K.length; i++){
if( j == K[i]){println(j+" has index = "+i+" in K"); c++;} }
for(int i = 0; i < K.length; i++){
if( j != K[i] && c == 0){println(j+" is not in K"); c++;} }
}
Monday, 22 September 2014
Wednesday, 17 September 2014
lab 3 balloon
int []ball = new int[4];
void setup() {
size(800, 600);
for (int i = 0; i < ball.length; i++) {
ball[i] = 4+i*4;
}
frameRate(30);
}
float y = 665;
void draw() {
background(0, 180, 200);
draw_balloon(100);
draw_balloon(110);
}
int k = 0;
int r = 0;
void draw_balloon(int One) {
for(int i = 1 ; i < 8;i++){
stroke(0);
line(i*One, y+(i*20), i*One, y+130+(i*20));
noStroke();
fill(r+(i*50), r+(i*40), r+(i*30));
ellipse(i*One, y+(i*20), (665/10)-y/10, 110);
}
y = y - ball[k];
if (y < -130) { y = height+260; r += 10; k = round(random(0,3)); }
}
void mousePressed(){
y = 665;
r = 0;
}
void setup() {
size(800, 600);
for (int i = 0; i < ball.length; i++) {
ball[i] = 4+i*4;
}
frameRate(30);
}
float y = 665;
void draw() {
background(0, 180, 200);
draw_balloon(100);
draw_balloon(110);
}
int k = 0;
int r = 0;
void draw_balloon(int One) {
for(int i = 1 ; i < 8;i++){
stroke(0);
line(i*One, y+(i*20), i*One, y+130+(i*20));
noStroke();
fill(r+(i*50), r+(i*40), r+(i*30));
ellipse(i*One, y+(i*20), (665/10)-y/10, 110);
}
y = y - ball[k];
if (y < -130) { y = height+260; r += 10; k = round(random(0,3)); }
}
void mousePressed(){
y = 665;
r = 0;
}
Sunday, 14 September 2014
Quadrant lab 3
void setup(){
size(300, 300);
background(0);
}
void draw(){
draw_line();
}
void draw_line(){
background(0);
stroke(255);
line(150, 0, 150, 300);
line(0, 150, 300, 150);
if((mouseX > 150) && (mouseY > 150))text("Quadrant 4", mouseX, mouseY);
if((mouseX > 150) && (mouseY < 150)) {text("Quadrant 1", mouseX, mouseY);}
if((mouseX == 150) && (mouseY == 150)) {text("Origin", mouseX, mouseY);}
if((mouseX < 150) && (mouseY < 150)) {text("Quadrant 2", mouseX, mouseY);}
if((mouseX < 150) && (mouseY > 150)) {text("Quadrant 3", mouseX, mouseY);}
}
size(300, 300);
background(0);
}
void draw(){
draw_line();
}
void draw_line(){
background(0);
stroke(255);
line(150, 0, 150, 300);
line(0, 150, 300, 150);
if((mouseX > 150) && (mouseY > 150))text("Quadrant 4", mouseX, mouseY);
if((mouseX > 150) && (mouseY < 150)) {text("Quadrant 1", mouseX, mouseY);}
if((mouseX == 150) && (mouseY == 150)) {text("Origin", mouseX, mouseY);}
if((mouseX < 150) && (mouseY < 150)) {text("Quadrant 2", mouseX, mouseY);}
if((mouseX < 150) && (mouseY > 150)) {text("Quadrant 3", mouseX, mouseY);}
}
Wednesday, 10 September 2014
Tax lab 3
double money = 35000,tax;
void setup() {
size(200, 200);
background(255);
if (money <= 15000) { tax = money * 10/100;}
else if(15000 < money && money <= 25000) {tax = money * 20/100;}
else if(25000 < money && money <= 35000) {tax = money * 30/100;}
else if(35000 < money) { tax = money * 40/100;}
println("Your money "+salary);
println("Your tax is = "+tax);
}
void setup() {
size(200, 200);
background(255);
if (money <= 15000) { tax = money * 10/100;}
else if(15000 < money && money <= 25000) {tax = money * 20/100;}
else if(25000 < money && money <= 35000) {tax = money * 30/100;}
else if(35000 < money) { tax = money * 40/100;}
println("Your money "+salary);
println("Your tax is = "+tax);
}
Tuesday, 9 September 2014
Grade lab 3
void setup() {
size(200, 200);
int score = 65;
char Grade;
if (score>=80) {Grade = 'A'; }
else if ((score<80)&&(score>=70)) {Grade = 'B'; }
else if ((score<70)&&(score>=60)) {Grade = 'C'; }
else if ((score<60)&&(score>=50)) {Grade = 'D';} else Grade = 'F';
}
println("You got Grade "+Grade);
fill(0);
text("You got Grade "+Grade, 50, 100);
}
size(200, 200);
int score = 65;
char Grade;
if (score>=80) {Grade = 'A'; }
else if ((score<80)&&(score>=70)) {Grade = 'B'; }
else if ((score<70)&&(score>=60)) {Grade = 'C'; }
else if ((score<60)&&(score>=50)) {Grade = 'D';} else Grade = 'F';
}
println("You got Grade "+Grade);
fill(0);
text("You got Grade "+Grade, 50, 100);
}
Tuesday, 2 September 2014
Animation Spoon and Fork lab 2
void setup(){
size(200, 200);
frameRate(50);
}
float posx = 0;
float c = 0;
void draw(){
if(c == 0){draw_fab(); posx = posx + 1;if(posx >20){c = 1;}}
if(c == 1){draw_fab(); posx = posx - 1;if(posx < -10){c = 0;}}
}
void draw_fab(){
background(200);
fill(255);
stroke(255);
quad(100, 25, 25, 100, 100, 175, 175, 100);
stroke(180);
fill(180);
rect(posx+45, 70, 10, 70);
rect(145-posx, 70, 10, 70);
quad(135-posx, 55, 165-posx, 55, 155-posx, 72, 145-posx, 72);
ellipse(posx+50, 50, 30, 45);
rect(135-posx, 30, 30, 25);
stroke(190);
fill(190);
ellipse(posx+50, 50, 26, 36);
rect(posx+47, 72, 6, 66);
rect(147-posx, 72, 6, 66);
quad(138-posx, 55, 162-posx, 55, 153-posx, 72, 147-posx, 72);
rect(138-posx, 32, 3, 25);
rect(145-posx, 32, 3, 25);
rect(152-posx, 32, 3, 25);
rect(159-posx, 32, 3, 25);
}
size(200, 200);
frameRate(50);
}
float posx = 0;
float c = 0;
void draw(){
if(c == 0){draw_fab(); posx = posx + 1;if(posx >20){c = 1;}}
if(c == 1){draw_fab(); posx = posx - 1;if(posx < -10){c = 0;}}
}
void draw_fab(){
background(200);
fill(255);
stroke(255);
quad(100, 25, 25, 100, 100, 175, 175, 100);
stroke(180);
fill(180);
rect(posx+45, 70, 10, 70);
rect(145-posx, 70, 10, 70);
quad(135-posx, 55, 165-posx, 55, 155-posx, 72, 145-posx, 72);
ellipse(posx+50, 50, 30, 45);
rect(135-posx, 30, 30, 25);
stroke(190);
fill(190);
ellipse(posx+50, 50, 26, 36);
rect(posx+47, 72, 6, 66);
rect(147-posx, 72, 6, 66);
quad(138-posx, 55, 162-posx, 55, 153-posx, 72, 147-posx, 72);
rect(138-posx, 32, 3, 25);
rect(145-posx, 32, 3, 25);
rect(152-posx, 32, 3, 25);
rect(159-posx, 32, 3, 25);
}
Animation Football Field lab 2
void setup(){
size(500, 300);
frameRate(30);
}
float g = 180;
float c = 0;
void draw(){
if(c == 0){draw_fbf(); g = g - 0.5;if(g < 100){c = 1;}}
if(c == 1){draw_fbf(); g = g + 0.5;if(g > 180){c = 0;}}
}
void draw_fbf(){
background(70, g, 70);
stroke(255);
strokeWeight(10);
line(0, 0, 500, 0);
line(0, 0, 0, 300);
line(500, 300, 500, 0);
line(0, 300, 500, 300);
line(250, 0, 250, 300);
noFill();
ellipse(250, 150, 100, 100);
line(500, 100, 430, 100);
line(500, 200, 430, 200);
line(430, 200, 430, 100);
line(0, 100, 70, 100);
line(0, 200, 70, 200);
line(70, 200, 70, 100);
arc(0, 0, 60, 60, 0, PI/2);
arc(500, 300, 60, 60, PI, TWO_PI-PI/2);
arc(500, 0, 60, 60, PI/2, PI);
arc(0, 300, 60, 60, TWO_PI-PI/2, TWO_PI);
}
size(500, 300);
frameRate(30);
}
float g = 180;
float c = 0;
void draw(){
if(c == 0){draw_fbf(); g = g - 0.5;if(g < 100){c = 1;}}
if(c == 1){draw_fbf(); g = g + 0.5;if(g > 180){c = 0;}}
}
void draw_fbf(){
background(70, g, 70);
stroke(255);
strokeWeight(10);
line(0, 0, 500, 0);
line(0, 0, 0, 300);
line(500, 300, 500, 0);
line(0, 300, 500, 300);
line(250, 0, 250, 300);
noFill();
ellipse(250, 150, 100, 100);
line(500, 100, 430, 100);
line(500, 200, 430, 200);
line(430, 200, 430, 100);
line(0, 100, 70, 100);
line(0, 200, 70, 200);
line(70, 200, 70, 100);
arc(0, 0, 60, 60, 0, PI/2);
arc(500, 300, 60, 60, PI, TWO_PI-PI/2);
arc(500, 0, 60, 60, PI/2, PI);
arc(0, 300, 60, 60, TWO_PI-PI/2, TWO_PI);
}
Animation Star lab 2
void setup() {
size(300, 300);
background(255, 255, 11);
frameRate(45);
}
float r = 0;
void draw(){
rotate(r);
draw_star();
r = r + 0.1;
}
void draw_star(){
background(255, 255, 11);
noStroke();
fill(0, 200, 200);
quad(150, 0, 50, 300, 150, 200, 250, 300);
triangle(0, 100, 300, 100, 150, 200);
rotate(PI/18);
fill(200, 10, 10);
quad(150, 0, 50, 300, 150, 200, 250, 300);
triangle(0, 100, 300, 100, 150, 200);
rotate(PI/9);
fill(10, 200, 10);
quad(150, 0, 50, 300, 150, 200, 250, 300);
triangle(0, 100, 300, 100, 150, 200);
rotate(PI/8);
fill(10, 10, 200);
quad(150, 0, 50, 300, 150, 200, 250, 300);
triangle(0, 100, 300, 100, 150, 200);
}
size(300, 300);
background(255, 255, 11);
frameRate(45);
}
float r = 0;
void draw(){
rotate(r);
draw_star();
r = r + 0.1;
}
void draw_star(){
background(255, 255, 11);
noStroke();
fill(0, 200, 200);
quad(150, 0, 50, 300, 150, 200, 250, 300);
triangle(0, 100, 300, 100, 150, 200);
rotate(PI/18);
fill(200, 10, 10);
quad(150, 0, 50, 300, 150, 200, 250, 300);
triangle(0, 100, 300, 100, 150, 200);
rotate(PI/9);
fill(10, 200, 10);
quad(150, 0, 50, 300, 150, 200, 250, 300);
triangle(0, 100, 300, 100, 150, 200);
rotate(PI/8);
fill(10, 10, 200);
quad(150, 0, 50, 300, 150, 200, 250, 300);
triangle(0, 100, 300, 100, 150, 200);
}
Bicycle lab 2
void setup(){
size(400, 300);
background(255);
frameRate(5);
}
float y = 0;
void draw(){
float rx = random(-100, 300);
float ry = random(-200, 100);
float rr = random(0, 255);
float rg = random(0, 255);
float rb = random(0, 255);
draw_b(30, rx, ry, rr, rg, rb);
y = y + 1;
if(y == 15){y = 0; background(255);}
}
void draw_b(float wheel,float posx, float posy, float rr, float rg, float rb){
stroke(rr, rg, rb);
strokeWeight(4);
noFill();
ellipse(posx+50, posy+200, wheel, wheel);
ellipse(posx+110, posy+200, wheel, wheel);
line(posx+50, posy+200, posx+65, posy+160);
line(posx+65, posy+160, posx+75, posy+160);
line(posx+62, posy+173, posx+100, posy+173);
line(posx+110, posy+200, posx+100, posy+173);
line(posx+62, posy+173, posx+80, posy+200);
line(posx+80, posy+200, posx+110, posy+200);
line(posx+80, posy+200, posx+105, posy+165);
line(posx+95, posy+165, posx+108, posy+165);
}
size(400, 300);
background(255);
frameRate(5);
}
float y = 0;
void draw(){
float rx = random(-100, 300);
float ry = random(-200, 100);
float rr = random(0, 255);
float rg = random(0, 255);
float rb = random(0, 255);
draw_b(30, rx, ry, rr, rg, rb);
y = y + 1;
if(y == 15){y = 0; background(255);}
}
void draw_b(float wheel,float posx, float posy, float rr, float rg, float rb){
stroke(rr, rg, rb);
strokeWeight(4);
noFill();
ellipse(posx+50, posy+200, wheel, wheel);
ellipse(posx+110, posy+200, wheel, wheel);
line(posx+50, posy+200, posx+65, posy+160);
line(posx+65, posy+160, posx+75, posy+160);
line(posx+62, posy+173, posx+100, posy+173);
line(posx+110, posy+200, posx+100, posy+173);
line(posx+62, posy+173, posx+80, posy+200);
line(posx+80, posy+200, posx+110, posy+200);
line(posx+80, posy+200, posx+105, posy+165);
line(posx+95, posy+165, posx+108, posy+165);
}
Turtle lab 2
void setup(){
size(300, 200);
frameRate(50);
}
float x = 0;
float y = 0;
float c = 0;
void draw(){
x = x + 2;
background(43, 96, 222);
noStroke();
if(x > 400){x = 0;}
stroke(101, 158, 199);
strokeWeight(10);
line(x, 0, x, height);
line(x-50, 0, x-50, height);
line(x-100, 0, x-100, height);
if(c == 0){y = y + 1; draw_turtle(); if( y == 50){c = 1;}}
if(c == 1){y = y - 1; draw_turtle();if( y == -50){c = 0;}}
}
void draw_turtle(){
noStroke();
fill(127, 82, 23);
ellipse(115, 125+y, 30, 70);
ellipse(115, 75+y, 30, 70);
ellipse(195, 135+y, 70, 20);
ellipse(195, 65+y, 70, 20);
ellipse(95, 100+y, 80, 35);
fill(128, 101, 23);
ellipse(150, 100+y, 150, 100);
fill(150, 111, 51);
ellipse(150, 100+y, 140, 90);
fill(130, 123, 96);
ellipse(110, 115+y, 30, 30);
ellipse(155, 80+y, 20, 20);
ellipse(200, 100+y, 15, 15);
fill(0);
ellipse(65, 110+y, 10, 10);
ellipse(65, 90+y, 10, 10);
}
size(300, 200);
frameRate(50);
}
float x = 0;
float y = 0;
float c = 0;
void draw(){
x = x + 2;
background(43, 96, 222);
noStroke();
if(x > 400){x = 0;}
stroke(101, 158, 199);
strokeWeight(10);
line(x, 0, x, height);
line(x-50, 0, x-50, height);
line(x-100, 0, x-100, height);
if(c == 0){y = y + 1; draw_turtle(); if( y == 50){c = 1;}}
if(c == 1){y = y - 1; draw_turtle();if( y == -50){c = 0;}}
}
void draw_turtle(){
noStroke();
fill(127, 82, 23);
ellipse(115, 125+y, 30, 70);
ellipse(115, 75+y, 30, 70);
ellipse(195, 135+y, 70, 20);
ellipse(195, 65+y, 70, 20);
ellipse(95, 100+y, 80, 35);
fill(128, 101, 23);
ellipse(150, 100+y, 150, 100);
fill(150, 111, 51);
ellipse(150, 100+y, 140, 90);
fill(130, 123, 96);
ellipse(110, 115+y, 30, 30);
ellipse(155, 80+y, 20, 20);
ellipse(200, 100+y, 15, 15);
fill(0);
ellipse(65, 110+y, 10, 10);
ellipse(65, 90+y, 10, 10);
}
Subscribe to:
Posts (Atom)