programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Can someone help me understand this code for generating fractal?

Greenhorn
Posts: 2
Hello everyone.

I'm trying to understand how this specific Koch curve works through java but I'm quite a beginner to understand some parts of the code. Here is an example I'd like to analyze (not written by me, of course, found it on the internet). I'm studying applied math in informatics and I've just begun learning java, so I'm really interested in this but in the same time kind of lost. Some parts of the code are already commented, but I'd appreciate if some of you could comment the most important parts or at least explain to me in some other way how this specific works. Thanks a lot.

Sheriff
Posts: 22846
43
It would help if you could explain what you don't understand. Otherwise somebody might spend a lot of time explaining how a Graphics object works, when it might be that you don't understand what the sine and cosine functions are doing there.

Eretaia Sorren
Greenhorn
Posts: 2
You're absolutely right. I apologize for being incoherent. I understand the mathematical part behind this, but my scarce knowledge of java prevents me from understanding the code. I've just begun learning. For example, what do these parts exactly do?

Thank you.

Sheriff
Posts: 11496
180
These are two functions that calculate what look to me like X and Y coordinate values.

The method/function iX takes in a floating point value, x, and adds it to the value of midX. The sum is then rounded using the utility function Math.round() which becomes the value returned to the caller of iX()

iY is similar. They are both called on Line 51 of the code listing you gave.

Junilu Lacar
Sheriff
Posts: 11496
180
... and Welcome to the Ranch, Eretaia!