Submit
Browse
Anonymous
Login
RSS
SuperCollider Code
Fork Code: Galton Board Simulator
name
code content
( var win = Window(); var display = UserView().layout_(HLayout().margins_(30)); var availableNotes = [58, 60, 61, 63, 65, 66, 68, 70].midicps; var timesNotesWerePlayed = Array.fill(availableNotes.size, { 0 }); var timers = Array.fill(availableNotes.size, { 0 }); var myFavoriteColor = Color(1, 0.333, 0.333); var mySecondFavoriteColor = Color(1, 1, 1); var blinkTime = 0.25; var displayRatio = 0.1; var playedNote; availableNotes.size.do({ |note, index| var view = UserView(); var counterView = UserView().animate_(true).frameRate_(24); var numberView = UserView().animate_(true); var barSize = 0; counterView.drawFunc_({ |view| barSize = view.bounds.height * displayRatio * timesNotesWerePlayed[index]; Pen.fillColor_( Color( myFavoriteColor.red + (mySecondFavoriteColor.red - myFavoriteColor.red * timers[index]), myFavoriteColor.green + (mySecondFavoriteColor.green - myFavoriteColor.green * timers[index]), myFavoriteColor.blue + (mySecondFavoriteColor.blue - myFavoriteColor.blue * timers[index]), ) ); Pen.fillRect( Rect( 0, view.bounds.height - barSize, view.bounds.width, barSize ) ); if(timers[index] > 0) { timers[index] = timers[index] - (blinkTime.reciprocal / view.frameRate) } { timers[index] = 0 }; }); numberView.drawFunc = { |view| Pen.stringCenteredIn( timesNotesWerePlayed[index].asString, Rect( 0, 0, view.bounds.width, view.bounds.height ), Font.default.deepCopy.size_(view.bounds.height * 0.5), Color.white ) }; view.layout_( VLayout( [counterView, stretch: 6], [numberView, stretch: 1] ).margins_(3) ); display.layout.add(view); }); Pbind( \instrument, \default, \dur, 0.25, \amp, 0.5, \freq, Prand(availableNotes, inf), \foo, Pfunc({ |event| playedNote = availableNotes.indexOf(event.freq); timesNotesWerePlayed[playedNote] = timesNotesWerePlayed[playedNote] + 1; if((timesNotesWerePlayed[playedNote] * displayRatio) >= 1) { displayRatio = displayRatio / 2 }; timers[playedNote] = 1; 0 }) ).play; display.drawFunc_({ |view| Pen.fillColor_(myFavoriteColor); Pen.fillRect( Rect( 0, 0, view.bounds.width, view.bounds.height ) ); Pen.fillColor_(Color.black); Pen.fillRect( Rect( 5, 5, view.bounds.width - 10, view.bounds.height - 10 ) ); }); win.layout_( VLayout(display).margins_(0) ); win.front; CmdPeriod.doOnce({ win.close }); )
code description
https://scsynth.org/t/galton-board-sim/6202
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