-
Notifications
You must be signed in to change notification settings - Fork 0
/
Voronoi.java
68 lines (54 loc) · 1.64 KB
/
Voronoi.java
1
2
3
4
5
6
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
66
67
68
package com.gdxtemplate.game;
import java.util.Random;
import com.badlogic.gdx.*;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
/*
------Initialising-Pseudocode------
1) Check number of points to be created
2) Generate a random x and y co-ordinate 0<=n<=400
3) Assign to a point
4) Repeat 2,3 until desired number of points
------Event-Queue-High-Level-Pseudocode------
1) Scan for next focus
2) Update Directrix with y = focus y
3) Update Parabola to current Directrix
4) Check for current meetings of parabola
5) Draw (optional)
*/
public class Voronoi extends ApplicationAdapter {
/*
Creation of all variables used within the main program
*/
ShapeRenderer sr;
Foci Foci = new Foci();
Render Render = new Render();
Directrix Directrix = new Directrix();
Maths Maths = new Maths();
private Random generate = new Random();
int usedFoci = 0;
@Override
public void create () {
sr = new ShapeRenderer();
int max = generate.nextInt(10) + 10; ///Creates an array of a random length between 10 and 20
usedFoci = max;
Foci.CreateArray(max);
for (int i = 0; i < max-1; i++) {
Foci.Generate(i, generate); ///Generates points up to the number created
}
}
@Override
public void render() { ///Main event queue
Gdx.gl.glClearColor(0,0,0,0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
Foci.FociSort();
if (usedFoci < Foci.GetMax() && usedFoci > -1) { ///Ensures that the program does not error by preventing OOB errors
Directrix.SetY(Foci.FociSort()[usedFoci][1]);
}
Render.Cycle(sr, Foci, Directrix, Maths);
usedFoci--;
}
@Override
public void dispose () {
}
}