PbeginShape
processing
Using the PbeginShape
and PendShape
functions allow creating more complex forms. PbeginShape
begins recording vertices for a shape and PendShape
stops recording.
The value of the kind parameter tells it which types of shapes to create from the provided vertices. The parameters available for beginShape() are POLYGON, POINTS, LINES, TRIANGLES, TRIANGLE_FAN, TRIANGLE_STRIP, QUADS, and QUAD_STRIP. After calling the PbeginShape
function, a series of Pvertex
commands must follow. To stop drawing the shape, call PendShape
. The Pvertex
function with two parameters specifies a position in 2D. Each shape will be outlined with the current stroke color and filled with the fill color.
Transformations such as Ptranslate
, Protate
, and Pscale
do not work within PbeginShape
. It is also not possible to use other shapes, such as Pellipse
or Prect
within PbeginShape
.
The P2D and P3D renderers allow Pstroke
and Pfill
to be altered on a per-vertex group basis. Settings such as PstrokeWeight
, PstrokeCap
, and PstrokeJoin
cannot be changed while inside a PbeginShape
/PendShape
block with any renderer.
Up to Warp 10 1.2.18, PbeginShape
could be called without the kind parameter. It defaults to POLYGON.
Link to original Processing doc
PbeginShape is available since version 1.0.0.
See also
Signatures
Examples
// @preview image
100 400 '2D' PGraphics //new image instance
0 'y' STORE
0xffffffff Pbackground //white background
0xff0000ff Pstroke //blue stroke (ARGB color)
10 PtextSize
0xffff0000 Pfill //red fill
3 PstrokeWeight
'CENTER' PtextAlign
'POLYGON CLOSE' 50 $y 10 + Ptext
'POLYGON' PbeginShape
30 $y 20 + Pvertex
85 $y 20 + Pvertex
85 $y 75 + Pvertex
30 $y 75 + Pvertex
'CLOSE' PendShape
$y 100 + 'y' STORE
'POLYGON OPEN' 50 $y 10 + Ptext
'POLYGON' PbeginShape
30 $y 20 + Pvertex
85 $y 20 + Pvertex
85 $y 75 + Pvertex
30 $y 75 + Pvertex
'OPEN' PendShape
$y 100 + 'y' STORE
'POINTS' 50 $y 10 + Ptext
'POINTS' PbeginShape
30 $y 20 + Pvertex
85 $y 20 + Pvertex
85 $y 75 + Pvertex
//0xff00ffff Pstroke //will make next point cyan
30 $y 75 + Pvertex
'OPEN' PendShape
$y 100 + 'y' STORE
'LINES' 50 $y 10 + Ptext
'LINES' PbeginShape
30 $y 20 + Pvertex
85 $y 20 + Pvertex
85 $y 75 + Pvertex
30 $y 75 + Pvertex
'OPEN' PendShape
Pencode
// @preview image
100 400 '2D' PGraphics //new image instance
0 'y' STORE
0xffffffff Pbackground //white background
0xff0000ff Pstroke //blue stroke (ARGB color)
10 PtextSize
0x7fff0000 Pfill //half transparent red fill
1 PstrokeWeight
'CENTER' PtextAlign
'TRIANGLES CLOSE' 50 $y 10 + Ptext
'TRIANGLES' PbeginShape
30 $y 75 + Pvertex
40 $y 20 + Pvertex
50 $y 75 + Pvertex
60 $y 20 + Pvertex
70 $y 75 + Pvertex
80 $y 20 + Pvertex
'CLOSE' PendShape //OPEN does the same thing
$y 100 + 'y' STORE
'TRIANGLE_STRIP' 50 $y 10 + Ptext
'TRIANGLE_STRIP' PbeginShape
30 $y 75 + Pvertex
40 $y 20 + Pvertex
50 $y 75 + Pvertex
60 $y 20 + Pvertex
70 $y 75 + Pvertex
80 $y 20 + Pvertex
'CLOSE' PendShape //OPEN does the same thing
$y 100 + 'y' STORE
'TRIANGLE_FAN' 50 $y 10 + Ptext
'TRIANGLE_FAN' PbeginShape
30 $y 75 + Pvertex
40 $y 20 + Pvertex
50 $y 75 + Pvertex
60 $y 20 + Pvertex
70 $y 75 + Pvertex
80 $y 20 + Pvertex
'CLOSE' PendShape //OPEN does the same thing
Pencode
// @preview image
100 400 '2D' PGraphics //new image instance
0 'y' STORE
0xffffffff Pbackground //white background
0xff0000ff Pstroke //blue stroke (ARGB color)
10 PtextSize
0x7fff0000 Pfill //half transparent red fill
1 PstrokeWeight
'CENTER' PtextAlign
'QUADS' 50 $y 10 + Ptext
'QUADS' PbeginShape
30 $y 20 + Pvertex
30 $y 75 + Pvertex
50 $y 75 + Pvertex
50 $y 20 + Pvertex
65 $y 20 + Pvertex
65 $y 75 + Pvertex
85 $y 75 + Pvertex
85 $y 20 + Pvertex
'OPEN' PendShape //always CLOSE, in quads mode.
$y 100 + 'y' STORE
'QUAD_STRIP' 50 $y 10 + Ptext
'QUAD_STRIP' PbeginShape
30 $y 20 + Pvertex
30 $y 75 + Pvertex
50 $y 75 + Pvertex
50 $y 20 + Pvertex
65 $y 20 + Pvertex
65 $y 75 + Pvertex
85 $y 75 + Pvertex
85 $y 20 + Pvertex
'OPEN' PendShape //always CLOSE, in quads mode.
$y 100 + 'y' STORE
Pencode