Entradas

Mostrando entradas de septiembre, 2025

Coches que se chocan con una bola

boolean r, l, d, u; float x = 50, y = 50; int numcoches = 30;   int xbola=30;  int ybola=30; Car[] cars = new Car[numcoches];  // Declaramos el arreglo de coches void setup() {   size(800, 800);   frameRate(80);    for (int i = 0; i < numcoches; i++) {     cars[i] = new Car(color(random(255), random(255), random(255)), random(10, width - 10), random(10, height - 10), random(-5, 5));   } } void draw() {   background(0);   ellipse(x, y, xbola, ybola);   if (r) x += 1;   if (l) x -= 1;   if (u) y -= 1;   if (d) y += 1;   for (int i = 0; i < numcoches; i++) {     cars[i].drive();     if(dist(x,y,cars[i].xpos,cars[i].ypos )<27){     noLoop();   }     cars[i].display();   } } void keyPressed() {   if (keyCode == RIGHT) r = true;   if (keyCode == LEFT) l = true;   if (keyCode == UP) u = true;   if (keyCode == DOWN) d = true; } ...

Coches infinitos

int numcoches = 10;  Car[] cars = new Car[numcoches];  // Declaramos el arreglo de coches void setup() {   size(800, 600);      // Inicializamos los coches en el ciclo   for (int i = 0; i < numcoches; i++) {     cars[i] = new Car(color(random(0, 255), random(0, 255), random(0, 255)),random(10, width - 10),random(10, height - 10),random(-5, 5));   } } void draw() {   background(255);      // Llamamos a las funciones de cada coche en el ciclo   for (int i = 0; i < numcoches; i++) {     cars[i].drive();     cars[i].display();   } } class Car {   color c;   float xpos;   float ypos;   float xspeed;   // El Constructor es definido con los argumentos   Car(color tempC, float tempXpos, float tempYpos, float tempXspeed) {     c = tempC;     xpos = tempXpos;     ypos = tempYpos;     xspeed = tempXspeed;   }   // ...

Coche arriba y abajo

Car myCar1; Car myCar2; // Two objects! void setup() {   size(600, 400);   // Arguments go inside the parentheses when the object is constructed.     myCar1 = new Car(color(51), 450, 100, 5);    myCar2 = new Car(color(151), 150, 50, -2); } void draw() {   background(255);   myCar1.move();   myCar1.display();   myCar2.move();   myCar2.display(); } // Even though there are multiple objects, only  one class is needed.  // No matter how many cookies you make, only one cookie cutter is needed. class Car {    color c;   float xpos;   float ypos;   float yspeed;   // The Constructor is defined with parameters.     Car(color tempC, float tempXpos, float tempYpos, float tempyspeed) {      c = tempC;     xpos = tempXpos;     ypos = tempYpos;     yspeed = tempyspeed;   }   void display() {     stroke(0);     fi...

Coche

 Car myCar1; Car myCar2; // Two objects! void setup() {   size(800,600);   // Parameters go inside the parentheses when the object is constructed.   myCar1 = new Car(color(255,0,0),800,100,-5);   myCar2 = new Car(color(0,0,255),0,10,5); } void draw() {   background(255);   myCar1.drive();   myCar1.display();   myCar2.drive();   myCar2.display(); } // Even though there are multiple objects, we still only need one class. // No matter how many cookies we make, only one cookie cutter is needed. class Car {   color c;   float xpos;   float ypos;   float xspeed;   // The Constructor is defined with arguments.   Car(color tempC, float tempXpos, float tempYpos, float tempXspeed) {     c = tempC;     xpos = tempXpos;     ypos = tempYpos;     xspeed = tempXspeed;   }   void display() {     stroke(0);     fill(c);     rectMode(CENTER); ...

Explicación

                      Explicación fácil de processing  Las funciones en processing son un conjunto de código que al invocar hace que puedas desarrollar tu código para crear funciones La función se ejecuta fuera del código y se ejecuta cuando tu la invocas. Principales funciones que tienes que conocer si quieres saber processing. para empezar a programar lo principal es utilizar un void que : Los void pueden ser de dos tipos void "setup"  que se ejecuta una vez al inicio para iniciar el entorno  y void "draw"  un bucle que se ejecuta continuamente para dibujar, actualizar la pantalla y manejar la interactividad.  Otras funciones esenciales incluyen las de dibujo. size() es para definir  un tamaño a la pantalla lo puedes elegir tu. fill() defines de que color quieres que sea tu objeto que se este representando. en el programa usamos noLoop()   en el setup() para que sólo se ejecute el...

Intento de reloj

  int f =100; void setup(){ size(800,600); background(200,100,0); } void draw(){   int x = millis();   noStroke();   fill(5,5,255);   text("tiempo", 50, 50); int h = hour(); int m = minute(); int s = second(); if (s = f) { println(h + ":" + m + ":" + s); f = s; } }

Degradado de color

void setup(){   size(800,600);  background(0); } void draw(){   int = c   fila(color(240,20,0)); } void fila(color c){   fill(c);   for (int i = 0; i < 320; i = i+20) {   line(800, i, 600, i); }

Linea

float x1 = 100; float y1 = 150; float x2 = 400; float y2 = 300; void setup() {   size(600, 400);   textSize(20); } void draw() {   background(255);      fill(255,255,255);   ellipse(x1, y1, 1, 1);   ellipse(x2, y2, 1, 1);      stroke(0);   line(x1, y1, x2, y2);     float distancia = dist(x1, y1, x2, y2);      fill(0);   text("Distancia: " + nf(distancia, 1, 2), 20, height - 30); }

Interrupciones flechas

  boolean r, l, d, u; float x = 50, y = 50; void setup() { size(800,800); frameRate(200); } void draw() { background(0); ellipse(x,y,75,75); if (r)x+= 1; if (l)x-= 1; if (u)y-= 1; if (d)y+= 1; } void keyPressed() { if (keyCode == RIGHT) r = true; if (keyCode == LEFT) l = true; if (keyCode == UP) u = true; if (keyCode == DOWN) d = true; } void keyReleased() { if (keyCode == RIGHT) r = false; if (keyCode == LEFT) l = false; if (keyCode == UP) u = false; if (keyCode == DOWN) d = false; }