Processing

This is our group’s sketch using processing. This is the path that our robot will follow. This has 5 main divisions which will be the tiles. Each main division (tile) is divided into three.

Our robot will navigate through the middle of the tiles following the path shown below.

The code includes an animation showing how the robot will follow this path

int screenXValue = 500;
int screenYvalue = screenXValue;
int nbOfInnerDivisions = 3;
int nbOfOuterHorizontalLines = 5;
int nbOfOuterVerticalLines =  nbOfOuterHorizontalLines;
int nbOfInnerHorizontalLines = nbOfOuterHorizontalLines * nbOfInnerDivisions;
int nbOfInnerVerticalLines = nbOfInnerHorizontalLines;
int xpos;
int ypos;
float rectWidth;
float rectHeight;
float HorizontalGap;
float VerticalGap;
int k;

void setup()
{
size (screenXValue,screenYvalue);
background (100,150,150);
drawLines(255,255,255,nbOfInnerHorizontalLines, nbOfInnerVerticalLines);
drawLines(0,0,0,nbOfOuterHorizontalLines, nbOfOuterVerticalLines);
HorizontalGap = (float)height/nbOfInnerHorizontalLines;
VerticalGap = (float)width/nbOfInnerVerticalLines;
rectWidth =  (screenXValue/nbOfOuterHorizontalLines)/nbOfInnerDivisions-1;
rectHeight = (screenYvalue/nbOfOuterVerticalLines)/nbOfInnerDivisions-1;
drawRects(VerticalGap, HorizontalGap);
xpos = (int)HorizontalGap + 1;
ypos = (int)VerticalGap + 1;
k = 0;
}

void draw()
{
animateSquare();
}

void drawLines(int r, int g, int b, int nbOfHorizontalLines, int nbOfVerticalLines)
{
stroke(r,g,b);
float distanceBetweenHorizontalLines = (float)height/nbOfHorizontalLines; //giving the distance between the lines a constant value
float distanceBetweenVerticalLines = (float)width/nbOfVerticalLines;
for(int i = 0; i < nbOfHorizontalLines; i++)
{
line(0, i*distanceBetweenHorizontalLines, width, i*distanceBetweenHorizontalLines);
}
for(int i = 0; i < nbOfVerticalLines; i++)
{
line (i*distanceBetweenVerticalLines,0,i*distanceBetweenVerticalLines, height);
}
}

void drawRects(float xpos, float ypos)
{
fill(100);
rect(xpos+1, ypos+1,rectWidth, rectHeight*4+4);
rect(xpos*2+2, ypos*4+1, rectWidth*6+5, rectHeight);
rect(xpos*2+2, ypos+1, rectWidth*3, rectHeight);
rect(xpos*4+1, ypos*2+2, rectWidth, rectHeight*6+5);
rect(xpos*7+1, ypos*5+2, rectWidth, rectHeight*6+5);
rect(xpos*8+2, ypos*10+1, rectWidth*6+5, rectHeight);
rect(xpos*5+2, ypos*7+1, rectWidth*6+5, rectHeight);
rect(xpos*10+1, ypos*8+2, rectWidth, rectHeight*5+3);
rect(xpos*13+1, ypos*11+2, rectWidth, rectHeight*3+1);
rect(xpos*10+1, ypos*13+1, rectWidth*3+1, rectHeight);
fill(255);
}

void animateSquare()
{
if(k>=0 && k< (VerticalGap*3))
{
rect(xpos, ypos++, rectWidth, rectHeight);
//delay(50);
}
else if(k>=(VerticalGap*3) && k<(VerticalGap*9))
{
rect(xpos++, ypos, rectWidth, rectHeight);
//delay(50);
}
else if(k>=(VerticalGap*9) && k<(VerticalGap*15))
{
rect(xpos, ypos++, rectWidth, rectHeight);
//delay(50);
}
else if(k>=(VerticalGap*15) && k<(VerticalGap*21))
{
rect(xpos++, ypos, rectWidth, rectHeight);
//delay(50);
}
else if(k>=(VerticalGap*21) && k<(VerticalGap*24))
{
rect(xpos, ypos++, rectWidth, rectHeight);
//delay(50);
}
else if(k>=(VerticalGap*24) && k<(VerticalGap*27))
{
rect(xpos–, ypos, rectWidth, rectHeight);
//delay(50);
}
else if(k>=(VerticalGap*27) && k<(VerticalGap*33))
{
rect(xpos, ypos–, rectWidth, rectHeight);
//delay(50);
}
else if(k>=(VerticalGap*33) && k<(VerticalGap*39))
{
rect(xpos–, ypos, rectWidth, rectHeight);
//delay(50);
}
else if(k>=(VerticalGap*39) && k<(VerticalGap*45))
{
rect(xpos, ypos–, rectWidth, rectHeight);
//delay(50);
}
else if(k>=(VerticalGap*45) && k<(VerticalGap*48))
{
rect(xpos–, ypos, rectWidth, rectHeight);
//delay(50);
}
k++;
if(k >=VerticalGap*48) setup();
}

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: