Entradas

Mostrando entradas de octubre, 2025

bola que rebota una con otra python

 r = 20 x = [100, 300] y = [200, 200] vx = [2, -3] vy = [3, -2] def setup():     size(400, 400) def draw():     background(255)          for i in range(2):         x[i] += vx[i]         y[i] += vy[i]         if x[i] < r or x[i] > width - r:             vx[i] *= -1         if y[i] < r or y[i] > height - r:             vy[i] *= -1     dx = x[1] - x[0]     dy = y[1] - y[0]          dist = sqrt(dx*dx + dy*dy)          if dist < r * 2:         vx[0] *= -1         vy[0] *= -1         vx[1] *= -1         vy[1] *= -1     for i in range(2):         ellipse(x[i], y[i], r*2, r*2)

Coches de lado a lado en python

numcoches = 10 cars = []  def setup():     size(800, 600)     global cars     cars = []     for i in range(numcoches):         c = color(random(0, 255), random(0, 255), random(0, 255))         xpos = random(20, width - 20)         ypos = random(20, height - 20)         xspeed = random(-5, 5)             while (xspeed) < 1:             xspeed = random(-5, 5)         cars.append(Car(c, xpos, ypos, xspeed)) def draw():     background(255)     for car in cars:         car.drive()         car.display() class Car:     def __init__(self, tempC, tempXpos, tempYpos, tempXspeed):         self.c = tempC         self.xpos = tempXpos         self.ypos = tempYpos ...

Bola que se choca con coche y para python

r = l = u = d = False x = 50 y = 50 numcoches = 30 xbola = 30 ybola = 30 cars = []  def setup():     size(800, 800)     frameRate(80)          global cars     for i in range(numcoches):         c = color(random(255), random(255), random(255))         xpos = random(10, width - 10)         ypos = random(10, height - 10)         xspeed = random(-5, 5)         cars.append(Car(c, xpos, ypos, xspeed)) def draw():     global x, y     background(0)          ellipse(x, y, xbola, ybola)     if r:         x += 1     if l:         x -= 1     if u:         y -= 1     if d:         y += 1         for car in cars:         car.drive()   ...

coches arriba abajo python

def setup():     size(600, 400)     global myCar1, myCar2     myCar1 = Car(color(51), 450, 100, 5)     myCar2 = Car(color(151), 150, 50, -2) def draw():     background(255)          myCar1.move()     myCar1.display()          myCar2.move()     myCar2.display() class Car:     def __init__(self, c, xpos, ypos, yspeed):         self.c = c         self.xpos = xpos         self.ypos = ypos         self.yspeed = yspeed     def display(self):         stroke(0)         fill(self.c)         rectMode(CENTER)         rect(self.xpos, self.ypos, 20, 10)     def move(self):         self.ypos += self.yspeed         if self.ypos > height and self.yspeed ...

coches de lado a lado python

def setup():     size(800, 600)     global myCar1, myCar2     myCar1 = Car(color(255, 0, 0), 800, 100, -5)     myCar2 = Car(color(0, 0, 255), 0, 10, 5) def draw():     background(255)     myCar1.drive()     myCar1.display()     myCar2.drive()     myCar2.display() class Car:     def __init__(self, c, xpos, ypos, xspeed):         self.c = c         self.xpos = xpos         self.ypos = ypos         self.xspeed = xspeed     def display(self):         stroke(0)         fill(self.c)         rectMode(CENTER)         rect(self.xpos, self.ypos, 20, 10)     def drive(self):         self.xpos += self.xspeed         if self.xpos > width:             se...

Codigo de linea con parametros python

 

Codigo bola con flechas python

x = 50 y = 50 r = False l = False u = False d = False def setup():     size(800, 800)     frameRate(200) def draw():     global x, y     background(255)     ellipse(x, y, 75, 75)          if r:         x += 1     if l:         x -= 1     if u:         y -= 1     if d:         y += 1 def keyPressed():     global r, l, u, d     if keyCode == RIGHT:         r = True     if keyCode == LEFT:         l = True     if keyCode == UP:         u = True     if keyCode == DOWN:         d = True def keyReleased():     global r, l, u, d     if keyCode == RIGHT:         r = False     if keyCode == LEFT:         l = False ...

hacer una linea en python

 Pos = 0.0 def setup():  # setup() runs once     size(800, 500)     frameRate(30) def draw():  # draw() loops forever, until stopped     background(200)     yPos = yPos - 1.0     if yPos < 0:     yPos = height     line(0, yPos, width, yPos) def setup():     size(800, 400) # Although empty here, draw() is needed so # the sketch can process user input events # (mouse presses in this case). def draw():     pass def mousePressed():         line(mouseX, 100, mouseX, 800)

Python

1 Dos puntos (4 variables) Dibujar segmentos que definen Calcular y mostrar longitud. 2 Hacer el calculo de la longitud del segmento con una función propia.

bola que rebotan una con otra

float x1, y1, p, w; float x2, y2, m, k; float r= 20; void setup() {   size(400, 400);   x1 = 100; y1 = 200; p = 2; w = 3;   x2 = 300; y2 = 200; m = -3; k = -2; } void draw() {   background(255);        x1 += p;   y1 += w;   x2 += m;   y2 += k;         if (x1 < r  || x1 > width - r) p *= -1;   if (y1 < r  || y1 > height - r) w *= -1;   if (x2 < r  ||  x2 > width - r) m *= -1;   if (y2 < r || y2 > height - r) k *= -1;      float dx = x2 - x1;   float dy = y2 - y1;   float dist = sqrt(dx*dx + dy*dy);   if (dist < r * 2) {     p *= -1;     w *= -1;     m *= -1;     k *= -1;   }      ellipse(x1, y1, r*2, r*2);   ellipse(x2, y2, r*2, r*2); } arrays obj

Bola que se para si se choca con otra

  float x1, y1;         float vx1, vy1;      float r1 = 30;         float x2, y2; float vx2, vy2; float r2 = 40; color c1, c2; void setup() {   size(600, 400);        x1 = random(r1, width - r1);   y1 = random(r1, height - r1);   vx1 = random(2, 5);   vy1 = random(2, 5);     x2 = random(r2, width - r2);   y2 = random(r2, height - r2);   vx2 = random(2, 5);   vy2 = random(2, 5);   c2 = color(100, 100, 255);  }