Thursday, January 26, 2017

Jython 10. Polyline

This Example, Polyline, will produce the same output as Java Example 10. A list of vertices is held in vertData. We pass the list to the Polyline() function.


# ex10.py
# Polyline

from javafx.application import Application
from javafx.scene import Scene
from javafx.scene import Group
from javafx.scene.paint import Color
from javafx.scene.shape import Polyline

class Ex10(Application):
    def start(self, stage):
        stage.setTitle("Example 10. Polyline")
        root = Group()
        
        x,y,w = 200,200,100
        
        vertData = []
        vertData.extend([x-2*w, y-w])
        vertData.extend([x-w, y+w])
        vertData.extend([x, y-w])
        vertData.extend([x+w, y+w])
        vertData.extend([x+2*w, y-w])
        vertData.extend([x, 0])
        vertData.extend([x-2*w, y-w])
        
        polyline = Polyline(vertData)
        polyline.setFill(Color.rgb(1, 225, 80))
                
        root.getChildren().addAll(polyline);
        
        scene = Scene(root, 400, 400, Color.PALEGREEN)
        stage.setScene(scene)
        stage.show()

if __name__ == '__main__':
    Application.launch(Ex10().class, [])

No comments:

Post a Comment