1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
//code1
void setup(){
size(1000,1000);
int answer = factorial(5);
println(answer);
}
float angle = 0;
void draw(){
angle = angle - 0.03;
background(0);
float xmover = 255*cos ( angle ) ;
float ymover = 255*sin ( angle ) ;
int xval = 20;
int yval = 20;
while (xval < 500){
xval = xval + 40;
while ( yval < 420 ) {
yval = yval + 40;
fill(128+ xmover/2, 128+ ymover/2, xval/2 - yval/2);
ellipse(xval + xmover , yval + ymover , xmover/2,ymover/4);
}
yval = 20;
}
}
int factorial(int input){
int xval = 1;
int fac = 1;
while ( xval < input ){
xval = xval + 1;
fac = fac * xval;
}
return fac;
}
//code 2
float x1 = 45;
float y1 = 145;
float x2 = 145;
float y2 = 245;
float speed1x = 3;
float speed2x = 4;
float speed1y = 5;
float speed2y = 4;
void setup(){
size(500,500);
}
void draw(){
ellipse(x1,y1, 150,150);
ellipse(x2,y2,50,50);
x1 = x1 + speed1x;
x2 = x2 + speed2x;
y1 = y1 + speed1y;
y2 = y2 + speed2y;
if ( x1 > width ) speed1x = -4;
if ( x2 > width ) speed2x = -2;
if ( y1 > height) speed1y = -4;
if ( y2 > height ) speed2y = -6;
if ( x1 < 0 ) speed1x = 8;
if ( x2 < 0 ) speed2x = 8;
if ( y1 < 0) speed1y = 2;
if ( y2 < 0 ) speed2y = 2;
float distance =sqrt( (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) );
if ( distance < 100) {
speed2x = - speed2x;
speed2y = - speed2y;
speed1x = - speed1x;
speed1y = - speed1y;
}
}
//code3
PFont f;
String typing = "";
void setup(){
size(500,500);
f = createFont("Arial", 48);
textFont(f);
}
int x = 50;
int y = 50;
void draw(){
text(typing, mouseX, mouseY);
for(int i = 0; i < 100; i++){
line(x+i*10, y, i*10, 400) ;
}
}
void keyPressed(){
if( key > 32 && key < 126) {
typing = typing + key;
}
if ( key == 8){
println("in delete");
background(100);
typing = typing.substring(0, typing.length()-2);
}
if( key == 'p'){
x++;
}
if( key == 'c'){
background(100);
}
}
|