How to fill a custom PPath with à color?

30 views
Skip to first unread message

Olivier Francillon

unread,
Aug 14, 2014, 4:46:33 AM8/14/14
to piccolo...@googlegroups.com
Hi everyone!

I'm trying to fill a custom shape with a color.
My shape is created from multiple lines (see the code)
PPath chair = PPath.createLine(0, 0, 1, 8);

chair.setPaint(Color.GREEN);
chair.moveTo(1, 8);
chair.lineTo(7, 8);
chair.moveTo(7,8);
chair.lineTo(8,0);
chair.moveTo(8, 0);
chair.lineTo(0,0);
chair.moveTo(0, 0);
BasicStroke stroke = new BasicStroke(2);
chair.setStroke(stroke);
chair.setStrokePaint(Color.WHITE);
this.addChild(rect);
this.addChild(chair);
return chair;

But, it won't work... 
How can I do ti fill this shape?



Michael Heuer

unread,
Aug 14, 2014, 11:47:08 AM8/14/14
to piccolo...@googlegroups.com
Hello Olivier,

I'm not sure why exactly but if you remove the moveTo lines and add
closePath() it works for me

PPath path = PPath.createLine(0, 0, 1, 8);
path.setPaint(Color.GREEN);
path.lineTo(7, 8);
path.lineTo(8, 0);
path.lineTo(0, 0);
path.closePath();

BasicStroke stroke = new BasicStroke(2);
path.setStroke(stroke);
path.setStrokePaint(Color.WHITE);

michael
> --
> You received this message because you are subscribed to the Google Groups
> "Piccolo2D Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to piccolo2d-use...@googlegroups.com.
> To post to this group, send email to piccolo...@googlegroups.com.
> Visit this group at http://groups.google.com/group/piccolo2d-users.
> For more options, visit https://groups.google.com/d/optout.

Olivier Francillon

unread,
Aug 14, 2014, 12:34:26 PM8/14/14
to piccolo...@googlegroups.com
Yes!
It works!!
Thank you very much Michael! 
So, when you use lineTo, the new position of next line is on the end of the created line... Move to break the "polyline".
Is that true?

Michael Heuer

unread,
Aug 14, 2014, 12:39:58 PM8/14/14
to piccolo...@googlegroups.com
I believe so.

For further clarification take a look at the Path2D javadocs

http://docs.oracle.com/javase/7/docs/api/java/awt/geom/Path2D.Double.html#lineTo(double,%20double)
http://docs.oracle.com/javase/7/docs/api/java/awt/geom/Path2D.Double.html#moveTo(double,%20double)

PPath just delegates to these.

michael


On Thu, Aug 14, 2014 at 11:34 AM, Olivier Francillon
Reply all
Reply to author
Forward
0 new messages