Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float cubos[] = new float[20]; //vector de cubos
- int menor, actual;
- void setup() {
- fullScreen(P3D); //tamaño de la pantalla
- inicializar();
- frameRate(5);
- }
- void draw() {
- menor=actual;
- for (int i=actual; i<cubos.length; i++) {
- if (cubos[menor]<cubos[i]){
- menor=i;
- }
- }
- float aux=cubos[menor];
- cubos[menor]=cubos[actual];
- cubos[actual]=aux;
- actual++;
- mostrar();
- if (actual==cubos.length)noLoop();
- }
- void mostrar() {
- background(255); //código de los cubos en 3D
- for (int i = 0; i < cubos.length; i++) {
- pushMatrix();
- stroke(0);
- translate(map(i, 0, cubos.length, width/cubos.length, width), height/2);
- rotateX(0.5);
- noFill();
- fill(random(255),random(255),random(255));
- box(cubos[i]);
- popMatrix();
- }
- }
- void inicializar() {
- menor=0;
- actual=0;
- for (int i = 0; i < cubos.length; i++) {
- cubos[i] = random(100);
- }
- }
- void mousePressed(){//al presionar click se reinica el programa
- inicializar();
- loop();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement