Skip to content

Commit dc52d1b

Browse files
committed
Add shape drawing test cases
1 parent 39aab83 commit dc52d1b

File tree

49 files changed

+244
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+244
-0
lines changed

test/unit/visual/cases/shapes.js

+172
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
import { visualSuite, visualTest } from '../visualTest';
2+
3+
visualSuite('Shape drawing', function() {
4+
for (const mode of ['2D', 'WebGL']) {
5+
visualSuite(`${mode} mode`, function() {
6+
const setup = (p5) => {
7+
p5.createCanvas(50, 50, mode === '2D' ? p5.P2D : p5.WEBGL);
8+
if (mode !== '2D') {
9+
p5.translate(-p5.width / 2, -p5.height / 2);
10+
}
11+
p5.background(200);
12+
p5.fill(255);
13+
p5.stroke(0);
14+
}
15+
16+
visualTest('Drawing polylines', function(p5, screenshot) {
17+
setup(p5);
18+
p5.beginShape();
19+
p5.vertex(10, 10);
20+
p5.vertex(15, 40);
21+
p5.vertex(40, 35);
22+
p5.vertex(25, 15);
23+
p5.vertex(15, 25);
24+
p5.endShape();
25+
screenshot();
26+
});
27+
28+
visualTest('Drawing with contours', function(p5, screenshot) {
29+
setup(p5);
30+
31+
const vertexCircle = (x, y, r, direction) => {
32+
for (let i = 0; i <= 12; i++) {
33+
const angle = p5.map(i, 0, 12, 0, p5.TWO_PI) * direction;
34+
p5.vertex(x + r * p5.cos(angle), y + r * p5.sin(angle));
35+
}
36+
}
37+
38+
p5.beginShape();
39+
vertexCircle(15, 15, 10, 1);
40+
41+
// Inner cutout
42+
p5.beginContour();
43+
vertexCircle(15, 15, 5, -1);
44+
p5.endContour();
45+
46+
// Outer shape
47+
p5.beginContour();
48+
vertexCircle(30, 30, 8, -1);
49+
p5.endContour();
50+
p5.endShape();
51+
52+
screenshot();
53+
});
54+
55+
visualTest('Drawing triangle fans', function(p5, screenshot) {
56+
setup(p5);
57+
p5.beginShape(p5.TRIANGLE_FAN);
58+
p5.vertex(25, 25);
59+
for (let i = 0; i <= 12; i++) {
60+
const angle = p5.map(i, 0, 12, 0, p5.TWO_PI);
61+
p5.vertex(25 + 10*p5.cos(angle), 25 + 10*p5.sin(angle));
62+
}
63+
p5.endShape();
64+
screenshot();
65+
});
66+
67+
visualTest('Drawing triangle strips', function(p5, screenshot) {
68+
setup(p5);
69+
p5.beginShape(p5.TRIANGLE_STRIP);
70+
p5.vertex(10, 10);
71+
p5.vertex(30, 10);
72+
p5.vertex(15, 20);
73+
p5.vertex(35, 20);
74+
p5.vertex(10, 40);
75+
p5.vertex(30, 40);
76+
p5.endShape();
77+
screenshot();
78+
});
79+
80+
visualTest('Drawing quad strips', function(p5, screenshot) {
81+
setup(p5);
82+
p5.beginShape(p5.QUAD_STRIP);
83+
p5.vertex(10, 10);
84+
p5.vertex(30, 10);
85+
p5.vertex(15, 20);
86+
p5.vertex(35, 20);
87+
p5.vertex(10, 40);
88+
p5.vertex(30, 40);
89+
p5.endShape();
90+
screenshot();
91+
});
92+
93+
visualTest('Drawing closed polylines', function(p5, screenshot) {
94+
setup(p5);
95+
p5.beginShape();
96+
p5.vertex(10, 10);
97+
p5.vertex(15, 40);
98+
p5.vertex(40, 35);
99+
p5.vertex(25, 15);
100+
p5.vertex(15, 25);
101+
p5.endShape(p5.CLOSE);
102+
screenshot();
103+
});
104+
105+
visualTest('Drawing with curves', function(p5, screenshot) {
106+
setup(p5);
107+
p5.beginShape();
108+
p5.curveVertex(10, 10);
109+
p5.curveVertex(10, 10);
110+
p5.curveVertex(15, 40);
111+
p5.curveVertex(40, 35);
112+
p5.curveVertex(25, 15);
113+
p5.curveVertex(15, 25);
114+
p5.curveVertex(15, 25);
115+
p5.endShape();
116+
screenshot();
117+
});
118+
119+
visualTest('Drawing with curves with tightness', function(p5, screenshot) {
120+
setup(p5);
121+
p5.curveTightness(0.5);
122+
p5.beginShape();
123+
p5.curveVertex(10, 10);
124+
p5.curveVertex(10, 10);
125+
p5.curveVertex(15, 40);
126+
p5.curveVertex(40, 35);
127+
p5.curveVertex(25, 15);
128+
p5.curveVertex(15, 25);
129+
p5.curveVertex(15, 25);
130+
p5.endShape();
131+
screenshot();
132+
});
133+
134+
visualTest('Drawing closed curve loops', function(p5, screenshot) {
135+
setup(p5);
136+
p5.beginShape();
137+
p5.curveVertex(10, 10);
138+
p5.curveVertex(15, 40);
139+
p5.curveVertex(40, 35);
140+
p5.curveVertex(25, 15);
141+
p5.curveVertex(15, 25);
142+
// Repeat first 3 points
143+
p5.curveVertex(10, 10);
144+
p5.curveVertex(15, 40);
145+
p5.curveVertex(40, 35);
146+
p5.endShape();
147+
screenshot();
148+
});
149+
150+
visualTest('Drawing with cubic beziers', function(p5, screenshot) {
151+
setup(p5);
152+
p5.beginShape();
153+
p5.vertex(10, 10);
154+
p5.bezierVertex(10, 10, 15, 40, 40, 35);
155+
p5.bezierVertex(25, 15, 15, 25, 15, 25);
156+
p5.endShape();
157+
screenshot();
158+
});
159+
160+
visualTest('Drawing with quadratic beziers', function(p5, screenshot) {
161+
setup(p5);
162+
p5.beginShape();
163+
p5.vertex(10, 10);
164+
p5.quadraticVertex(10, 10, 15, 40);
165+
p5.quadraticVertex(40, 35, 25, 15);
166+
p5.quadraticVertex(15, 25, 10, 10);
167+
p5.endShape();
168+
screenshot();
169+
});
170+
});
171+
}
172+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}

0 commit comments

Comments
 (0)