Skip to content

Commit 8d35ebd

Browse files
committed
added mouse controlled poly
1 parent 492d570 commit 8d35ebd

File tree

4 files changed

+61
-9
lines changed

4 files changed

+61
-9
lines changed

debug/apps/fast2d/src/main/java/fast2d/MainActivity.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
import processing.core.PApplet;
1212

1313
public class MainActivity extends AppCompatActivity {
14-
private int TEST = 0; // Basic self-intersecting polygon
15-
// private int TEST = 1; // SVG loading
14+
// private int TEST = 0; // Basic self-intersecting polygon
15+
private int TEST = 1; // Mouse controlled polygon
16+
// private int TEST = 2; // Load and display SVG
1617

1718
private PApplet sketch;
1819

@@ -27,8 +28,10 @@ protected void onCreate(Bundle savedInstanceState) {
2728

2829
if (TEST == 0) {
2930
sketch = new SketchBasicPoly();
30-
} if (TEST == 1) {
31-
sketch = new SketchSVG();
31+
} else if (TEST == 1) {
32+
sketch = new SketchMousePoly();
33+
} else if (TEST == 2) {
34+
sketch = new SketchLoadDisplaySVG();
3235
}
3336

3437

debug/apps/fast2d/src/main/java/fast2d/SketchBasicPoly.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ public void draw() {
2323
background(255);
2424

2525
fill(255, 0, 63, 127);
26-
stroke(255, 0, 255, 127);
27-
strokeWeight(12 * displayDensity);
28-
strokeJoin(ROUND);
29-
noStroke();
3026

3127
strokeWeight(6 * weight * displayDensity);
3228
stroke(0, 127, 95, 191);

debug/apps/fast2d/src/main/java/fast2d/SketchSVG.java renamed to debug/apps/fast2d/src/main/java/fast2d/SketchLoadDisplaySVG.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import processing.core.PApplet;
44
import processing.core.PShape;
55

6-
public class SketchSVG extends PApplet {
6+
public class SketchLoadDisplaySVG extends PApplet {
77
PShape bot;
88

99
public void settings() {
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package fast2d;
2+
3+
import java.util.ArrayList;
4+
5+
import processing.core.PApplet;
6+
import processing.core.PVector;
7+
8+
public class SketchMousePoly extends PApplet {
9+
float weight = 1;
10+
11+
//data for demo 2
12+
int[] c = new int[4096];
13+
ArrayList<PVector> points = new ArrayList<PVector>();
14+
15+
public void settings() {
16+
fullScreen(P2DX);
17+
}
18+
19+
public void setup() {
20+
//setup for demo 2
21+
for (int i = 0; i < c.length; ++i) {
22+
c[i] = color(random(255), random(255), random(255));
23+
}
24+
}
25+
26+
public void draw() {
27+
background(255);
28+
29+
fill(255, 0, 63, 127);
30+
noStroke();
31+
32+
//NOTE: we draw each vertex with a random fill color to test how it behaves.
33+
//in P2D, the colors are interpolated across the triangles output by the GLU tessellator.
34+
//in JAVA2D, when endShape() is called, the currently active color is used for all vertices.
35+
//for now P4D follows the behavior of P2D, but switching to JAVA2D's behavior
36+
//would allow us to simplify our implementation a bit
37+
beginShape();
38+
for (int i = 0; i < points.size(); ++i) {
39+
fill(c[i]);
40+
vertex(points.get(i).x, points.get(i).y);
41+
}
42+
endShape();
43+
}
44+
45+
public void mousePressed() {
46+
points.add(new PVector(mouseX, mouseY));
47+
}
48+
49+
public void mouseDragged() {
50+
points.get(points.size() - 1).x = mouseX;
51+
points.get(points.size() - 1).y = mouseY;
52+
}
53+
}

0 commit comments

Comments
 (0)