Child geom as display pixels

About advanced scenes, and the Thyme scripting language used in Algodoo.

Child geom as display pixels

Postby Kilinich » Thu Dec 23, 2010 10:46 pm

Last few scenes I've implementing parent-child geoms into something useful.
Looks like big display is best it can be used for.

Scripts is pretty simple:

Code: Select all
(e)=>{
// create display inside laser object
    e.laser.display := [];

// fill it with pixels
    for(34, (x)=>{
        line := [];
        for(24, (y)=>{
            line = line ++ [scene.addbox({
                pos := e.pos + [x, y] * 0.01;
                size := [0.01, 0.01];
                color := [0, 0, 0, 0.1];
                drawBorder := false;
                collideSet := 8;
                body = 13;
                glued := true
            })]
        });
        e.laser.display = e.laser.display ++ [line];

// in my case I need only one pixel per row so let's create variables for it
        eval("e.laser.row" + x + " := []")
    });

// now replace this onLaserHit with new code for displaying pixels
    e.laser.onLaserHit := (e)=>{
        for(scene.my.cmdCount, (c)=>{
            cmd := scene.my.cmdQueue(c);
//parse command queue and update pixels color
            x := cmd(0);
            y := cmd(1);
            ly := eval("e.laser.row" + x);
            (e.laser.display(x)(ly)).color = [0, 0, 0, 0.1];
            (e.laser.display(x)(y)).color = [0, 0, 0, 0.8];
            eval("e.laser.row" + x + " = " + y)
        });
        scene.my.cmdQueue = [];
        scene.my.cmdCount = 0
    }
}


Rating: rated 8.7
Filesize: 0.55 MB
Comments: 16
Ratings: 24
download
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: Child geom as display pixels

Postby Kilinich » Thu Dec 23, 2010 10:52 pm

Second part is Sonar script.
It's similar to Radar I've make before:

Code: Select all
(e)=>{
// store last values of probe pos and sonar data
    lx := math.toInt(e.laser.sonar.friction);
    ly := math.toInt(e.laser.sonar.controllerAcc - e.pos(1) + 24);
// Add command to display queue
    scene.my.setPixel(lx, ly);
// controllerAcc of geom hit by laser is circularly changing from 0 to 33
    x := e.geom.controllerAcc;
// kill prev sonar object
    e.laser.sonar.density = 0;
// create new sonar probe object
    e.laser.sonar = scene.addbox({
        friction := x;
        pos := e.pos - [17 - x, 12];
        size := [1, 24];
        color := [0, 0, 0, 0];
        drawBorder := false;
        collideSet := 2;
        controllerAcc := e.pos(1) - 24;
        density := 1e-007;
// store highest contact in controllerAcc
        onCollide := (e)=>{e.pos(1) > controllerAcc ? {controllerAcc = e.pos(1)} : {}}
    })
}
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: Child geom as display pixels

Postby Kilinich » Thu Dec 23, 2010 11:09 pm

Oh, and last thing - scene.my code and variables to communicate between sonar and display:

Code: Select all
scene.my.cmdCount := 0;
scene.my.cmdQueue := []
Scene.my.setPixel := (x, y)=>{
    scene.my.cmdCount = scene.my.cmdCount + 1;
    scene.my.cmdQueue = scene.my.cmdQueue ++ [[x, y]]
}
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 2 guests