Sunday, January 22, 2017

Jython 6. Ellipse

This Example, Circle, will produce the same output as Java Example 6.


# ex06.py
# Ellipse

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 Ellipse

class Pos:
    pass

pos = Pos()
pos.cen = [200,200] # center x,y
pos.rad = [100,150] # radius x,y
pos.val = pos.cen + pos.rad

class Ex06(Application):
    def start(self, stage):
        stage.setTitle("Example 6. Ellipse")
        root = Group()
        
        elli = Ellipse(*pos.val)
        elli.setFill(Color.RED)
        root.getChildren().add(elli)
        
        scene = Scene(root, 400, 400, Color.AQUA)
        stage.setScene(scene)
        stage.show()

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

An empty class is created. We create an instance pos and then set its values. It is also possible to, for example, use variables like cen, rad, and val, in the global namespace. However this organizes things since they are related, and the only reason we are using them is to create a new namespace.


No comments:

Post a Comment