Skip to content

Instantly share code, notes, and snippets.

@Derfies
Created October 10, 2017 05:08
Show Gist options
  • Save Derfies/5d286ba16b907a93c92d83f9b7c62edf to your computer and use it in GitHub Desktop.
Save Derfies/5d286ba16b907a93c92d83f9b7c62edf to your computer and use it in GitHub Desktop.
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