# 2D array

11 messages
Open this post in threaded view
|

## 2D array

 Bonjour ! How can I parse a 2D array ? Something like that !? :-( ///////////////////////////////////////////////////////////////// for(i = [0 : 3]) // rows {         for(j = [0 : 3]) // columns         {           a[ i, j];         } } a = [         [0,1,1,0],         [1,0,0,1],         [1,1,1,1],         [1,0,0,1]         ]; Regards, Maurn
Open this post in threaded view
|

## Re: 2D array

 On Tue, 5 Jun 2012 20:48:38 +0200 Maurin Donneaud <[hidden email]> wrote: > Bonjour ! > > How can I parse a 2D array ? > Something like that !? a[i * 4 + j] I'm increasingly finding the trick is to write programs in real languages that output OpenSCAD files though. There are fundamental things missing like class heirarchies, function pointers, structures and various kinds of iteration. Quite possibly those not being in OpenSCAD but generating OpenSCAD is the right thing anyway. Alan
Open this post in threaded view
|

## Re: 2D array

 You're thinking too hard.  The matrix is already in vector-of-vector form so the following works:for(i = [0 : 3]) // rows{ echo(str("row:",i)); for(j = [0 : 3]) // columns { echo(a[i][j]); }}a = [ [0,1,1,0], [1,0,0,1], [1,1,1,1], [1,0,0,1] ];cube();On 2012-06-05, at 3:02 PM, Alan Cox wrote:On Tue, 5 Jun 2012 20:48:38 +0200Maurin Donneaud <[hidden email]> wrote:Bonjour !How can I parse a 2D array ?Something like that !?a[i * 4 + j]I'm increasingly finding the trick is to write programs in real languagesthat output OpenSCAD files though. There are fundamental things missinglike class heirarchies, function pointers, structures and various kindsof iteration.Quite possibly those not being in OpenSCAD but generating OpenSCAD is theright thing anyway.Alan_______________________________________________OpenSCAD mailing list[hidden email]http://rocklinux.net/mailman/listinfo/openscad --"The future is already here.  It's just not very evenly distributed" -- William GibsonMe: http://clothbot.com/wiki/
Open this post in threaded view
|

## Re: 2D array

 …or to allow for variable-length rows, do something like the following:for(i = [0 : len(a)-1]) // rows{ echo(str("row:",i)); for(j = [0 : len(a[i])-1]) // columns { echo(a[i][j]); }}a = [ [0,1,1,0], [1,0,0,1], [1,1,1,1], [1,0,0,1] ];cube();On 2012-06-05, at 3:09 PM, Andrew Plumb wrote:You're thinking too hard.  The matrix is already in vector-of-vector form so the following works:for(i = [0 : 3]) // rows{ echo(str("row:",i)); for(j = [0 : 3]) // columns { echo(a[i][j]); }}a = [ [0,1,1,0], [1,0,0,1], [1,1,1,1], [1,0,0,1] ];cube();On 2012-06-05, at 3:02 PM, Alan Cox wrote:On Tue, 5 Jun 2012 20:48:38 +0200Maurin Donneaud <[hidden email]> wrote:Bonjour !How can I parse a 2D array ?Something like that !?a[i * 4 + j]I'm increasingly finding the trick is to write programs in real languagesthat output OpenSCAD files though. There are fundamental things missinglike class heirarchies, function pointers, structures and various kindsof iteration.Quite possibly those not being in OpenSCAD but generating OpenSCAD is theright thing anyway.Alan_______________________________________________OpenSCAD mailing list[hidden email]http://rocklinux.net/mailman/listinfo/openscad --"The future is already here.  It's just not very evenly distributed" -- William GibsonMe: http://clothbot.com/wiki/ _______________________________________________OpenSCAD mailing list[hidden email]http://rocklinux.net/mailman/listinfo/openscad --"The future is already here.  It's just not very evenly distributed" -- William GibsonMe: http://clothbot.com/wiki/
Open this post in threaded view
|

## Re: 2D array

 In reply to this post by Alan Cox a[i][j] as the array is actually a list of lists.On 5 June 2012 20:02, Alan Cox wrote: On Tue, 5 Jun 2012 20:48:38 +0200 Maurin Donneaud <[hidden email]> wrote: > Bonjour ! > > How can I parse a 2D array ? > Something like that !? a[i * 4 + j] I'm increasingly finding the trick is to write programs in real languages that output OpenSCAD files though. There are fundamental things missing like class heirarchies, function pointers, structures and various kinds of iteration. Quite possibly those not being in OpenSCAD but generating OpenSCAD is the right thing anyway. Alan _______________________________________________ OpenSCAD mailing list [hidden email] http://rocklinux.net/mailman/listinfo/openscad
Open this post in threaded view
|

## Re: 2D array

Open this post in threaded view
|

## Re: 2D array

 Administrator On Jun 6, 2012, at 18:35 , Peter Falke wrote: > len() is an undocumented command of OpenSCAD in the openscad wiki (I just checked.) > Are there any other such commands around? len() was added in OpenSCAD 2011.12. The wiki documentation isn't always up to date as it's community managed. For an overview over actual changes in recent versions, please consult the release notes: https://github.com/openscad/openscad/blob/master/RELEASE_NOTES -Marius
Open this post in threaded view
|

## Re: 2D array

Open this post in threaded view
|