kramann.info
© Guido Kramann

Login: Passwort:










kramann.info
© Guido Kramann

Login: Passwort:




Simulation of LUAbot

(EN google-translate)

(PL google-translate)

LUAbot003_SIM.zip -- Processing Project.
LUAbot[] luabot = new LUAbot[8];
public void setup()
{
    size(640,640);
    frameRate(20);
    for(int i=0;i<luabot.length;i++)
    {
       luabot[i] = new LUAbot(80+i*60,80,30.0*i,(i%2)*127+128,((i/2)%2)*127+128,((i/4)%2)*127+128);
       luabot[i].setV(5);
    }   
}
public void draw()
{
    scale(1,-1); //coordinate transformation
    translate(0,-640);
    background(255);
    noFill();
    stroke(0);
    strokeWeight(height/200);
    ellipse(20,20,40,40);
    line(20,20,40,20);
    
    for(int i=0;i<luabot.length;i++)
    {
       luabot[i].draw();
       for(int k=0;k<10;k++) //Animation ten times faster
           luabot[i].timestep();
    }   
}

Code 0-1: LUAbot003_SIM

public class LUAbot
{
    float R=20.0;
    float x,y,phi; //position orientation
    float v,w;     //speed pixel per second, angular speed degree per second
    int r,g,b;     //color RED GREEN BLUE
    public LUAbot(float x, float y, float phi, int r, int g, int b)
    {
        this.x=x;
        this.y=y;
        this.phi=phi;
        this.r=r;
        this.g=g;
        this.b=b;
        
        v=0.0;
        w=0.0;
    }
    
    public void setV(int v) //Pixel pro Sekunde
    {
        if(v>20) v=20;
        if(v<-20) v=-20;
        this.v = v*0.05; //Pixel per timestep
    }
    
    public void setW(int w) //Degree per second
    {
        if(w>20) w=20;
        if(w<-20) w=-20;
        this.w = w*0.05; //degree per timestep of 0,05s (1/20s)
    }
    
    public void timestep()
    {
        //Integration angular speed:
        phi+=w;
        //  0<=phi<360:
        if(phi<0.0)
            phi+=(1.0-floor(phi/360.0))*360.0;
        phi=phi - floor(phi/360.0)*360.0;
        float p = phi*PI/180.0;
        //Integration translational speed:
        x+=v*cos(p);
        y+=v*sin(p);
    }
    
    public void draw()
    {
        stroke(0);
        fill(r,g,b);
        ellipse(x,y,R*2,R*2);
        float p = phi*PI/180.0;
        line(x,y,x+R*cos(p),y+R*sin(p));
    }
}

Code 0-2: Tab LUAbot