Skip to main content

range expressions for other objects...

2 replies [Last post]
hansiraber
Offline
Joined: 2007-04-01

hey!

I'm just curious: is there any way to use the list comprehensions on other objects as well?
So analogous to this
[ 5 ... 100 step 5 ]

I'd like to do this:
[ Line{ startX: 5, startY: 0, endX: 5, endY: 10} ... Line{ startX: 100, startY: 0, endX: 100, endY: 10} step 5 ]

I know this doesn't work and JavaFX will never be able to understand which of the variables i wanna change, however... to me it seems there must be a better way than generating all of these in a while loop. Anyone has an idea?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
hansiraber
Offline
Joined: 2007-04-01

p.s. i'm not completely lost, i'm using this for now:
[code]
// The lines marking the pixel values every 5/10/100 pixels.
var lines:Line[] = [];
for( x in [5 .. 1600] where x mod 5 == 0 ){
var line:Line = Line {
startX: x, startY: 0
endX: x, endY: if( x mod 100 == 0 ) 10 else if( x mod 10 == 0 ) 5 else 3
strokeWidth: 1
stroke: Color.WHITE
};

insert line into lines
}
[/code]
well, maybe i should be satisfied... but i'm quite sure this can be written prettier!

Message was edited by: hansiraber

michael_heinrichs
Offline
Joined: 2007-11-15

Try this:

[code]
var lines = for (x in [5 .. 1600 step 5]) {
Line {
startX: x, startY: 0
endX: x, endY: if( x mod 100 == 0 ) 10 else if( x mod 10 == 0 ) 5 else 3
strokeWidth: 1
stroke: Color.WHITE
};
}
[/code]

I wrote it out of my head, but this or something close to this should work.