Skip to content

Commit 51acae9

Browse files
curlybraces.xml, set.xlm: add information on Python sets (vs Processing set())
closes jdf#66
1 parent c686c43 commit 51acae9

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

‎Reference/api_en/curlybraces.xml‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ element_names = {'H': 'hydrogen', 'He': 'helium', 'Li': 'lithium'}
1616
1717
# Curly braces with nothing inside creates an empty dictionary
1818
nothing_here = {}
19+
20+
# Curly braces with values-only create a new set
21+
element_set = {'H', 'He', 'Li'}
1922
]]></code>
2023
</example>
2124

@@ -24,21 +27,31 @@ Curly braces are used to define "dictionary literals," giving you the ability
2427
to declare a dictionary and its contents inside your program. A dictionary
2528
literal consists of a series of key/value pairs, written with a colon
2629
(<b>:</b>) between them, and with each of the key/value pairs separated from
27-
one other with commas.
30+
one other with commas. <br />
31+
<br />
32+
Curly braces are also used to define "sets," or a series of unique keys
33+
without values, separated by commas. This is not to be confused with using set() on a pixel.
2834
]]></description>
2935

3036
<syntax>
3137
dict = {<c>key0: val0, ..., keyN: valN</c>}
38+
set = {<c>key0, key1, ..., keyN</c>}
3239
</syntax>
3340

3441
<parameter>
3542
<label>key0: val0, ..., keyN: valN</label>
3643
<description><![CDATA[a sequence of key/value pairs]]></description>
3744
</parameter>
3845

46+
<parameter>
47+
<label>key0, key1, ..., keyN</label>
48+
<description><![CDATA[a sequence of unique keys]]></description>
49+
</parameter>
50+
3951
<returns></returns>
4052

4153
<related>indexbrackets</related>
54+
<related>set</related>
4255

4356
<availability>1.0</availability>
4457

‎Reference/api_en/set.xml‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,21 @@ Changes the color of any pixel, or writes an image directly to the display windo
4545
<br />
4646
The <b>x</b> and <b>y</b> parameters specify the pixel to change and the <b>c</b> parameter specifies the color value. The <b>c</b> parameter is interpreted according to the current color mode. (The default color mode is RGB values from 0 to 255.) When setting an image, the <b>x</b> and <b>y</b> parameters define the coordinates for the upper-left corner of the image, regardless of the current <b>imageMode()</b>.
4747
<br /><br />
48-
Setting the color of a single pixel with <b>set(x, y)</b> is easy, but not as fast as putting the data directly into <b>pixels</b>. The equivalent statement to <b>set(x, y, #000000)</b> using <b>pixels</b> is <b>pixels[y*width+x] = #000000</b>. See the reference for <a href="pixels.html">pixels</a> for more information.
48+
Setting the color of a single pixel with <b>set(x, y)</b> is easy, but not as
49+
fast as putting the data directly into <b>pixels</b>. The equivalent statement
50+
to <b>set(x, y, #000000)</b> using <b>pixels</b> is <b>pixels[y*width+x] =
51+
#000000</b>. See the reference for <a href="pixels.html">pixels</a> for more
52+
information.<br />
53+
<br />
54+
While set(r, g, b) changes pixel color, s = set([1, 1, 3]) is a Python function
55+
for converting a single list or tuple into int a set of unique keys: {1, 3}.
56+
Sets in this sense may also be created using curly braces: s = {1, 2, 3}.
4957
]]></description>
5058

5159
<syntax>
5260
set(<c>x</c>, <c>y</c>, <c>c</c>)
5361
set(<c>x</c>, <c>y</c>, <c>img</c>)
62+
s = set(<c>[key0, key1, ..., keyN]</c>)
5463
</syntax>
5564

5665
<parameter>
@@ -73,6 +82,12 @@ set(<c>x</c>, <c>y</c>, <c>img</c>)
7382
<description><![CDATA[PImage: image to copy into the original image]]></description>
7483
</parameter>
7584

85+
<parameter>
86+
<label>[key0, key1, ..., keyN]</label>
87+
<description><![CDATA[a sequence of unique keys]]></description>
88+
</parameter>
89+
7690
<related>pixels</related>
91+
<related>curlybraces</related>
7792

7893
</root>

0 commit comments

Comments
 (0)