Submit
Browse
Anonymous
Login
RSS
SuperCollider Code
Fork Code: Chopsticks GUI
name
code content
( var numX=12, numY=8, width, height, margin; w = Window.new("CompositeView", Window.availableBounds).front; width = (Window.availableBounds.width/numX).floor; height = (Window.availableBounds.height/numY).floor; margin = (width + height)/20; w.addFlowLayout(0@0, 0@0); t = Array.fill(numX * numY, { arg i; var u, n, col, moveTo, lineTo, toggle; col = Color.rand; toggle = i%2; n = CompositeView.new(w, Rect(0, 0, width, height)) .background_(col); u=UserView(n, Rect(margin, margin, width-(margin*2), height-(margin*2))); // OK u.background_(col); u.drawFunc={|uview| if(toggle.asBoolean, { moveTo = 0@uview.bounds.height.rand; lineTo = uview.bounds.width@uview.bounds.height.rand; }, { moveTo = uview.bounds.width.rand@uview.bounds.height; lineTo = uview.bounds.width.rand@0; }); Pen.moveTo(moveTo); Pen.lineTo(lineTo); Pen.stroke; }; u.mouseDownAction={|view| col = Color.rand; u.background_(col); n.background_(col); toggle = (toggle - 1).abs; }; u.animate_(true); }); w.front; )
code description
A GUI example of nesting Views and multiplying widgets, including mouse actions and Pen drawing for each of the views. Thanks to hjh for spotting an early bug on sc-users. Add your own sound...
use markdown for formating
category tags
comma separated, i.g. "wild, siren" (do not enter default SC class names, please)
ancestor(s)
comma separated identificators, i.g. "1-C,1-1,1-4M,1-x"
Private?
the code will be accessible by direct url and not visible in public activity
signup to submit public code without captcha
comment of change