@@ -62,6 +62,33 @@ tuples.
62
62
print(tuple(v.yx)) # (2.0, 1.0)
63
63
64
64
65
+ A vector can be converted to other data types using the built-in constructors
66
+
67
+ ::
68
+
69
+ v = pygame.Vector2(1, 2)
70
+
71
+ list(v) == [1.0, 2.0]
72
+ tuple(v) == (1.0, 2.0)
73
+ set(v) == {1.0, 2.0}
74
+
75
+ Conversion can be combined with swizzling or slicing to create a new order
76
+
77
+ ::
78
+
79
+ v = pygame.Vector3(1, 2, 3)
80
+
81
+ list(v.xz) == [1.0, 3.0]
82
+ list(v.zyx) == [3.0, 2.0, 1.0]
83
+ list(v.yyy) == [2.0, 2.0, 2.0]
84
+ tuple(v.xyyzzz) == (1.0, 2.0, 2.0, 3.0, 3.0, 3.0)
85
+ tuple(v.zxyxzzyx) == (3.0, 1.0, 2.0, 1.0, 3.0, 3.0, 2.0, 1.0)
86
+ set(v.yxzxzyzxyx) == {1.0, 2.0, 3.0} # sets remove duplicates
87
+
88
+ list(v[:]) == [1.0, 2.0, 3.0]
89
+ tuple(v[::-1]) == (3.0, 2.0, 1.0)
90
+ set(v[1:3]) == {2.0, 3.0}
91
+
65
92
.. versionaddedold :: 1.9.2pre
66
93
.. versionchangedold :: 1.9.4 Removed experimental notice.
67
94
.. versionchangedold :: 1.9.4 Allow scalar construction like GLSL Vector2(2) == Vector2(2.0, 2.0)
0 commit comments