Re: [R] Fractals with R

2007-04-18 Thread Atte Tenkanen
Now problems with plot-command...

I try to plot Julia set and the algorithm works, if the points are drawn during 
the loop. But if I want to save the values first to the matrix and then 
afterwards plot them at once, the picture is distorted. What's wrong with the 
plot-command? I think the PointsMatrix is ok?

-Atte

C=-0.7-0.4i # Complex parameter, connected to coordinate of the Mandelbrot set 
in a complex plane.
Limits=c(-2,2)
z=0+0i
MaxIter=60
cl=colours()
Step=seq(Limits[1],Limits[2],by=0.01)
PointsMatrix=array(0,dim=c(length(Step)*length(Step),3))
a1=0

for(x in Step)
{
for(y in Step)
{
z1=x+y*1i
n=0
z=z1
while(nMaxIter  abs(z)2)
{
z=z^2+C
n=n+1
}
if(abs(z)2) colour=1
else colour=n*10
#points(z1, pch=., col=cl[colour]) # This works!
 
   # But this doesn't!
a1=a1+1
PointsMatrix[a1,]=c(x,y,colour)
}
}

#???
plot(PointsMatrix[,1], PointsMatrix[,2], xlim=Limits, ylim=Limits, 
col=cl[PointsMatrix[,3]], pch=.)

##


 Atte Tenkanen wrote:
  Hi,
  
  That is of counter for web page. Do you get some pop-up windows?
  
  
  Atte
 
 Hi Atte,


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Fractals with R

2007-04-18 Thread Atte Tenkanen
Here is a workable version for the Julia set. I put it also to 
http://fractalswithr.blogspot.com/

Atte



 Now problems with plot-command...
 
 I try to plot Julia set and the algorithm works, if the points are 
 drawn during the loop. But if I want to save the values first to 
 the matrix and then afterwards plot them at once, the picture is 
 distorted. What's wrong with the plot-command? I think the 
 PointsMatrix is ok?
 
 -Atte
 
 C=-0.7-0.4i # Complex parameter, connected to coordinate of the 
 Mandelbrot set in a complex plane.
 Limits=c(-2,2)
 z=0+0i
 MaxIter=60
 cl=colours()
 Step=seq(Limits[1],Limits[2],by=0.01)
 PointsMatrix=array(0,dim=c(length(Step)*length(Step),3))
 a1=0
 
 for(x in Step)
 {
   for(y in Step)
   {
   z1=x+y*1i
   n=0
   z=z1
   while(nMaxIter  abs(z)2)
   {
   z=z^2+C
   n=n+1
   }
   if(abs(z)2) colour=1
   else colour=n*10
   #points(z1, pch=., col=cl[colour]) # This works!
 
   # But this doesn't!
a1=a1+1
PointsMatrix[a1,]=c(x,y,colour)
   }
 }
 
 #???
 plot(PointsMatrix[,1], PointsMatrix[,2], xlim=Limits, ylim=Limits, 
 col=cl[PointsMatrix[,3]], pch=.)
 
 #---
 -#
 
 
  Atte Tenkanen wrote:
   Hi,
   
   That is of counter for web page. Do you get some pop-up windows?
   
   
   Atte
  
  Hi Atte,
  
 


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Fractals with R

2007-04-13 Thread kone
Hi everybody,

I put some R-code to a web page for drawing fractals. See

http://fractalswithr.blogspot.com/

If you have some R-code for fractal images, I'm willing to include  
them to the page.

Has somebody tried L-systems or Markov algorithm (http:// 
en.wikipedia.org/wiki/Markov_algorithm) with R?

Best wishes,

Atte Tenkanen
University of Turku, Finland

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Fractals with R

2007-04-13 Thread Gad Abraham
kone wrote:
 Hi everybody,
 
 I put some R-code to a web page for drawing fractals. See
 
 http://fractalswithr.blogspot.com/
 
 If you have some R-code for fractal images, I'm willing to include  
 them to the page.

That's really nice, but what's with the annoying popups, courtesy of 
Webstats4U?

Gad

-- 
Gad Abraham
Department of Mathematics and Statistics
The University of Melbourne
Parkville 3010, Victoria, Australia
email: [EMAIL PROTECTED]
web: http://www.ms.unimelb.edu.au/~gabraham

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Fractals with R

2007-04-13 Thread Atte Tenkanen
Hi,

That is of counter for web page. Do you get some pop-up windows?


Atte


 kone wrote:
  Hi everybody,
  
  I put some R-code to a web page for drawing fractals. See
  
  http://fractalswithr.blogspot.com/
  
  If you have some R-code for fractal images, I'm willing to 
 include  
  them to the page.
 
 That's really nice, but what's with the annoying popups, courtesy 
 of 
 Webstats4U?
 
 Gad
 
 -- 
 Gad Abraham
 Department of Mathematics and Statistics
 The University of Melbourne
 Parkville 3010, Victoria, Australia
 email: [EMAIL PROTECTED]
 web: http://www.ms.unimelb.edu.au/~gabraham


__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Fractals with R

2007-04-13 Thread Gad Abraham
Atte Tenkanen wrote:
 Hi,
 
 That is of counter for web page. Do you get some pop-up windows?
 
 
 Atte

Hi Atte,

Yes, annoying stuff from http://ilead.itrack.it. Your webcounter
provider using their scripts to do this, without your intervention. How
nice of them...

Cheers,
Gad

-- 
Gad Abraham
Department of Mathematics and Statistics
University of Melbourne
Victoria 3010, Australia
email: [EMAIL PROTECTED]
web: http://www.ms.unimelb.edu.au/~gabraham

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Fractals with R

2007-04-13 Thread Jeffrey Horner
kone wrote:
 Hi everybody,
 
 I put some R-code to a web page for drawing fractals. See
 
 http://fractalswithr.blogspot.com/
 
 If you have some R-code for fractal images, I'm willing to include  
 them to the page.
 
 Has somebody tried L-systems or Markov algorithm (http:// 
 en.wikipedia.org/wiki/Markov_algorithm) with R?

Here's an interactive example of how to draw pretty pictures with 
polynomials and other R functions:

http://biostat3.mc.vanderbilt.edu/polyart/

...without the pop-up windows ;)

Cheers,

Jeff
-- 
http://biostat.mc.vanderbilt.edu/JeffreyHorner

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Fractals with R

2007-04-13 Thread Atte Tenkanen
Hi Jeff,

Thank you for the nice page. I also have done some R-videos combining jpeg's 
in video editor (or with mjpegtools) but this kind of command in R would be 
useful. Unfortunately I couldn't install NRart-package but got a lot of fun 
when playing with your Start Making Art!-page.

I haven't met pop-ups in my page, but perhaps the counter-server detects my id 
and leave me alone?

Atte

 kone wrote:
  Hi everybody,
  
  I put some R-code to a web page for drawing fractals. See
  
  http://fractalswithr.blogspot.com/
  
  If you have some R-code for fractal images, I'm willing to 
 include  
  them to the page.
  
  Has somebody tried L-systems or Markov algorithm (http:// 
  en.wikipedia.org/wiki/Markov_algorithm) with R?
 
 Here's an interactive example of how to draw pretty pictures with 
 polynomials and other R functions:
 
 http://biostat3.mc.vanderbilt.edu/polyart/
 
 ...without the pop-up windows ;)
 
 Cheers,
 
 Jeff
 -- 
 http://biostat.mc.vanderbilt.edu/JeffreyHorner


__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Fractals in R and having fun! (and more persp and color)

2003-09-18 Thread ucgamdo
Hi Martin,

   Thanks a lot for pointing your function out to me. I tried it, and
indeed it is very fast. I will have a close look at the asymmetry problem
in my own code, although this sounds pretty bizarre to me, I mean, I
realised that there was some asymmetry but I didn't really payed attention
to that. I think that the high number of iterations that can be achieved
with your function will be the solution to obtaining 'smoother' slopes in
the perspective plot (i.e. the outer regions that rise progressively
towards the set). If you come with any ideas on how to improve that
perspective let me know. I think I'll have a go to the c code.

Thanks,
Mario.

At 10:21 18/09/03 +0200, you wrote:

Mario Well, I started playing with fractals in R, and wrote
Mario a function to generate de Mandelbrot set, which might
Mario be of interest to some people

Mario
###
Mario # Mandelbrot set
Mario
###

Mario mandelbrot - function(x = c(-3.0, 1.0),   # x coordinates
Marioy = c(-1.8, 1.8),   # y coordinates
Mariob = .05,# by 'steps'
Marioiter = 20)  # maximum number of
iterations

..
..
..

Well, only a bit more than year ago I had posted my version of
mandelbrot() and a drawing function, see

   http://finzi.psych.upenn.edu/R/Rhelp02a/archive/5898.html

   [ I have a slightly updated version of the R code, that is now
 available as ftp://stat.ethz.ch/U/maechler/R/Mandelbrot.R
   ]

which is an order of magnitude more efficient than yours (22 x
faster for your b = 0.01, *1), *2)
and with an iterImage() function for drawing its result in
several (simple) color schemes.
I agree that the proper solution would *definitely* use C code!

Your idea of using persp() -- while seen frequently in fractal books,
is new ``for R'' however, and nice!  Thank you.


Regards,
Martin

*1) mainly because I only have the iteration loop
and do the rest vectorized, but also because I have a check
for symmetry and make use of it when appropriate

*2) For speed comparison, note that I use 10 x more iterations
and a much higher resolution by default

*3) When I do the comparison, I see that your function's result
slightly differs from mine -- not for the Mandelbrot set
itself, but for the very ``outer points'' (the dark orange
ones in the image plot). Your result is
asymmetric and hence can't be quite correct.



__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] Fractals in R and having fun! (and more persp and color)

2003-09-17 Thread ucgamdo
Well, I started playing with fractals in R, and wrote a function to
generate de Mandelbrot set, which might
be of interest to some people

###
# Mandelbrot set
###

mandelbrot - function(x = c(-3.0, 1.0),   # x coordinates
   y = c(-1.8, 1.8),   # y coordinates
   b = .05,# by 'steps'
   iter = 20)  # maximum number of iterations
{
  m = NULL  # will store the results, this is the 'image' matrix
  
  for(i in seq(x[1], x[2], by = b)) {

r = NULL # stores part of the iteration results

for(j in seq(y[1], y[2], by = b)) {

  it = iter # will hold iteration at which point (i, j) breaks off

  c = c(i, j)  # initial point
  z = c(i, j)  # i: real part; j: imaginary part

  for(k in 1:iter) {

# the Mandelbrot iteration formulae: z - z*z + c
z =  c(z[1]^2 - z[2]^2, 2 * z[1]*z[2]) + c

# tests if point breaks off
if((z[1] + z[2])^2  4) { it = k; break }
  }

  r = c(r, it) # stores iteration results
}
# constructs the 'image' matrix
m = rbind(m, r)
  }

  # the output fractal object
  fractal = list(x = seq(x[1], x[2], by = b), # x coordinates
y = seq(y[1], y[2], by = b),  # y coordinates
z = m)# it matrix
}

##
# here goes how it works
##

frac - mandelbrot()
image(frac)  # perhaps not very nice!

# more resolution, beware, this might take some time to calculate

frac - mandelbrot(b = .01)
image(frac)

# now here comes the fun, lets do a persp plot of the set!

persp(log(frac$z), border = NA, theta = 225, phi = 45, col = gray, shade
= .4)

###END###

Well, here comes what would have been my question. How to put some nice
colors to the above perspective plot? I wanted to post this question some
weeks ago, but it was answered yesterday after all the discussion on persp
and colors. If you see my previous post, you'll the definition of
surf.colors used below:

persp(log(frac$z), border = NA, theta = 225, phi = 45, col =
surf.colors(frac$z, col = c(gray(seq(0.5, 1, len = 39)), black)), shade =
.4)

that was what I always wanted to do, and this was the source of my
confusion when checking the code in persp demo.

But now some new question arises, which I'll leave to the interested hacker:

Any C programmer who volunteers to write and link c code to R to calculate de
Mandelbrot set faster?

Does anyone have any idea on how to 'smooth' the valleys and ridges that
rise towards the set?, i.e. to avoid the stairs like appearence of the plot?

I hope you can have some fun with this!

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help