after12am / eisenscript

A programming language designed for generating awesome structures.
https://after12am.github.io/eisenscript-docs/
MIT License
46 stars 5 forks source link

Live demo with squashed spheres and torus #47

Closed kronpano closed 4 years ago

kronpano commented 7 years ago

simple script: 6 * { ry 60 } r rule r md 22 { {x 2}sphere { ry 12 rx 12 rz 22 x 1 z -0.4 y -0.4 s 1.1 0.8 1.2} r } rule r md 22 { {z 2 s 0.5}torus { ry 22 rx 22 rz 12 x 1 z -0.4 y -0.4 s 0.8 0.8 1.1} r }

So you can squash spheres and use other primitives like torus and so on. Scripts so far work a bit different from the eisen script in Structure synth live demo here - zoom with mousewheel, rotate left click and shift right click.

https://playingwithstuff.000webhostapp.com/play2/

What I found here: if you use a construct like

6 * { ry 60 } r rule r md 5 > k { sphere {x 2}r } rule k md 4 { box {y 2}k }

it goes into r for a depth of 5 once and from then on executes k So again I think there is a problem in terms of breadth first and recursivity ?

Structure Synth: image

and Browser Synth: image

I guess it might not really be your aim to be exactly like Structure Synth. In that case just tell me and I will stop comparing the two.

kronpano commented 7 years ago

I think the way the script is interpreted is quite different from Structure Synth.

set maxobjects 10 3 * {rz 120}aaa rule aaa md 2 > bbb{ {x 1}box { x 1.8} aaa } rule bbb md 2 { sphere {z 1.5}bbb }

This simple example with follow rule and restricted objects shows that this version goes into rule aaa for one branch, then into bbb and then - something goes wrong. By increasing maxobjects from 1 to 10 you can see it grow in BrowserSynth with on arm with boxes, then the spheres and then only spheres. In Structure Synth you can not go with maxobjects below 7 because it will do all three arms immediately and once they are done it will add one sphere for all three and then the other one for all three.

In the case of follow rules this makes a big difference for the resulting structure.

From the Structure Synth web site

And recursion is handled ‘breadth first’. The last point requires an explanation: Whenever a procedural programming language executes a function or procedure, it does so in sequential order – the individual statements in the function are executed in the order of appearance. If one of the statements is a procedure call, this procedure is executed and must be completed before the next statement is executed. The state of the currently executing function (the return address pointer, local variables, …) are stored in stack frames on a call stack, in order to be able to return after executing a function. Put differently, this means the function call tree for the program is traversed ‘depth-first’. Recursion in Structure Synth is handled differently. Instead of a call stack, there is generational stack: whenever a rule is encountered, all sub rules and primitives in the rule definition are pushed onto a new stack that will be evaluated at the next generation. This means the rules are traversed ‘breadth first’ – all calls at the same recursive depth are processed at the same time. Consider the following example: Procedure recurse() { recurse(); // call myself another(); // call another function } A traditional programming language would never reach the ‘another()’ function. It would recurse until the call stack overflowed. In contrast, In Structure Synth the first generation would process both the ‘recurse’ and ‘another’ statement. (When processing the ‘recurse’ statement it would schedule new ‘recurse’ and ‘another’ calls for the next generation).

kronpano commented 7 years ago

I think the problem is in the same place as the fix yesterday - in interpreter.js at the end:

// if achieved maxdepth chosen.depth = (chosen.depth || 0) + 1; if (chosen.maxdepth && chosen.maxdepth < chosen.depth) { if (chosen.alternate) return this.sampling(chosen.alternate); if (this.depth < chosen.maxdepth) return chosen; return false; }

But so far I can't get my head around how the interpreter works. Needs some time I guess.

after12am commented 7 years ago

This is a bug related to #48 . But it was still not works well...

Here is the result in v1.1.8 now.

eisenscript

after12am commented 7 years ago

v1.1.9 is fixed version. see here. Please check it.

after12am commented 7 years ago

But so far I can't get my head around how the interpreter works. Needs some time I guess.

Sorry, it's late today. I have to sleep. I will reply later.