• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Generating a mandelbrot with Java  RSS feed

Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

First of all, thanks for all the replies on my other posts. I really appriciate it.

I have recently become totally facinated with fractals, and i want to make one with Java.

I have based the code on the pseudocode from the wiki article on en.wikipedia.org about mandelbrot sets.

Here is the pseudocode:

And this is my attempt to port it to Java:

There are currently no compile or runtime errors, but its not working. Its only plotting 1 pixel. I need to scale the values for x0 and y0, so they have the range (-2.5 to 1) and (-1 to 1)
I have no idea how to do this, also, the x and y variables are integers, how am i supposed to add or multiply with double x0 and y0 ?

And i also dont understand why x0 and y0 are used as the cordinates for the plotting, i mean it has to be integers, not doubles, there are no "half pixels".

Does anyone here have experience with generating fractals using Java?

Kind regards Mads Nielsen
Saloon Keeper
Posts: 4745
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For starters, there shouldn't be a loop from 1 to canvasSize, but two nested loops for 1<=x<=800 and 1<=y<=600, so that you know for which pixel the iteration depth is being calculated, and so you can set that pixel in the appropriate color. (The code is not even using "i" anywhere.)
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mads Nielsen wrote:

In your code you hardcoded x0, y0 as 1,1. That shouldnt be the case .. you should be iterating over each and every pixel from the screen (I mean your window area) and that each pixel will provide value for x0, y0
For Eg., (As Tim said)
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!