nfg_Day6

Day 6
<< main | course director notes

code void setup{ size(640,480); }
 * 5. save frames**

void draw{ background(128);

for(int i=0; i<10000; i++){ strokeWeight(random(10,20)); stroke(0,20); point(random(width),random(height)); } }

void keyPressed{ if(key==' '){ saveFrame; } } code

code float posX=320; float posY=240; int counter = 0;
 * 5. wrap around**

void setup{ size(640,480); frameRate(60); }

void draw{ strokeWeight(20); point(posX,posY); if(mousePressed){ posX++; }else{ posY--; } if(posY<0){ posY=480; }else if(posY>480){ posY=0; } if(posX<0){ posX=640; }else if(posX>640){ posX=0; } }

code

code float posX = 320; float posY = 240; float speedX = 5; float speedY = 5;
 * 5. triangle**

void setup{ size(640,480); smooth; background(0); }

void draw{ noStroke; fill(0,2); rect(0,0,width,height); if(posX < 0 || posX > width){ speedX *= -1; } if(posY < 0 || posY > height){ speedY *= -1; }

posX += random(speedX); posY += random(speedY);

strokeWeight(1); stroke(0); fill(255,20); triangle(posX,posY-30,posX-30,posY+30,posX+30,posY+30); strokeWeight(5); stroke(255,0,0); point(posX,posY); posX++; }

code

code float posX=320; float posY=240; float speedX = 5; float speedY = 5; int counter = 0;
 * 5. if else**

void setup{ size(640,480); frameRate(60); background(0); }

void draw{ noStroke; fill(0,2); rect(0,0,width,height); if(posX < 0 || posX > width){ speedX *= -1; } if(posY < 0 || posY > height){ speedY *= -1; }

posX += random(speedX); posY += random(speedY);

strokeWeight(random(10,20)); stroke(255,128); point(posX,posY); } code

code arc(50, 55, 60, 60, radians(0),radians(180)); code
 * 5. semicircle in degrees**

++    …add 1 every frame --      …subtract 1 every frame += 0.1    …add this number (0.1) every frame -= 0.1    …subtract this number (0.1) every frame /= 0.1    …divide by this number (0.1) every frame
 * 4. operators**
 * = 0.1    …multiply by this number (0.1) every frame

code float mary = 200;
 * 3. variables**

void setup{ size(640,480); frameRate(60); smooth; background(0); }

void draw{ stroke(255,0,0,128); strokeWeight(20); point(320,mary); mary+= 0.1; // add 0.1 every frame } code

code void setup{ size(640,480); frameRate(60); smooth; background(0); }
 * 2. functions**

void draw{ noStroke; fill(0,20); rectMode(CORNER); rect(0,0,width,height);

stroke(128); //grey strokeWeight(5); line(0,0,640,480); line(0,480,640,0); line(mouseX,mouseY,320,480);

strokeWeight(20); stroke(255,0,0); //red point(0,0);

stroke(0,255,0); //blue point(0,480);

stroke(0,0,255);//green point(mouseX,mouseY);

stroke(0); //black point(640,0);

stroke(255); //white point(640,480);

noStroke; fill(0,0,255,128); rectMode(CENTER); rect(mouseX,mouseY,100,200);

stroke(255,0,0); strokeWeight(5); point(132,144); } code

code size(640,480); smooth;
 * 1. drawing commands**

background(0);

stroke(128); //grey strokeWeight(5); line(0,0,640,480); line(0,480,640,0); line(320,0,320,480);

strokeWeight(20); stroke(255,0,0); //red point(0,0);

stroke(0,255,0); //blue point(0,480);

stroke(0,0,255);//green point(320,240);

stroke(0); //black point(640,0);

stroke(255); //white point(640,480);

noStroke; fill(0,0,255); rectMode(CENTER); rect(132,144,100,200);

stroke(255,0,0); strokeWeight(5); point(132,144); code