Submit
Browse
Anonymous
Login
RSS
SuperCollider Code
Fork Code: spinning doughnut
name
code content
//req. Canvas3D quark: Quarks.install("Canvas3D"); //works with both cocoa and qt GUI //see thread https://www.listarc.bham.ac.uk/lists/sc-users/msg06458.html for more examples //cmd+period to stop ( var width = 500, height = 400; var w, u; var segments= 40; var minorRadius= 0.667; var majorRadius= 1; w = Window("spinning doughnut", Rect(128, 64, width, height), false) .front; u = Canvas3D(w, Rect(0, 0, width, height)); u.add(Canvas3DItem() .paths_( Array.fill(segments+1, {|i| var u= i/segments*2pi; Array.fill(segments+1, {|j| var v= j/segments*2pi; var x= (minorRadius*cos(v)+majorRadius)*cos(u); var y= (minorRadius*cos(v)+majorRadius)*sin(u); var z= minorRadius*sin(v); [x, y, z]; }); }) ) ); u.animate(40, {|t| u.transforms = [ Canvas3D.mRotateY(t/52%2pi*sin(t/30)), Canvas3D.mRotateX(t/50%2pi), Canvas3D.mScale(1, 1, sin(t/32)*2) ]; }); CmdPeriod.doOnce({w.close}); ) //and with trails ( var width = 500, height = 400; var w, u; var segments= 40; var minorRadius= 2; var majorRadius= 1; w = Window("spinning doughnut tails", Rect(128, 64, width, height), false) .front; u = Canvas3D(w, Rect(0, 0, width, height)); u.view.clearOnRefresh= false; u.add(Canvas3DItem() .paths_( Array.fill(segments+1, {|i| var u= i/segments*2pi; Array.fill(segments+1, {|j| var v= j/segments*2pi; var x= (minorRadius*cos(v)+majorRadius)*cos(u); var y= (minorRadius*cos(v)+majorRadius)*sin(u); var z= minorRadius*sin(v); [x, y, z]; }); }) ) ); u.view.drawFunc= { Pen.fillColor= Color.grey(1, 0.1); //alpha set trail amount Pen.fillRect(Rect(0, 0, width, height)); }<>u.view.drawFunc; u.animate(40, {|t| u.transforms = [ Canvas3D.mRotateY(t/22), Canvas3D.mRotateX(t/25*sin(t/23)), Canvas3D.mScale(1, 1, sin(t/24)) ]; }); CmdPeriod.doOnce({w.close}); ) //and with sound input from mic ( var width = 500, height = 400; var w, u, amp= 0.1; var segments= 25; var minorRadius= 0.5; var majorRadius= 1.5; w = Window("spinning wireframe doughnut", Rect(128, 64, width, height), false) .front; u = Canvas3D(w, Rect(0, 0, width, height)); u.add(Canvas3DItem() .paths_( Array.fill(segments+1, {|i| var u= i/segments*2pi; Array.fill(segments+1, {|j| var v= j/segments*2pi; var x= (minorRadius*cos(v)+majorRadius)*cos(u); var y= (minorRadius*cos(v)+majorRadius)*sin(u); var z= minorRadius*sin(v); [x, y, z]; }); }) ++ Array.fill(segments+1, {|i| var u= i/segments*2pi; Array.fill(segments+1, {|j| var v= j/segments*2pi; var x= (minorRadius*cos(u)+majorRadius)*cos(v); var y= (minorRadius*cos(u)+majorRadius)*sin(v); var z= minorRadius*sin(u); [x, y, z]; }); }) ) ); u.animate(60, {|t| u.transforms = [ Canvas3D.mRotateY(sin(t/42)*sin(t/53)), Canvas3D.mRotateX(sin(t/31)*sin(t/64)), Canvas3D.mRotateX(sin(t/20)*sin(t/75)), Canvas3D.mScale(amp, amp, sin(t/9)*sin(t/86)) ]; }); //--sound input s.waitForBoot{ OSCFunc({|m| amp= m[3].explin(0.01, 1, 0.667, 1)}, \tr, s.addr); {SendTrig.kr(Impulse.kr(60), 0, Amplitude.kr(SoundIn.ar, 0.1, 0.4)); DC.ar(0)}.play; }; CmdPeriod.doOnce({w.close}); )
code description
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