different color in path

Richard Bair richard.bair at oracle.com
Fri Jul 12 22:34:36 PDT 2013


Usually questions of this kind are better answered on https://forums.oracle.com/community/developer/english/java/javafx/javafx_2.0_and_later (which I see just go a face-lift, looks great!).

What you should do depends on what you need. Have you looked into the Canvas node? I agree trying to do this with a bazillion Path objects is not going to work.

Richard

On Jul 13, 2013, at 12:08 PM, fajar <si.siput.ngantuk at gmail.com> wrote:

> Pada 7/12/2013 10:56 AM, Richard Bair menulis:
>> No, it is not possible. Each path is a single shape, and all shapes have a single fill / stroke / etc. You will need to use several paths and position them accordingly.
>> 
>> Thanks
>> Richard
>> 
>> On Jul 13, 2013, at 12:38 AM, fajar <si.siput.ngantuk at gmail.com> wrote:
>> 
>>> Is possible to setting different color for individually element in path? for example:
>>> 
>>> package test;
>>> 
>>> import javafx.application.Application;
>>> import javafx.scene.Scene;
>>> import javafx.scene.layout.StackPane;
>>> import javafx.scene.paint.Color;
>>> import javafx.scene.shape.ArcTo;
>>> import javafx.scene.shape.MoveTo;
>>> import javafx.scene.shape.Path;
>>> import javafx.stage.Stage;
>>> 
>>> public class TestPath extends Application{
>>> 
>>>    @Override
>>>    public void start(Stage primaryStage) throws Exception {
>>>        // TODO Auto-generated method stub
>>>        Path path = new Path();
>>> 
>>>        MoveTo moveTo = new MoveTo();
>>>        moveTo.setX(0.0);
>>>        moveTo.setY(0.0);
>>> 
>>>        path.setStroke(Color.RED);
>>>        ArcTo arcTo = new ArcTo();
>>>        arcTo.setX(50.0);
>>>        arcTo.setY(50.0);
>>>        arcTo.setRadiusX(50.0);
>>>        arcTo.setRadiusY(50.0);
>>>        path.setStroke(Color.AQUA);
>>> 
>>>        path.getElements().add(moveTo);
>>>        path.getElements().add(arcTo);
>>> 
>>>        StackPane pane = new StackPane();
>>> 
>>>        pane.getChildren().add(path);
>>>        pane.setPrefSize(500, 500);
>>>        primaryStage.setScene(new Scene(pane));
>>>        primaryStage.show();
>>>    }
>>> 
>>>    public static void main(String[] args){
>>>        launch(args);
>>>    }
>>> }
>>> 
>>> Is there any possible way to do this?
>>> When above code was running, it was make entire path color changed, not particular element on it.
>>> 
> i mean, i need to create something like this picture using javaFX
> 
> my sample code like below:
> 
>    public Group getEsembel() {
>        Group root = new Group();
>        Image image = new Image(main);
>        double width = image.getWidth();
>        double height = image.getHeight();
> 
>        PixelReader pixel = image.getPixelReader();
> 
>        double originX = 0.0;
>        double destinyX = 0.0;
>        double originY = 0.0;
>        double destinyY = 0.0;
> 
>        for (int y = 0; y < height; y += step) {
>            Group elementLine = new Group();
>            elementLine.setTranslateY(y);
>            for (int x = 0; x < width; x += step) {
>                Color color = pixel.getColor(x, y);
>                double brightness = color.getBrightness();
>                destinyX = step;
>                destinyY = -brightness * depth + depth / 2;
> 
>                MoveTo moveto = new MoveTo(originX, originY);
>                LineTo lineto = new LineTo(destinyX, destinyY);
>                elementLine.getChildren().add(
>                        PathBuilder.create().elements(moveto, lineto).build());
>                elementLine.setRotationAxis(Rotate.X_AXIS);
>                elementLine.setRotate(90);
>                originX = destinyX;
>                originY = destinyY;
>            }
>            root.getChildren().add(elementLine);
>        }
>        return root;
>    }
> 
> This code  not yet working as expected...
> but i can figure out if  I use that way (use Path to render different pixel segment) , thats very memory consuming
> i mean is there any elegant way to do this using javaFX
> by the way... above picture was created using Three.js
> Thanks.
> <unduhan.png>



More information about the openjfx-dev mailing list