Difference between revisions of "Path2D:setPath"

From GiderosMobile
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
+
'''Available since:''' Gideros 2016.04<br/>
'''<translate>Available since</translate>:''' Gideros 2016.04<br/>
+
'''Class:''' [[Path2D]]<br/>
'''<translate>Class</translate>:''' [[Special:MyLanguage/Path2D|Path2D]]<br/>
 
=== <translate>Description</translate> ===
 
<translate>Set path to draw, using string with commands represented as:
 
<ul>
 
<li>M - MoveTo, 2 values (x,y)</li>
 
<li>L - LineTo, 2 values (x,y)</li>
 
<li>Q - QuadTo, 4 values (c0x,c0y,x,y)</li>
 
<li>C - CubicTo, 6 values (c0x,c0y,c1x,c1y,x,y)</li>
 
<li>H - Horzontal Line, 1 value (x)</li>
 
<li>V - Vertical Line, 1 value (y)</li>
 
<li>A - ArcTo, 7 values (r1,r2,angle,largeArc,sweep,x,y)</li>
 
<li>Z - Close, no parameter</li>
 
<li>* - repeat last command until all coordinates are exhausted</li>
 
</ul>
 
and provided coordinates as table or simply arguments</translate>
 
<source lang="lua">
 
Path2D:setPath(commands,coordinates,moreCoordinates)
 
</source>
 
  
=== <translate>Parameters</translate> ===
+
=== Description ===
'''commands''': (string) <translate>list of commands as ML**Z expecting according coordinates</translate> <br/>
+
Sets path to draw, using string with commands represented as:
'''coordinates''': (table or number) <translate>lua table with coordinates for each command, in the same order as commands</translate> <br/>
+
*M - MoveTo, 2 values (x,y)
'''moreCoordinates''': (number) <translate>if second argument is not table, you can provide more coordinates as separate arguments</translate> '''optional'''<br/>
+
*L - LineTo, 2 values (x,y)
 +
*Q - QuadTo, 4 values (c0x,c0y,x,y)
 +
*C - CubicTo, 6 values (c0x,c0y,c1x,c1y,x,y)
 +
*H - Horzontal Line, 1 value (x)
 +
*V - Vertical Line, 1 value (y)
 +
*A - ArcTo, 7 values (r1,r2,angle,largeArc,sweep,x,y)
 +
*Z - Close, no parameter
 +
*'''*''' - repeats last command until all coordinates are exhausted
 +
and provided coordinates as table or simply arguments.
 +
<syntaxhighlight lang="lua">
 +
Path2D:setPath(commands,coordinates,moreCoordinates)
 +
</syntaxhighlight>
  
=== <translate>Examples</translate> ===
+
=== Parameters ===
 +
'''commands''': (string) list of commands as ML**Z expecting according coordinates<br/>
 +
'''coordinates''': (table or number) lua table with coordinates for each command, in the same order as commands<br/>
 +
'''moreCoordinates''': (number) if second argument is not table, you can provide more coordinates as separate arguments '''optional'''<br/>
 +
 
 +
=== Example ===
 
'''Drawing Moon'''<br/>
 
'''Drawing Moon'''<br/>
<source lang="lua">--Moon
+
<syntaxhighlight lang="lua">
 +
--Moon
 
local p=Path2D.new()
 
local p=Path2D.new()
 
local ms="MQQZ" --MoveTo, QuadTo, QuadTo, Close
 
local ms="MQQZ" --MoveTo, QuadTo, QuadTo, Close
Line 37: Line 36:
 
p:setLineColor(0xC0C0C0) --Line color
 
p:setLineColor(0xC0C0C0) --Line color
 
p:setAnchorPosition(100,100)
 
p:setAnchorPosition(100,100)
stage:addChild(p)</source>
+
stage:addChild(p)
 +
</syntaxhighlight>
  
 
{{Path2D}}
 
{{Path2D}}

Latest revision as of 14:32, 13 July 2023

Available since: Gideros 2016.04
Class: Path2D

Description

Sets path to draw, using string with commands represented as:

  • M - MoveTo, 2 values (x,y)
  • L - LineTo, 2 values (x,y)
  • Q - QuadTo, 4 values (c0x,c0y,x,y)
  • C - CubicTo, 6 values (c0x,c0y,c1x,c1y,x,y)
  • H - Horzontal Line, 1 value (x)
  • V - Vertical Line, 1 value (y)
  • A - ArcTo, 7 values (r1,r2,angle,largeArc,sweep,x,y)
  • Z - Close, no parameter
  • * - repeats last command until all coordinates are exhausted

and provided coordinates as table or simply arguments.

Path2D:setPath(commands,coordinates,moreCoordinates)

Parameters

commands: (string) list of commands as ML**Z expecting according coordinates
coordinates: (table or number) lua table with coordinates for each command, in the same order as commands
moreCoordinates: (number) if second argument is not table, you can provide more coordinates as separate arguments optional

Example

Drawing Moon

--Moon
local p=Path2D.new()
local ms="MQQZ" --MoveTo, QuadTo, QuadTo, Close
local mp={100,0, -50,100, 100,200, 20,100, 100,0 }
p:setPath(ms,mp) --Set the path from a set of commands and coordinates
p:setLineThickness(3) -- Outline width
p:setFillColor(0xE0E0E0,0.7) --Fill color
p:setLineColor(0xC0C0C0) --Line color
p:setAnchorPosition(100,100)
stage:addChild(p)