PROCESSING

                                                      PROCESSING COMMANDS


INT:

The first time a variable is written, it must be declared with a statement expressing its datatype. Subsequent uses of this variable must not reference the datatype because Processing will think the variable is being declared again.

a = 23;   int b = -256;   int c = a + b;  int a=a+1;



FLOAT:

When an array of int or String values is passed in, then a floating point array of the same length is returned.

int i = 65; float f = float(i); println(i + " : " + f); // Prints "65 : 65.0"


STRING:

A string is a sequence of characters.


FILL:
Sets the color used to fill shapes.
fill(153);


NOFILL:
Disables filling geometry, if noStroke is also callednothing will be drawn to the screen.
noFill();


STROKE:
Sets the color used to draw lines and borders around shapes.
stroke(153);


BACKGROUND:
sets the color used for the background of the Processing window.
background(51);

IF:
Allows the program to make a decision about which code to execute. 
  if (i < 35) {

ELSE:
Extends the if structure allowing the program to choose between two or more blocks of code.
 if (i < 140) {
    line(120, i, 320, i);
  } else {

WHILE:
The while structure executes a series of statements continuously while the expression is true.
int i = 0;
while (i < 320) {


FOR:
Controls a sequence of repetitions, The loop continues until the test evaluates to false
size(400, 400);
for (int i = 0; i < 160; i = i+1) {
  line(120, i, 320, i);
}




ALL PROCESSING CODE:

PROGRAMMING


WRITTING SENTENCES IN A LANGUAJE A COMPUTER CAN UNDERSTAND


LOW LEVEL:

-binary(machine code)

-assembler (same as binary but with words)



HIGH LEVEL:

-C++    

-python

-javascript

-processing

IDE= Interface Development Enviroment

with 1 sentence of Hl you can write thousands of LL





PROCESSING

BASIC STRUCTURE


-1 define variables

-2 create setup group

-3 create draw group

-4 create modules





int a=5;

void setup(){

size (800,600);

fill(0);

}

void draw(){   —----------------> void draw= repetir infinitamente

a=a+1;

draw();

}

void dibuja(){

textSize(30);

text(a,300,200);

}

BASIC COMMANDS


COLOR:


-fill(R,G,B);            fill(55,23,231);        fill(55);

//selecciona el boligrafo de color x//


-background(0,255,3);

//borra el fondo y ponlo de x color//


-text(a,400,300);                      text(a,400,300);  —----->variable

                                                text(“a”,400,300); —--→ literal

escribe un texto x en coordenadas x,y



más comandos:

rect(a,b,c,d);

rectMode(CENTER);



hacer resumen de:

-int

-float

-string

-fill

-nofill

-stroke

-background

-if

-else

-while 

-for



codigo fraccional:

int f=1;

int n=7;


void setup(){

  size(800,600);

  background(0);

  fill(255);

}

void draw(){

  for (int i = 1; i <= n; i = i +1){

    f = f*i;

  }

  text("el factorial de"+n+"es:"+f, 400, 300);

    noLoop();

  }

CALCULAR HIPOTENUSA:

codigo principal:

int c1=5;  //cateto1//

int c2=8;  //cateto2//

float h;


void setup(){

 background(0);

 size(600,800);

 fill(255);

}

void draw(){

   h=hipotenusa (c1,c2) ;

   text(h,400,300);

   noLoop();

 }

funcion:

float hipotenusa (int c1, int c2){

float hipotenusa=sqrt(c1*c2+c1*c2);

return hipotenusa;

}





int a=7

int b=5

float a1;

float a2;

void setup(){

 background(0);

 size(600,800);

 fill(255);

}                 

void draw(){

  h=hipotenusa(a,b);

  an=angulo(a,b);

  an2angulo

  

  

  text("los angulos de un triangulos con catetos que miden"+a+ "y"+b+ "son:" a1"y"a2,300,400);

  

  

float hipotenusa (int ta, int tb){

  float th;

h=sqrt(ta*ta+tb*tb);

return th;

}

float angulo(){







TRIANGULO

int a=7;

int b=5;

float a1;

float tg;

float th;

void setup(){

 background(0);

 size(600,800);

 fill(255);

}                 

void draw(){

  th=hipotenusa(a,b);

  tg=grados(a,b);


  text("los angulos de un triangulos con catetos que miden"+a+

  "y"+b+ "son:"+ th +"y"+ tg ,100,400);

  

}



funcion:

float hipotenusa (int ta, int tb){

  float th =sqrt(ta*ta+tb*tb);

 

th=sqrt(ta*ta+tb*tb);

return th;

}

float grados (float ta, float tb){

  float tg= atan(tb/ta);

  tg=tg*360/(2*PI);

return tg;

}





ARRAYS


string nombres[] = new string[3];

string nombres2[] ={“pedro”,”ana”,”juan”}

int a[]= new int[5];

int a[]={2,4,5};



STRING

int i=250;

String[] a={"no","se","programar"};

size(800,600);

textSize(30);

textMode(CENTER);

fill(0);

background(255);

for (int x=0; x<2+1; x=x+1){

 i=i+50;

 text (a[x],400,i);

 delay(100);


 }





EJERCICIO MEDIA MAX MIN


float suma=0;

int max=0;

float min=50;

float media=0;

size(800,600);

background(255);

fill(0);

textSize(50);

rectMode(CENTER);

int []c={37,6,9,3,48};

for (int i = 0; i <=4;i=i+1) {

 suma=suma+c[i];

 media=suma/5;

  

 if (c[i]>max){

   max=c[i];

}

 if (c[i]<min){

   min=c[i];

 }

}

text(media,400,400);

text(max,400,300);

text(min, 400,200);


ARRAY 2D

int suma=0;

int max=0;

float min=50;

float media=0;

size(1600,1200);

background(0);

fill(38,205,21);

textSize(50);

rectMode(CENTER);

int [][] c={{37,6,9,3,48},

           {23,4,14,3,7}};

  

for (int i = 0; i <=1;i=i+1) {

  for (int j = 0; j <=4;j=j+1) {

 suma=suma+(c[i][j]);

 media=suma/10;

  

 if (c[i][j]>max){

   max=c[i][j];

}

 if (c[i][j]<min){

   min=c[i][j];

 }

}

}

text("la media de los numeros es:"+media,400,200);

text("el maximo de los numeros es:"+max,400,300);

text("el minimo de los numeros es:"+min, 400,400);







PARA USAR SISTEMA DE COORDS NORMAL:


xp=x+width/2

yp=lenght/2-y





size(800,600);

int x=300;

int y=-200;

int xp;

int yp;


background(0);

fill(255);

xp=x+(width/2);

yp=(height/2)-y;


text ("holabuenastardes",xp,yp);



MOUSEX MOUSEY

void setup(){

  size(800,600);

  background(0);

  textSize(30);

}

void draw(){


    fill(mouseX,mouseY,mouseX-mouseY);

 ellipse(mouseX,mouseY,mouseX+mouseY,mouseX-mouseY);

}






int x=1;

int y=1;

int n=3;


void setup(){

  size(800,600);

  background(0);

  textSize(30);

}

void draw(){

  background(0);

  fill(mouseX,mouseY);

  text("gay el que lo lea",x,y);

  x=x+n;

  y=y+n;

 if (x>800){

   x=-n; }

    if (x<0){

   x=+n; }

 if (y>600){

   y=-n;}

 if (y<0){

   y=+n; }

}





COMIENZO PING PONG

float xb = 400;

float yb = 300;

float xr = mouseX;

float vx =5;

float vy =5;

int puntos=0;

void setup() {

  size(800, 600);

  fill(255);

textSize(30);

}

void draw() {

  background(0);

    fill(255);

   xb=xb+vx;

  yb=yb+vy;


  text("puntos:"+puntos,50,50);

  ellipse(xb, yb, 30, 30);

   rect(mouseX,500,200,20);

     velocidades();

if(xb > mouseX-25 && xb < mouseX+250 && yb> 490){

vy=vy*(-1);

puntos=puntos+100;

   vx=(xb-xr)/40;;

}

if(yb>600){ 

  background(0);

  stop();

  text("GAME OVER",300,300);

  text("score:"+puntos,300,350);

}

  colisiones(); 

 }

void velocidades(){

  vy=vy*(1.0014);

  vx=vx*(1.0014);

}

void colisiones(){

  if(xb>800 ){

  vx=vx*(-1);

  }

  if(xb<0){

  vx=vx*(-1);

  }


if (yb>600){

vy=vy*(-1);

}

if(yb<0){

  vy=vy*(-1);

}

}



Comentarios