I have jumped into Dynamo as I want to start learning to programme and get familiar with some of the tools out there for Architecture and design.
I draw these series of sketches normally by hand where you start off with a line and draw the next line following it almost as perfectly as you can, by the end of the drawing it undulates in a natural flow. I have started to try and programme this (correct use of the word?). Somewhat succesfully
The logic followed here is that I draw a spline with specific x integer values, then make the y values vary between 0-1 and create a spline from this. The next line then takes the previous y values and adds a random value between 0-1.
Are there any suggestions on how I can simplify and improve this so I can make the x a slider and the number of splines a slider also?
try node to code and enter the wonderfull world of designscript.
node to code works like this: select a couple of nodes and rightclick.
use node to code and the group of nodes changes into a codeblock in designscript that does the same thing. study the result and get your way around it
in the end you will learn to use it just like so in this thread
@T.Sullivan If you find yourself repeating too many nodes or steps, you most likely aren’t going about composing your workflow properly.
Below is a script that probably does what you set out to do. However, if you’ve only started exploring Dynamo, please treat it only as one possible approach, while you explore other alternate approaches.
def abc(a,b)
{
ab = [Imperative]
{
y = [][];
c = 0;
d = 0;
e = List.OfRepeatedItem(0,b);
while (c<a)
{
f = Math.RandomList(b);
while (d<b)
{
y[c][d] = f[d]+e[d];
e[d] = y[c][d];
d = d + 1;
}
c = c + 1;
d = 0;
}
return = y;
}
e = Point.ByCoordinates((0..5..#a),ab<1>);
f = NurbsCurve.ByControlPoints(e,3);
return f;
};
That’s awesome, I’ve tried to understand how it works, hopefully it’s ok!
Cheers,
Mark
# definition with 2 inputs
def abc(a,b)
{
# imperative function for looping (as opposed to data flow function)
ab = [Imperative]
{
# y is 2 variables (the first will be a random number, the second the list count (which is added sequentially), these are added to create random sequential y point values)
y = [][];
#c & d are integers
c = 0;
d = 0;
# repeat 0, b number of times
e = List.OfRepeatedItem(0,b);
#create a while loop which runs ‘a’ number of times
while (c<a)
{
#create ‘b’ number of random doubles between 0 to 1
f = Math.RandomList(b);
#create a while loop which runs ‘b’ number of times (it’s a sub loop, ie. it runs b**a times)
while (d<b)
{
#state y’s variables in terms of b
#c = f(random ‘b’) at number d
#d = e(repeated ‘b’) at number d
# add random ‘b’ and repeated ‘b’
y[c][d] = f[d]+e[d];
#update so that the next run adds the previous y position
e[d] = y[c][d];
#add 1 to d, so that eventually it equals b and stops the loop
d = d + 1;
}
#add 1 to c, so that eventually it equals a and stops the loop
c = c + 1;
#reset d to 0 so that it’s clear for the next run of sub list looping
d = 0;
}
return = y;
}
#create points with x coords up to 5 stepped by ‘a’ amount and y coords which use the ab function
#ab contains nested loops, <1> makes the whole nested list be iterated over by each main list value sequentially
e = Point.ByCoordinates((0..5..#a),ab<1>);
#create curve from points with degree 3
f = NurbsCurve.ByControlPoints(e,3);
return f;
};