Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #21856

L-system construction of Lévy C curves (was: Injecting some activity through "questions" (DSLs))

Message-ID <3347742.XQ3BYjxHdU@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2013-11-02 21:31 +0100
Subject L-system construction of Lévy C curves (was: Injecting some activity through "questions" (DSLs))
Newsgroups comp.lang.javascript
References <2a650b44-7c6b-4478-810d-9b091bb78559@googlegroups.com>

Show all headers | View raw


Michael Haufe (TNO) wrote:

> Since there have been complaints about lack of questions and activity in
> the group, I've decided to ask a question once in awhile to hopefully
> spark some more activity. These will probably be questions I already know
> the answer to or something which is in the realm of opinion/style and a
> point of conflict in the JS community in general. On the former kind of
> questions I'll feign ignorance in order to draw out some hopefully useful
> discussions and aspects.

Don’t.  And watch your Subject header fields.

<http://www.catb.org/~esr/faqs/smart-questions.html>

> So if you're willing to play along, here is my first question:
> 
> I have a <canvas/> element upon which I draw shapes and lines. To abstract
> away the dirty details, I've created a small language with which I use to
> draw the desired shapes:
> 
> F: Draw Forward
> f: Move Forward
> [: Push State
> ]: Pop State
> -: Rotate Left
> +: Rotate Right
> 
> An example of usage would be:
> 
> defSystem({
>     name:"Levy C Curve",
>     start: "F",
>     x: 450,
>     y: 300,
>     depth:11,
>     stepSize: 5,
>     angle: Math.PI,
>     stepAngle: Math.PI/4,
>     rules: {
>         "F": "+F--F+"
>     }
> })
> 
> […]
> Currently my program works by initially performing the replacements and
> expanding the drawing commands out as far as necessary before executing
> the final string (which as you've seen, can be quite large).
> 
> How would you approach this problem and prevent the exponential expansion
> of the string while still being able to execute the drawing rules?

I am not sure what you are asking here.  AIUI, the very point of the 
L(indenmayer)-system construction of Lévy C curves and other self-similar 
fractal curves is iterative simultaneous application of production rules. 

String values are probably the most efficient way in ECMAScript 
implementations to represent the resulting turtle graphics operations (with 
String values consisting of 16-bit units, and Number values each being 64 
bit in memory instead; add to that the complexity of substitute Array 
operations), and the Canvas API is a way to draw turtle graphics.

I also see the alternative to represent the resulting operations as a 
trinary number (e.g., “F” ≡ 0, “+” ≡ 1, “−” ≡ 2).  However, producing the 
operations value this way would not only be less time-efficient, but would 
also quickly reach the limit of IEEE-754 integer precision (at 2⁵³ [1]), 
probably allowing for fewer iterations than with a string value.

[1] <news:7523620.37GnReVopu@PointedEars.de>

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Injecting some activity through "questions" (DSLs) "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-11-01 21:06 -0700
  Re: Injecting some activity through "questions" (DSLs) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-11-02 20:15 +0000
    Re: Injecting some activity through "questions" (DSLs) "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-11-03 15:30 -0800
      Re: Injecting some activity through "questions" (DSLs) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-11-04 02:06 +0000
        Re: Injecting some activity through "questions" (DSLs) "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-11-11 13:11 -0800
          Re: Injecting some activity through "questions" (DSLs) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-11-11 21:55 +0000
  L-system construction of Lévy C curves (was: Injecting some activity through "questions" (DSLs)) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-11-02 21:31 +0100
    Re: L-system construction of Lévy C curves (was: Injecting some activity through "questions" (DSLs)) "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-11-03 15:38 -0800
      Re: L-system construction of Lévy C curves Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-11-04 03:12 +0100
        Re: L-system construction of Lévy C curves "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-11-03 19:17 -0800
  Re: Injecting some activity through "questions" (DSLs) John Harris <niam@jghnorth.org.uk.invalid> - 2013-11-03 11:23 +0000
    Re: Injecting some activity through "questions" (DSLs) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-11-03 12:43 +0000
    Re: Injecting some activity through "questions" (DSLs) "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-11-03 15:41 -0800

csiph-web