Re: Setting values in an array without usings loops [message #35869] |
Fri, 25 July 2003 08:35 |
R.G. Stockwell
Messages: 363 Registered: July 1999
|
Senior Member |
|
|
"Nancy W. Pearson" <pearson@elbereth.uchicago.edu> wrote in message
news:bfrfuj$ppd$1@bob.news.rcn.net...
> Johan Marais wrote:
>> I want to create a circle consisting out of ones but without the use of
for
>> loops. here is how I do it with the loops. Anyone that can help?
>>
>> r = 33
>> mask = intarr(2*r,2*r)
>> for m=0,2*r-1 do begin
>> for n=0,2*r-1 do begin
>> if ((m-r)^2 + (n-r)^2) gt r^2 then mask[m,n] = 1
>> endfor
>> endfor
>
> IDL> m = shift(dist(2*r),r,r) gt r
Wheeet! Illegal use of hidden "for loop"! 10 yard penalty and loss of
down.
:)
function dist....
for i=0L, m1/2 do begin ;Row loop
y = sqrt(x + i^2.) ;Euclidian distance
a[0,i] = y ;Insert the row
if i ne 0 then a[0, m1-i] = y ;Symmetrical
endfor
Cheers,
bob
PS
yeah, i suppose every array function has a "hidden for loop" if you look
deep enough.
|
|
|
Re: Setting values in an array without usings loops [message #35870 is a reply to message #35869] |
Fri, 25 July 2003 08:12  |
Johan Marais
Messages: 7 Registered: July 2003
|
Junior Member |
|
|
Thanks, that works well!!
"Nancy W. Pearson" <pearson@elbereth.uchicago.edu> wrote in message
news:bfrfuj$ppd$1@bob.news.rcn.net...
> Johan Marais wrote:
>> I want to create a circle consisting out of ones but without the use of
for
>> loops. here is how I do it with the loops. Anyone that can help?
>>
>> r = 33
>> mask = intarr(2*r,2*r)
>> for m=0,2*r-1 do begin
>> for n=0,2*r-1 do begin
>> if ((m-r)^2 + (n-r)^2) gt r^2 then mask[m,n] = 1
>> endfor
>> endfor
>
> IDL> m = shift(dist(2*r),r,r) gt r
>
> TTFN,
>
> David Grier
>
|
|
|
Re: Setting values in an array without usings loops [message #35871 is a reply to message #35870] |
Fri, 25 July 2003 07:54  |
R.G. Stockwell
Messages: 363 Registered: July 1999
|
Senior Member |
|
|
"Johan Marais" <johan.marais@uz.kuleuven.ac.be> wrote in message
news:3f213af8_7@athenanews.com...
> I want to create a circle consisting out of ones but without the use of
for
> loops. here is how I do it with the loops. Anyone that can help?
>
> r = 33
> mask = intarr(2*r,2*r)
> for m=0,2*r-1 do begin
> for n=0,2*r-1 do begin
> if ((m-r)^2 + (n-r)^2) gt r^2 then mask[m,n] = 1
> endfor
> endfor
Weehee, if one uses a little imaginaryation:
r = 33
m = (indgen(2*r)-r) # (intarr(2*r)+1)
n = (intarr(2*r)+1) # (indgen(2*r)-r)
bobbo=long(abs(complex(m,n))/r) eq 0
I would also add the following lines:
smilesize = 3
bobbo[r/2,r-smilesize:r+smilesize] = 0
bobbo[r/2+1,r-2*smilesize:r-smilesize] = 0
bobbo[r/2+1,r+smilesize:r+2*smilesize] = 0
bobbo[r/2+2,r-3*smilesize:r-2*smilesize] = 0
bobbo[r/2+2,r+2*smilesize:r+3*smilesize] = 0
bobbo[r/2+3,r-4*smilesize:r-3*smilesize] = 0
bobbo[r/2+3,r+3*smilesize:r+4*smilesize] = 0
bobbo[3*2*r/4,2*r/4] = 0
bobbo[3*2*r/4,3*2*r/4] = 0
surface,bobbo,az=89,ax=85
bwahahahahahahahahahahahahahahahaha
Cheers,
-bob
|
|
|
Re: Setting values in an array without usings loops [message #35872 is a reply to message #35871] |
Fri, 25 July 2003 07:47  |
Nancy W. Pearson
Messages: 1 Registered: July 2003
|
Junior Member |
|
|
Johan Marais wrote:
> I want to create a circle consisting out of ones but without the use of for
> loops. here is how I do it with the loops. Anyone that can help?
>
> r = 33
> mask = intarr(2*r,2*r)
> for m=0,2*r-1 do begin
> for n=0,2*r-1 do begin
> if ((m-r)^2 + (n-r)^2) gt r^2 then mask[m,n] = 1
> endfor
> endfor
IDL> m = shift(dist(2*r),r,r) gt r
TTFN,
David Grier
|
|
|