Rename student examples
This commit is contained in:
56
drawSquare.c
56
drawSquare.c
@@ -24,7 +24,7 @@ static int actualIdx = 0;
|
||||
/* drawReferenceLine implementation. */
|
||||
void drawReferenceLine(int x0, int y0, int x1, int y1) {
|
||||
if (referenceIdx < sizeof(referenceLines) / sizeof(line_t)) {
|
||||
referenceLines[referenceIdx++] = (line_t) {x0, y0, x1, y1};
|
||||
referenceLines[referenceIdx++] = (line_t) {.x0 = x0, .y0 = y0, .x1 = x1, .y1 = y1};
|
||||
} else {
|
||||
exit(1);
|
||||
}
|
||||
@@ -33,7 +33,7 @@ void drawReferenceLine(int x0, int y0, int x1, int y1) {
|
||||
/* drawLine implementation. */
|
||||
void drawLine(int x0, int y0, int x1, int y1) {
|
||||
if (actualIdx < sizeof(actualLines) / sizeof(line_t)) {
|
||||
actualLines[actualIdx++] = (line_t) {x0, y0, x1, y1};
|
||||
actualLines[actualIdx++] = (line_t) {.x0 = x0, .y0 = y0, .x1 = x1, .y1 = y1};
|
||||
} else {
|
||||
exit(1);
|
||||
}
|
||||
@@ -41,8 +41,25 @@ void drawLine(int x0, int y0, int x1, int y1) {
|
||||
|
||||
/* drawSquare implementations follow. */
|
||||
|
||||
void drawSquareWeird(int x, int y, int len)
|
||||
static void drawSquareStudent1(int x, int y, int len) {
|
||||
if (x+len > 10){
|
||||
len = 10-x;
|
||||
}
|
||||
|
||||
if (y+len > 10){
|
||||
len = 10-y;
|
||||
}
|
||||
|
||||
drawLine(x, y, x+len, y);
|
||||
|
||||
drawLine(x, y, x, y+len);
|
||||
|
||||
drawLine(x+len, y, x+len, y+len);
|
||||
|
||||
drawLine(x, y+len, x+len, y+len);
|
||||
}
|
||||
|
||||
void drawSquareStudent2(int x, int y, int len)
|
||||
{
|
||||
|
||||
if(((x+len<10) && (x-len>= 0)) && ((y-len>0) && (y+len<=10)) && len>0)
|
||||
@@ -88,22 +105,37 @@ void drawSquareWeird(int x, int y, int len)
|
||||
}
|
||||
}
|
||||
|
||||
static void drawSquareAlmostCorrect(int x, int y, int len) {
|
||||
if (x+len > 10){
|
||||
len = 10-x;
|
||||
void drawSquareStudent3(int x, int y, int len)
|
||||
{
|
||||
if (0 <= x && x > 10 && 0 < y && y <= 10 && len > 0){
|
||||
|
||||
drawLine(x, y, x + len, y);
|
||||
|
||||
drawLine(x + len, y, x + len, y - len);
|
||||
drawLine(x + len, y - len, x, y - len);
|
||||
drawLine(x, y - len, x, y);
|
||||
}
|
||||
|
||||
if (y+len > 10){
|
||||
len = 10-y;
|
||||
else if (x + len < 0|| y - len >= 10){
|
||||
|
||||
len++;
|
||||
drawLine(x, y, x + len, y);
|
||||
|
||||
drawLine(x + len, y, x + len, y - len);
|
||||
drawLine(x + len, y - len, x, y - len);
|
||||
drawLine(x, y - len, x, y);
|
||||
}
|
||||
|
||||
drawLine(x, y, x+len, y);
|
||||
else {
|
||||
|
||||
drawLine(x, y, x, y+len);
|
||||
len--;
|
||||
|
||||
drawLine(x+len, y, x+len, y+len);
|
||||
drawLine(x, y, x + len, y);
|
||||
|
||||
drawLine(x, y+len, x+len, y+len);
|
||||
drawLine(x + len, y, x + len, y - len);
|
||||
drawLine(x + len, y - len, x, y - len);
|
||||
drawLine(x, y - len, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
/* Example drawSquare that's just drawReferenceSquare reordered. */
|
||||
|
||||
Reference in New Issue
Block a user