Hi community! All new here and to SC
I come from applied physics and I’m used to using python for scientific programming.
I have this idea for using a numerical emulation of waves on a membrane as a kind of advanced LFO, and thought I would give SC a spin. I’m really confused. I’ve followed some tutorials but they all approach the language from a kind of “Lets make music” viewpoint. I would rather like to learn it from a “Lets make math” viewpoint so to speak. (Any tips on where to find this is much appreciated).
Anyway, I’m confused as to how the for loops and while loops (and do? New to me) seem to require functions within them, inside which only variables defined in these inner “loop”-functions can be used. Passing variables in and out of loops to be able to access them seems like a real hassle? While working with global variables required to have single letter names also seems like a wierd arbitrary work around.
In meta code written in a mashup of python and SC, the membrane part works like this:
endTime = 50;
n = 100; //gridsize
timeStep = 0.5;
roomStep = 1;
speed = 1;
xSum = 0;
ySum = 0;
t = 0;
currentGrid = Array2D.fromArray(n,n);
oldGrid = Array2D.fromArray(n,n);
newGrid = Array2D.fromArray(n,n);
while t < endTime:
– for i in range(0,n):
---- for j in range(0,n):
------ xSum = currentGrid[i + 1, j] - 2*currentGrid[i,j] + currentGrid[i - 1,j]
------ ySum = currentGrid[i,j + 1] - 2*currentGrid[i,j] + currentGrid[i,j - 1]
------ newGrid[i,j] = 2*currentGrid[i,j] - oldGrid[i,j] + (((speed**2)*(timeStep**2)*(xSum + ySum))/(roomStep**2))
– oldGrid = Array2D.copy(currentGrid)
– currentGrid = Array2D.copy(newGrid)
After this the values in currentGrid are to be used in loops that generate synths. But one problem at a time.
How do you properly construct nested for loops and similar in SC?