Created
October 10, 2017 05:08
-
-
Save Derfies/5d286ba16b907a93c92d83f9b7c62edf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import nodebox.graphics as nbg | |
thisDirPath = os.path.dirname( os.path.abspath( __file__ ) ) | |
uberPath = os.path.join( thisDirPath, '..' ) | |
if uberPath not in sys.path: | |
sys.path.append( uberPath ) | |
from uberNode import UberNode | |
class Rectangle( object ): | |
def __init__( self, x, y, width, height ): | |
self.x = x | |
self.y = y | |
self.width = width | |
self.height = height | |
def draw( self, **kwargs ): | |
rect = nbg.rect( self.x, self.y, self.width, self.height, **kwargs ) | |
class Split( UberNode ): | |
def __init__( self, *args, **kwargs ): | |
UberNode.__init__( self, *args, **kwargs ) | |
self.addInput( 'in' ) | |
self.addOutput( 'out' ) | |
def evaluate( self, **inputs ): | |
inRect = inputs['in'] | |
return { | |
'out': Rectangle( 0, 0, inRect.width / 2, inRect.height ), | |
} | |
if __name__ == '__main__': | |
nbg.canvas.size = 500, 500 | |
rectDefs = [] | |
rect = Rectangle( 0, 0, 100, 100 ) | |
rectDefs.append( (rect, (1, 0, 0, 1)) ) | |
in_ = UberNode() | |
in_.addOutput( 'rect', rect ) | |
split = Split() | |
in_.connect( 'rect', split, 'in' ) | |
rectDefs.append( (split.getOutputValue( 'out' ), (0, 1, 0, 1)) ) | |
def draw( canvas ): | |
canvas.clear() | |
for rectDef in rectDefs: | |
rect, colour = rectDef | |
rect.draw( fill=colour ) | |
nbg.canvas.run( draw ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment