Browse Source

Begin drawing proper stars. It doesn't work yet (more bug spray needed :P).

master
Starbeamrainbowlabs 2 years ago
parent
commit
e804d9cd02
2 changed files with 38 additions and 2 deletions
  1. 37
    1
      Star.js
  2. 1
    1
      package.json

+ 37
- 1
Star.js View File

@@ -9,9 +9,38 @@ class Star
9 9
 		this.canvas = inCanvas;
10 10
 		
11 11
 		this.position = inPosition;
12
+		this.points = 5;
13
+		
12 14
 		this.size = inSize;
15
+		this.innerRingSize = this.size * 0.6;
13 16
 		
14 17
 		this.colour = "white";
18
+		
19
+		this.recalculatePoints();
20
+	}
21
+	
22
+	/**
23
+	 * The step around a circle (in radians) between each point (both inner and
24
+	 * outer) on the star.
25
+	 * Used by recalculatePoints().
26
+	 * @return {number} The step around a circle between each point on the star.
27
+	 */
28
+	get pointStep()
29
+	{
30
+		return (Math.PI * 2) / (this.points * 2);
31
+	}
32
+	
33
+	recalculatePoints()
34
+	{
35
+		this.points = [];
36
+		for (let n = 0, i = 0; n < Math.PI * 2; n += this.pointStep, i++)
37
+		{
38
+			let currentSize = i % 2 == 0 ? this.size : this.innerRingSize;
39
+			this.points.push(new Vector(
40
+				currentSize * Math.cos(Math.PI * 2 * (n / this.points * 2) + this.rotation - Math.PI / 2),
41
+				currentSize * Math.sin(Math.PI * 2 * (n / this.points * 2) + this.rotation - Math.PI / 2)
42
+			));
43
+		}
15 44
 	}
16 45
 	
17 46
 	update(dt)
@@ -23,9 +52,16 @@ class Star
23 52
 	{
24 53
 		context.save();
25 54
 		context.translate(this.position.x, this.position.y);
55
+		// TODO: Debug this
56
+		context.beginPath();
57
+		context.moveTo(this.points[0].x, this.points[0].y);
58
+		for (let point of this.points) {
59
+			context.lineTo(point.x, point.y);
60
+		}
61
+		context.closePath();
26 62
 		
27 63
 		context.fillStyle = this.colour;
28
-		context.fillRect(-5, -5, 10, 10);
64
+		context.fill();
29 65
 		
30 66
 		context.restore();
31 67
 	}

+ 1
- 1
package.json View File

@@ -9,7 +9,7 @@
9 9
 	"scripts": {
10 10
 		"env": "env",
11 11
 		"test": "echo (There aren't any tests yet!)",
12
-		"start": "wzrd $npm_package_main:$npm_package_config_browserify_bundle & sensible-browser http://localhost:9966/",
12
+		"start": "wzrd $npm_package_main:$npm_package_config_browserify_bundle & sleep 1; sensible-browser http://localhost:9966/",
13 13
 		"stop": "kill $(pgrep --full wzrd)",
14 14
 		"build": "browserify $npm_package_main -t rollupify -o $npm_package_config_browserify_bundle",
15 15
 		"build.dev": "browserify $npm_package_main -t rollupify -o $npm_package_config_browserify_bundle --debug",

Loading…
Cancel
Save