Why? Because I can! There is simply no use for this, but it’s satisfying to get it working. Just another script…

Why? Because I can! There is simply no use for this, but it’s satisfying to get it working. Just another script…

]]>

11 Commentsto Why? Because I can! There is simply no use for this, but it’s satisfying to get it working. Just another script…

  1. Anonymous says:

    < ![CDATA[

    But… How? Custom view?

    ]]>

  2. Anonymous says:

    < ![CDATA[

    Benoît de Chezelles just a normal item. I’m using the box background to have a high enough resolution.

    ]]>

  3. Anonymous says:

    < ![CDATA[

    That would be a cool boot animation

    ]]>

  4. Anonymous says:

    < ![CDATA[

    …now map 6 apps’ icons on the sides and make the clickable 😀

    ]]>

  5. Anonymous says:

    < ![CDATA[

    Fun! Canvas and polygons?

    ]]>

  6. Anonymous says:

    < ![CDATA[

    Pierre Hébert Basically yes.

    ]]>

  7. Anonymous says:

    < ![CDATA[

    Lutz Linke that would be extremely annoying. It already is at maximum speed, so you’d have to wait a long time to start apps on the back. Plus, I’d have to learn how to use transformation matrizes.

    ]]>

  8. Anonymous says:

    < ![CDATA[

    Nice! I won’t care in seeing the script 😛



    What about use the container scrolling to turn the cube?

    ]]>

  9. Anonymous says:

    < ![CDATA[

    I wonder whether it would be possible to instantiate a GLSurface view and throw some basic gl commands at it.

    ]]>

  10. Anonymous says:

    < ![CDATA[

    Lukas Morawietz could you post the script? (Or send it to me? )


    Thanks

    ]]>

  11. Anonymous says:

    < ![CDATA[

    //code adpated from http://codentronix.com/2011/05/10/html5-experiment-a-rotating-solid-cube/




    function Point3D(x,y,z) {


    this.x = x;


    this.y = y;


    this.z = z;



    this.rotateX = function(angle) {


    var rad, cosa, sina, y, z;


    rad = angle * Math.PI / 180;


    cosa = Math.cos(rad);


    sina = Math.sin(rad);


    y = this.y * cosa – this.z * sina;


    z = this.y * sina + this.z * cosa;



    return new Point3D(this.x, y, z);


    }



    this.rotateY = function(angle) {


    var rad, cosa, sina, x, z;


    rad = angle * Math.PI / 180;


    cosa = Math.cos(rad);


    sina = Math.sin(rad);


    z = this.z * cosa – this.x * sina;


    x = this.z * sina + this.x * cosa;



    return new Point3D(x,this.y, z);


    }



    this.rotateZ = function(angle) {


    var rad, cosa, sina, x, y;


    rad = angle * Math.PI / 180;


    cosa = Math.cos(rad);


    sina = Math.sin(rad);


    x = this.x * cosa – this.y * sina;


    y = this.x * sina + this.y * cosa;



    return new Point3D(x, y, this.z);


    }



    this.project = function(viewWidth, viewHeight, fov, viewDistance) {


    var factor, x, y;


    factor = fov / (viewDistance + this.z);


    x = this.x * factor + viewWidth / 2;


    y = this.y * factor + viewHeight / 2;



    return new Point3D(x, y, this.z);


    }


    }



    var vertices = [


    new Point3D(-1,1,-1),


    new Point3D(1,1,-1),


    new Point3D(1,-1,-1),


    new Point3D(-1,-1,-1),


    new Point3D(-1,1,1),


    new Point3D(1,1,1),


    new Point3D(1,-1,1),


    new Point3D(-1,-1,1)


    ];


    // Define the vertices that compose each of the 6 faces. These numbers are


    // indices to the vertex list defined above.


    var faces  = [[0,1,2,3],[1,5,6,2],[5,4,7,6],[4,0,3,7],[0,4,5,1],[3,2,6,7]];



    // Define the colors for each face.


    var colors = [[255,0,0],[0,255,0],[0,0,255],[255,255,0],[0,255,255],[255,0,255]];


    var angle = 0;


    var item=LL.getEvent().getItem();


    var img=LL.createImage(item.getWidth(),item.getHeight());


    var ctx=img.draw();


    loop();



    function loop() {


    var t = new Array();


    ctx.drawRGB(0,0,0);


    for( var i = 0; i < vertices.length; i++ ) {


    var v = vertices[i];


    var r = v.rotateX(angle).rotateY(angle);


    var p = r.project(img.getWidth()-20,img.getHeight()-20,200,4);


    t.push(p);


    }



    var avg_z = new Array();



    for( var i = 0; i < faces.length; i++ ) {


    var f = faces[i];


    avg_z[i] = {“index”:i, “z”:(t[f[0]].z + t[f[1]].z + t[f[2]].z + t[f[3]].z) / 4.0};


    }



    avg_z.sort(function(a,b) {


    return b.z – a.z;


    });



    for( var i = 0; i < faces.length; i++ ) {


    var f = faces[avg_z[i].index]


    var p=new Path();


    p.moveTo(t[f[0]].x,t[f[0]].y);


    p.lineTo(t[f[1]].x,t[f[1]].y);


    p.lineTo(t[f[2]].x,t[f[2]].y);


    p.lineTo(t[f[3]].x,t[f[3]].y);



    var paint=new Paint();


    paint.setARGB(255,colors[avg_z[i].index][0],colors[avg_z[i].index][1],colors[avg_z[i].index][2]);


    ctx.drawPath(p,paint);



                }



                angle += 1;


    img.update();


    item.setBoxBackground(img,”nfs”);


    if(!LL.isPaused())setTimeout(loop,0);


    }

    ]]>

Leave a Reply

Your email address will not be published. Required fields are marked *