Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. float cubos[] = new float[20]; //vector de cubos
  2. int menor, actual;
  3.  
  4. void setup() {
  5. fullScreen(P3D); //tamaño de la pantalla
  6. inicializar();
  7. frameRate(5);
  8. }
  9.  
  10.  
  11. void draw() {
  12. menor=actual;
  13. for (int i=actual; i<cubos.length; i++) {
  14. if (cubos[menor]<cubos[i]){
  15. menor=i;
  16. }
  17. }
  18.  
  19. float aux=cubos[menor];
  20. cubos[menor]=cubos[actual];
  21. cubos[actual]=aux;
  22. actual++;
  23. mostrar();
  24. if (actual==cubos.length)noLoop();
  25. }
  26.  
  27.  
  28.  
  29. void mostrar() {
  30. background(255); //código de los cubos en 3D
  31. for (int i = 0; i < cubos.length; i++) {
  32. pushMatrix();
  33. stroke(0);
  34. translate(map(i, 0, cubos.length, width/cubos.length, width), height/2);
  35. rotateX(0.5);
  36. noFill();
  37. fill(random(255),random(255),random(255));
  38. box(cubos[i]);
  39. popMatrix();
  40. }
  41. }
  42.  
  43. void inicializar() {
  44. menor=0;
  45. actual=0;
  46. for (int i = 0; i < cubos.length; i++) {
  47. cubos[i] = random(100);
  48. }
  49. }
  50. void mousePressed(){//al presionar click se reinica el programa
  51.  
  52. inicializar();
  53. loop();
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement