Skip to content

Commit 63cec82

Browse files
author
Jeremy Silver
committed
Clean up 1.3.05
1 parent 759d0a9 commit 63cec82

File tree

3 files changed

+99
-7
lines changed

3 files changed

+99
-7
lines changed

1.3.05-Exercise-DrawASpiral/README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Draw a Spiral
2+
3+
In this exercise, you'll take a project that draws a bunch of concentric rentanges, and modify it to draw a spiral instead! This is just to get some more practice with LibGDX drawing, but also to challenge your geometric reasoning. Go hit up the TODOs if you want to give it a try!
4+
5+
6+
# Hint below! Spoilers!
7+
8+
.
9+
.
10+
.
11+
.
12+
.
13+
.
14+
.
15+
.
16+
.
17+
.
18+
.
19+
.
20+
.
21+
.
22+
.
23+
.
24+
.
25+
.
26+
.
27+
.
28+
.
29+
.
30+
.
31+
.
32+
.
33+
.
34+
35+
36+
37+
38+
39+
40+
41+
42+
43+
44+
45+
46+
47+
48+
49+
50+
51+
52+
53+
54+
55+
56+
57+
```
58+
┌────┐ ┌────┐
59+
│┌──┐│ │┌──┐│ ┌──┐ ┌──┐
60+
││┌┐││ ││┌┐││ │┌┐│ │┌┐│ ┌┐ ┌┐
61+
││└┘││ │└─┘││ │└┘│ └─┘│ └┘ ─┘
62+
│└──┘│ └───┘│ └──┘ ───┘
63+
└────┘ ─────┘
64+
```
65+

1.3.05-Exercise-DrawASpiral/core/src/com/udacity/gamedev/drawaspiral/DrawASpiral.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,36 @@
77
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
88
import com.badlogic.gdx.math.Vector2;
99

10+
/**
11+
* TODO: Start here
12+
*
13+
* In this exercise we have a project that draws a number of concentric rectangles as specified in
14+
* the COILS constant. The space between the rectangles is given by xStep and yStep.
15+
*
16+
* The rectangles are drawn using four lines between five points. Your task is to adjust the first
17+
* and last point such that each rectangle turns into a coil that meets up with the neighboring
18+
* coils inside and outside of it.
19+
*/
20+
1021
public class DrawASpiral extends ApplicationAdapter {
1122

12-
ShapeRenderer shapeRenderer;
23+
// How many rectangles/coils to draw
1324
private static final int COILS = 20;
25+
ShapeRenderer shapeRenderer;
1426

1527
@Override
16-
public void create () {
28+
public void create() {
1729
shapeRenderer = new ShapeRenderer();
1830
}
1931

2032
@Override
21-
public void render () {
33+
public void dispose() {
34+
super.dispose();
35+
shapeRenderer.dispose();
36+
}
37+
38+
@Override
39+
public void render() {
2240
Gdx.gl.glClearColor(0, 0, 0, 1);
2341
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
2442

@@ -29,7 +47,7 @@ public void render () {
2947
int xStep = screenWidth / 2 / COILS;
3048
int yStep = screenHeight / 2 / COILS;
3149

32-
for (int i = 0; i < COILS; i++){
50+
for (int i = 0; i < COILS; i++) {
3351

3452
int xOffset = xStep * i;
3553
int yOffset = yStep * i;
@@ -39,17 +57,15 @@ public void render () {
3957
Vector2 point2 = new Vector2(screenWidth - xOffset, yOffset);
4058
Vector2 point3 = new Vector2(screenWidth - xOffset, screenHeight - yOffset);
4159
Vector2 point4 = new Vector2(xOffset, screenHeight - yOffset);
60+
4261
// TODO: Make this coil stop before connecting back to itself
4362
Vector2 point5 = new Vector2(xOffset, yOffset);
4463

4564
shapeRenderer.line(point1, point2);
4665
shapeRenderer.line(point2, point3);
4766
shapeRenderer.line(point3, point4);
4867
shapeRenderer.line(point4, point5);
49-
5068
}
51-
52-
5369
shapeRenderer.end();
5470
}
5571
}

1.3.05-Solution-DrawASpiral/core/src/com/udacity/gamedev/drawaspiral/DrawASpiral.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
88
import com.badlogic.gdx.math.Vector2;
99

10+
/**
11+
* TODO: Start here
12+
*
13+
* In this exercise we have a project that draws a number of concentric rectangles as specified in
14+
* the COILS constant. The space between the rectangles is given by xStep and yStep.
15+
*
16+
* The rectangles are drawn using four lines between five points. Your task is to adjust the first
17+
* and last point such that each rectangle turns into a coil that meets up with the neighboring
18+
* coils inside and outside of it.
19+
*/
20+
1021
public class DrawASpiral extends ApplicationAdapter {
1122

1223
ShapeRenderer shapeRenderer;

0 commit comments

Comments
 (0)