Varying a stroke width of a curve in JavaFX -
is there way create curve in javafx varying stroke width? example, starting @ 10 point , end @ 1 point.
you can't vary stroke width.
you can simulate behavior though, creating path layers multiple curves, start @ different starting positions converge single point.
import javafx.application.application; import javafx.scene.group; import javafx.scene.scene; import javafx.scene.paint.color; import javafx.scene.shape.*; import javafx.stage.stage; import java.util.random; public class dividedpath extends application { private static final double width = 400, height = 400; private static final random random = new random(42); @override public void start(stage stage) { cubiccurve curve = randomcurve(width, height); path path = new path(); (int = -5; <= +5; i++) { path.getelements().addall( new moveto(curve.getstartx() + i, curve.getstarty()), new cubiccurveto( curve.getcontrolx1(), curve.getcontroly1(), curve.getcontrolx2(), curve.getcontroly2(), curve.getendx(), curve.getendy() ) ); } path.setstroke(color.forestgreen); group root = new group(); curve.setfill(null); root.getchildren().addall( path, curve ); scene scene = new scene( root, width, height, color.rgb(35,39,50) ); stage.setscene(scene); stage.setresizable(false); stage.show(); } private cubiccurve randomcurve(double mx, double my) { return new cubiccurve( random.nextdouble() * mx, random.nextdouble() * my, random.nextdouble() * mx, random.nextdouble() * my, random.nextdouble() * mx, random.nextdouble() * my, random.nextdouble() * mx, random.nextdouble() * ); } }
Comments
Post a Comment