Name: [011] John Montgomery
Member: 99 months
Authored: 21 videos
Description: I'm a C/C++, Java and Python programmer living in Hove, UK. ...

Animated Mandelbrot fractal applet - Part 8 [ID:066] (9/10)

in series: Writing an Applet with Java

video tutorial by John Montgomery, added 03/07

(Showmedo is undergoing major changes. To report any problems viewing the videos please email us and include browser and OS specifics. Cheers - Kyran.)

Half of creating a nice interactive applet is ensuring that things at least appear to be happening. So rather than rendering the entire Mandelbrot fractal in one go, John demonstrates how it can be rendered in parts.

John uses a 'dissolve' to bring in the Mandelbrot as it is rendered. There is also a nice example here of the difference in performance that can occur by choosing a suitable data structure - first John uses an ArrayList but the 'remove' method proves to be slow, then John uses a LinkedList which is clearly much faster.

Note - John refers to using a 'cross fade' in this video, this is an error and the fade is really a 'dissolve'.

Uploaded on 24th September 2006, running time 8 minutes.

Got any questions?

Get answers in the ShowMeDo Learners Google Group.

Video statistics:

  • Video's rank shown in the most popular listing
  • Video plays: 1048 (since July 30th)
  • Plays in last week: 0
  • Published: Sometime before 1st March 2007 (in other words - we don't remember!)

Thank-yous, questions and comments

If this video tutorial was helpful please take some time to say thank-you to the authors for their hard work. Feel free to ask questions. Let the author know why their video tutorial was useful - what are you learning about? Did the video tutorial save you time? Would you like to see more?

You may also want to see our ShowMeDo Google Group to speak to our active users and authors.

Your email address will not be published.

Show some quick comments >>

All comments excluding tick-boxed quick-comments

6. anonymous Thu, 27 Nov 2008 19:42

Fascinating to see you assemble a java applet in real time! I'm retired from software development and got out just as java was hitting its stride.

I found your site while surfing for fast, high resolution interactive applications running the mandelbrodt set

Hi Fred. I feel I ought to step in and make a comment here - your points are quite correct, but in fairness this video set isn't really about the <i>efficient</i> use of data structures. John's showing new Java users how to draw and interact with a simple app!

The user gets to see John choose a structure which solves the problem in hand (a terribly useful act in its own right). He also gets to show that his first choice of data-structure is too slow (a useful point for a newbie to learn from), and that a refined choice of structure does an adequate job solving the task (making for a pragmatic solution - again useful for a is always tricky knowing when to stop tinkering with code to make it 'better').

Whilst more efficient programming choices could have been made, it is the animation and user-interaction components of the video that should be the take-home points.

Of course, we'd welcome a video set discussing the finer points of how to choose the right data structure to solve a tricky problem, given memory/time constraints and the like...that'd also make for a great educational piece for an intermediate Java user. Maybe you'd be interested in sharing your knowledge of the subject?

Hi Fred,

Thanks for the info. I know it's faster to remove from the end of an ArrayList, but it required less typing to change the type of the list (to LinkedList) rather than remove from the end of the list...

Laziness is meant to be a programmer's virtue after all ;^)

I added an updated version of the code to <a href="">the wiki</a> thich was roughly how I would have done it, if I was more concerned about speed.

Cheers, John

Hi John,

ArrayList is masssively faster than LinkedList in most situations (including this one) if used appropriately. In this case remove items from the END, not the beginning of the ArrayList -- removing from the front requires copying all elements above down by one for each removal. Removing from the end only changes one index. But the better solution is to never remove elements.

-- Fred

Hi Fred,

Yeah, I am well aware of the inefficiencies of creating the ArrayList each time and could have done better on that respect, but felt that it was important to keep all of the code in sight - which is why I only commented on the fact this may be inefficient.

When I recorded this, I was partially banking on ArrayList simply being "fast enough" on the G5 iMac I was using, but it quickly became apparent that it wasn't - hence the switch mid way through to a LinkedList. It was slightly unintentional, but in the end I figured it was a good example of how using the wrong kind of data structure can have a big impact.

Again with the Java 5/generics, it was partly a desire to keep things a bit simpler, but also the fact that I had not set up Eclipse on that iMac (not my usual dev machine) to use Java 5 yet.

I guess in short I was trying not to sweat the small stuff too much and just get on with demoing something interesting. Glad you basically still liked it. Thanks for the feedback, it's always handy for other people looking at this to get some more input. Maybe you should add a section on code improvements to the wiki page for this series?

cheers, John

Hi John,

I just took a look at your dissolving Mandelbrot program. As usual I liked your style of presentation, and especially that you leave some of the abortive starts in.

However, there is a data structure error so serious as to make your program work best as a counter example. The basic problem is that you remove from the front of an ArrayList rather than the back, which makes the performance O(N) instead of O(1) -- from a trivial constant time to a substantial amount of copying, which aside from its use of the CPU seriously messes with the hardware memory cache.

But the approach of dynamically creating the ArrayList each time is flawed anyway, as you pointed out to some extent. It should be created only once, populated only once, and shuffled only once. Nothing should ever be removed from it.

And finally, it feels a little stale. Java 5 has been out for a while now, and a generic ArrayLists are the norm, at least for teaching materials. And traversing it with the enhanced for loop would be nice.

Despite this technical flaw, I still enjoyed it. I hope you don't find my comments too discouraging, and keep up the good work.

Cheers, Fred

Showmedo is a peer-produced video-tutorials and screencasts site for free and open-source software (FOSS)- with the exception of some club videos, the large majority are free to watch and download.

how to help » about » faq »

Educating the Open-source Community With Showmedo

Although as important as the software it supports, education and documentation are relatively neglected in the Open-source world. Coders love to code, and explaining how best to use or improve the software tends to be deferred or even sidelined.

At Showmedo we believe the community can play a vital role here and also say thanks for the tools and software that make our lives easier. If you have a piece of software you love or a programming langugage you are enthusiastic about, why not make a screencast showing others how to use it? All the stuff you wish you'd been told, the tips, tricks, insights that would have saved you time and frustration.

Screencasting is easier than you think, and we're happy to help you. You can emailus for advice or just use some of the how-to screencasts on the site. This screencasting learning-pathis a good place to start.

Kudos and Thanks for John



Showmedo's development is fairly rapid and bugs will inevitably creep in. If you have any problems please drop us a line using the contact address below. Likewise, any suggestions for improvements to the site are gratefully received.