├── .gitignore
├── LICENSE
├── LICENSE.lesser
├── README.md
├── Sources
└── libnoise
│ ├── GradientPresets.hx
│ ├── ModuleBase.hx
│ ├── QualityMode.hx
│ ├── Utils.hx
│ ├── builder
│ ├── NoiseMap.hx
│ ├── NoiseMapBuilder.hx
│ ├── NoiseMapBuilderCylinder.hx
│ ├── NoiseMapBuilderPlane.hx
│ └── NoiseMapBuilderSphere.hx
│ ├── generator
│ ├── Billow.hx
│ ├── Checker.hx
│ ├── Const.hx
│ ├── Cylinder.hx
│ ├── Perlin.hx
│ ├── RidgedMultifractal.hx
│ ├── Sphere.hx
│ └── Voronoi.hx
│ ├── model
│ ├── Cylinder.hx
│ ├── Plane.hx
│ └── Sphere.hx
│ └── operator
│ ├── Abs.hx
│ ├── Add.hx
│ ├── Blend.hx
│ ├── Cache.hx
│ ├── Clamp.hx
│ ├── Curve.hx
│ ├── Displace.hx
│ ├── Exponent.hx
│ ├── Invert.hx
│ ├── Max.hx
│ ├── Min.hx
│ ├── Multiply.hx
│ ├── Power.hx
│ ├── Rotate.hx
│ ├── Scale.hx
│ ├── ScaleBias.hx
│ ├── Select.hx
│ ├── Subtract.hx
│ ├── Terrace.hx
│ ├── Translate.hx
│ └── Turbulence.hx
├── haxelib.json
├── test.hxml
└── test
└── Sources
└── Test.hx
/.gitignore:
--------------------------------------------------------------------------------
1 | test/images/*
2 | test/build-test
3 | .idea
4 | *.iml
5 | libnoise.zip
6 | .directory
7 |
8 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
--------------------------------------------------------------------------------
/LICENSE.lesser:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 |
9 | This version of the GNU Lesser General Public License incorporates
10 | the terms and conditions of version 3 of the GNU General Public
11 | License, supplemented by the additional permissions listed below.
12 |
13 | 0. Additional Definitions.
14 |
15 | As used herein, "this License" refers to version 3 of the GNU Lesser
16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU
17 | General Public License.
18 |
19 | "The Library" refers to a covered work governed by this License,
20 | other than an Application or a Combined Work as defined below.
21 |
22 | An "Application" is any work that makes use of an interface provided
23 | by the Library, but which is not otherwise based on the Library.
24 | Defining a subclass of a class defined by the Library is deemed a mode
25 | of using an interface provided by the Library.
26 |
27 | A "Combined Work" is a work produced by combining or linking an
28 | Application with the Library. The particular version of the Library
29 | with which the Combined Work was made is also called the "Linked
30 | Version".
31 |
32 | The "Minimal Corresponding Source" for a Combined Work means the
33 | Corresponding Source for the Combined Work, excluding any source code
34 | for portions of the Combined Work that, considered in isolation, are
35 | based on the Application, and not on the Linked Version.
36 |
37 | The "Corresponding Application Code" for a Combined Work means the
38 | object code and/or source code for the Application, including any data
39 | and utility programs needed for reproducing the Combined Work from the
40 | Application, but excluding the System Libraries of the Combined Work.
41 |
42 | 1. Exception to Section 3 of the GNU GPL.
43 |
44 | You may convey a covered work under sections 3 and 4 of this License
45 | without being bound by section 3 of the GNU GPL.
46 |
47 | 2. Conveying Modified Versions.
48 |
49 | If you modify a copy of the Library, and, in your modifications, a
50 | facility refers to a function or data to be supplied by an Application
51 | that uses the facility (other than as an argument passed when the
52 | facility is invoked), then you may convey a copy of the modified
53 | version:
54 |
55 | a) under this License, provided that you make a good faith effort to
56 | ensure that, in the event an Application does not supply the
57 | function or data, the facility still operates, and performs
58 | whatever part of its purpose remains meaningful, or
59 |
60 | b) under the GNU GPL, with none of the additional permissions of
61 | this License applicable to that copy.
62 |
63 | 3. Object Code Incorporating Material from Library Header Files.
64 |
65 | The object code form of an Application may incorporate material from
66 | a header file that is part of the Library. You may convey such object
67 | code under terms of your choice, provided that, if the incorporated
68 | material is not limited to numerical parameters, data structure
69 | layouts and accessors, or small macros, inline functions and templates
70 | (ten or fewer lines in length), you do both of the following:
71 |
72 | a) Give prominent notice with each copy of the object code that the
73 | Library is used in it and that the Library and its use are
74 | covered by this License.
75 |
76 | b) Accompany the object code with a copy of the GNU GPL and this license
77 | document.
78 |
79 | 4. Combined Works.
80 |
81 | You may convey a Combined Work under terms of your choice that,
82 | taken together, effectively do not restrict modification of the
83 | portions of the Library contained in the Combined Work and reverse
84 | engineering for debugging such modifications, if you also do each of
85 | the following:
86 |
87 | a) Give prominent notice with each copy of the Combined Work that
88 | the Library is used in it and that the Library and its use are
89 | covered by this License.
90 |
91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license
92 | document.
93 |
94 | c) For a Combined Work that displays copyright notices during
95 | execution, include the copyright notice for the Library among
96 | these notices, as well as a reference directing the user to the
97 | copies of the GNU GPL and this license document.
98 |
99 | d) Do one of the following:
100 |
101 | 0) Convey the Minimal Corresponding Source under the terms of this
102 | License, and the Corresponding Application Code in a form
103 | suitable for, and under terms that permit, the user to
104 | recombine or relink the Application with a modified version of
105 | the Linked Version to produce a modified Combined Work, in the
106 | manner specified by section 6 of the GNU GPL for conveying
107 | Corresponding Source.
108 |
109 | 1) Use a suitable shared library mechanism for linking with the
110 | Library. A suitable mechanism is one that (a) uses at run time
111 | a copy of the Library already present on the user's computer
112 | system, and (b) will operate properly with a modified version
113 | of the Library that is interface-compatible with the Linked
114 | Version.
115 |
116 | e) Provide Installation Information, but only if you would otherwise
117 | be required to provide such information under section 6 of the
118 | GNU GPL, and only to the extent that such information is
119 | necessary to install and execute a modified version of the
120 | Combined Work produced by recombining or relinking the
121 | Application with a modified version of the Linked Version. (If
122 | you use option 4d0, the Installation Information must accompany
123 | the Minimal Corresponding Source and Corresponding Application
124 | Code. If you use option 4d1, you must provide the Installation
125 | Information in the manner specified by section 6 of the GNU GPL
126 | for conveying Corresponding Source.)
127 |
128 | 5. Combined Libraries.
129 |
130 | You may place library facilities that are a work based on the
131 | Library side by side in a single library together with other library
132 | facilities that are not Applications and are not covered by this
133 | License, and convey such a combined library under terms of your
134 | choice, if you do both of the following:
135 |
136 | a) Accompany the combined library with a copy of the same work based
137 | on the Library, uncombined with any other library facilities,
138 | conveyed under the terms of this License.
139 |
140 | b) Give prominent notice with the combined library that part of it
141 | is a work based on the Library, and explaining where to find the
142 | accompanying uncombined form of the same work.
143 |
144 | 6. Revised Versions of the GNU Lesser General Public License.
145 |
146 | The Free Software Foundation may publish revised and/or new versions
147 | of the GNU Lesser General Public License from time to time. Such new
148 | versions will be similar in spirit to the present version, but may
149 | differ in detail to address new problems or concerns.
150 |
151 | Each version is given a distinguishing version number. If the
152 | Library as you received it specifies that a certain numbered version
153 | of the GNU Lesser General Public License "or any later version"
154 | applies to it, you have the option of following the terms and
155 | conditions either of that published version or of any later version
156 | published by the Free Software Foundation. If the Library as you
157 | received it does not specify a version number of the GNU Lesser
158 | General Public License, you may choose any version of the GNU Lesser
159 | General Public License ever published by the Free Software Foundation.
160 |
161 | If the Library as you received it specifies that a proxy can decide
162 | whether future versions of the GNU Lesser General Public License shall
163 | apply, that proxy's public statement of acceptance of any version is
164 | permanent authorization for you to choose that version for the
165 | Library.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | #Libnoise
2 |
3 | This is a haxe port of [libnoise](http://libnoise.sourceforge.net/), the coherent noise library.
4 | The port is almost complete, only the gradient and noise2D utilities are missing.
5 |
6 | Install with :
7 | ```
8 | haxelib install libnoise
9 | ```
10 |
11 | ##changelog
12 | ###1.0.1:
13 | * fixes to be compatible with haxe 3.3
14 | * added NoiseMap
15 | * added builders to create planar (with seamless option), spherical and cylindrical projections
16 | * added builders tests
17 | * inlined some utils function to get ~+20% performance
18 |
19 |
20 | ##Images
21 |
22 | Perlin :
23 |
24 | 
25 |
26 | Billow :
27 |
28 | 
29 |
30 | Voronoi :
31 |
32 | 
33 |
34 | Ridged multifractal :
35 |
36 | 
37 |
38 | Min operator :
39 |
40 | 
41 |
42 | Select operator :
43 |
44 | 
45 |
46 | Turbulences operator :
47 |
48 | 
49 |
50 |
51 | More images and examples usages in the test folder, require the [format library](http://lib.haxe.org/p/format) to generate images.
52 |
53 | #License
54 | This port is released under the [LGPL licence](https://www.gnu.org/licenses/lgpl.html), see LICENSE and LICENSE.lesser for details.
55 | #About
56 | [Libnoise](http://libnoise.sourceforge.net/) was originaly created by Jason Bevins. The library was later ported to
57 | Xna by [Marc André Ueberall](http://www.big-black-block.com/#home), and moved to Unity by Tim Speltz. This haxe
58 | version was mainly ported with [Libnoise.unity](https://github.com/ricardojmendez/LibNoise.Unity) as reference.
59 |
--------------------------------------------------------------------------------
/Sources/libnoise/GradientPresets.hx:
--------------------------------------------------------------------------------
1 | package libnoise;
2 |
3 | //Don't use this yet
4 | /*
5 | class GradientPresets {
6 |
7 | static var Empty(default,null) : Gradient;
8 | static var Grayscale(default,null) : Gradient;
9 | static var Rgb(default,null) : Gradient;
10 | static var Rgba(default,null) : Gradient;
11 | static var Terrain(default,null) : Gradient;
12 |
13 | public static function __init__(){
14 | // Grayscale gradient color keys
15 | var grayscaleColorKeys = new List();
16 | grayscaleColorKeys.push(new GradientColorKey(Color.black, 0));
17 | grayscaleColorKeys.push(new GradientColorKey(Color.white, 1));
18 |
19 | // RGB gradient color keys
20 | var rgbColorKeys = new List();
21 | rgbColorKeys.push(new GradientColorKey(Color.red, 0));
22 | rgbColorKeys.push(new GradientColorKey(Color.green, 0.5));
23 | rgbColorKeys.push(new GradientColorKey(Color.blue, 1));
24 |
25 | // RGBA gradient color keys
26 | var rgbaColorKeys = new List();
27 | rgbaColorKeys.push(new GradientColorKey(Color.red, 0));
28 | rgbaColorKeys.push(new GradientColorKey(Color.green, 1 / 3));
29 | rgbaColorKeys.push(new GradientColorKey(Color.blue, 2 / 3));
30 | rgbaColorKeys.push(new GradientColorKey(Color.black, 1));
31 |
32 |
33 | // RGBA gradient alpha keys
34 | var rgbaAlphaKeys = new List();
35 | rgbaAlphaKeys.push(new GradientAlphaKey(0, 2 / 3));
36 | rgbaAlphaKeys.push(new GradientAlphaKey(1, 1));
37 |
38 | // Terrain gradient color keys
39 | var terrainColorKeys = new List();
40 | terrainColorKeys.push(new GradientColorKey(new Color(0, 0, 0.5), 0));
41 | terrainColorKeys.push(new GradientColorKey(new Color(0.125, 0.25, 0.5), 0.4));
42 | terrainColorKeys.push(new GradientColorKey(new Color(0.25, 0.375, 0.75), 0.48));
43 | terrainColorKeys.push(new GradientColorKey(new Color(0, 0.75, 0), 0.5));
44 | terrainColorKeys.push(new GradientColorKey(new Color(0.75, 0.75, 0), 0.625));
45 | terrainColorKeys.push(new GradientColorKey(new Color(0.625, 0.375, 0.25), 0.75));
46 | terrainColorKeys.push(new GradientColorKey(new Color(0.5, 1, 1), 0.875));
47 | terrainColorKeys.push(new GradientColorKey(Color.white, 1));
48 |
49 | // Generic gradient alpha keys
50 | var alphaKeys = new List();
51 | alphaKeys.push(new GradientAlphaKey(1, 0));
52 | alphaKeys.push(new GradientAlphaKey(1, 1));
53 |
54 | Empty = new Gradient();
55 |
56 | Rgb = new Gradient();
57 | Rgb.SetKeys(rgbColorKeys.ToArray(), alphaKeys.ToArray());
58 |
59 | Rgba = new Gradient();
60 | Rgba.SetKeys(rgbaColorKeys.ToArray(), rgbaAlphaKeys.ToArray());
61 |
62 | Grayscale = new Gradient();
63 | Grayscale.SetKeys(grayscaleColorKeys.ToArray(), alphaKeys.ToArray());
64 |
65 | Terrain = new Gradient();
66 | Terrain.SetKeys(terrainColorKeys.ToArray(), alphaKeys.ToArray());
67 | }
68 |
69 |
70 | }
71 | */
--------------------------------------------------------------------------------
/Sources/libnoise/ModuleBase.hx:
--------------------------------------------------------------------------------
1 | package libnoise;
2 |
3 | class ModuleBase {
4 |
5 | var modules : Array;
6 |
7 | public function new(count : Int) {
8 | if (count > 0)
9 | modules = new Array();
10 | }
11 |
12 | public inline function get(index : Int) {
13 | return this.modules[index];
14 | }
15 |
16 | public inline function set(index : Int, value : ModuleBase) {
17 | return this.modules[index] = value;
18 | }
19 |
20 | public inline function length(){
21 | return modules.length;
22 | }
23 |
24 | public function getValue(x : Float, y : Float, z : Float) : Float{
25 | throw "ModuleBase.getValue is an abstract method";
26 | return 0;
27 | }
28 |
29 | //TODO: see if dispose functions need to be implemented (cf https://github.com/ricardojmendez/LibNoise.Unity/blob/master/ModuleBase.cs#L158)
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/Sources/libnoise/QualityMode.hx:
--------------------------------------------------------------------------------
1 | package libnoise;
2 |
3 | enum QualityMode {
4 | LOW;
5 | MEDIUM;
6 | HIGH;
7 | }
8 |
--------------------------------------------------------------------------------
/Sources/libnoise/Utils.hx:
--------------------------------------------------------------------------------
1 | package libnoise;
2 |
3 | class Utils {
4 | static public inline var SQRT3 : Float = 1.7320508075688772935;
5 | static public inline var OctavesMaximum = 30;
6 | static public inline var Deg2Rad = 0.01745329251;
7 |
8 | #if NOISE_VERSION_1
9 | static private var GeneratorNoiseX : Int = 1;
10 | static private var GeneratorNoiseY : Int = 31337;
11 | static private var GeneratorNoiseZ : Int = 263;
12 | static private var GeneratorSeed : Int = 1013;
13 | static private var GeneratorShift : Int = 13;
14 | #else
15 | static private var GeneratorNoiseX : Int = 1619;
16 | static private var GeneratorNoiseY : Int = 31337;
17 | static private var GeneratorNoiseZ : Int = 6971;
18 | static private var GeneratorSeed : Int = 1013;
19 | static private var GeneratorShift : Int = 8;
20 | #end
21 |
22 | public static var Randoms : Array = [
23 | -0.763874, -0.596439, -0.246489, 0.0, 0.396055, 0.904518, -0.158073, 0.0,
24 | -0.499004, -0.8665, -0.0131631, 0.0, 0.468724, -0.824756, 0.316346, 0.0,
25 | 0.829598, 0.43195, 0.353816, 0.0, -0.454473, 0.629497, -0.630228, 0.0,
26 | -0.162349, -0.869962, -0.465628, 0.0, 0.932805, 0.253451, 0.256198, 0.0,
27 | -0.345419, 0.927299, -0.144227, 0.0, -0.715026, -0.293698, -0.634413, 0.0,
28 | -0.245997, 0.717467, -0.651711, 0.0, -0.967409, -0.250435, -0.037451, 0.0,
29 | 0.901729, 0.397108, -0.170852, 0.0, 0.892657, -0.0720622, -0.444938, 0.0,
30 | 0.0260084, -0.0361701, 0.999007, 0.0, 0.949107, -0.19486, 0.247439, 0.0,
31 | 0.471803, -0.807064, -0.355036, 0.0, 0.879737, 0.141845, 0.453809, 0.0,
32 | 0.570747, 0.696415, 0.435033, 0.0, -0.141751, -0.988233, -0.0574584, 0.0,
33 | -0.58219, -0.0303005, 0.812488, 0.0, -0.60922, 0.239482, -0.755975, 0.0,
34 | 0.299394, -0.197066, -0.933557, 0.0, -0.851615, -0.220702, -0.47544, 0.0,
35 | 0.848886, 0.341829, -0.403169, 0.0, -0.156129, -0.687241, 0.709453, 0.0,
36 | -0.665651, 0.626724, 0.405124, 0.0, 0.595914, -0.674582, 0.43569, 0.0,
37 | 0.171025, -0.509292, 0.843428, 0.0, 0.78605, 0.536414, -0.307222, 0.0,
38 | 0.18905, -0.791613, 0.581042, 0.0, -0.294916, 0.844994, 0.446105, 0.0,
39 | 0.342031, -0.58736, -0.7335, 0.0, 0.57155, 0.7869, 0.232635, 0.0,
40 | 0.885026, -0.408223, 0.223791, 0.0, -0.789518, 0.571645, 0.223347, 0.0,
41 | 0.774571, 0.31566, 0.548087, 0.0, -0.79695, -0.0433603, -0.602487, 0.0,
42 | -0.142425, -0.473249, -0.869339, 0.0, -0.0698838, 0.170442, 0.982886, 0.0,
43 | 0.687815, -0.484748, 0.540306, 0.0, 0.543703, -0.534446, -0.647112, 0.0,
44 | 0.97186, 0.184391, -0.146588, 0.0, 0.707084, 0.485713, -0.513921, 0.0,
45 | 0.942302, 0.331945, 0.043348, 0.0, 0.499084, 0.599922, 0.625307, 0.0,
46 | -0.289203, 0.211107, 0.9337, 0.0, 0.412433, -0.71667, -0.56239, 0.0,
47 | 0.87721, -0.082816, 0.47291, 0.0, -0.420685, -0.214278, 0.881538, 0.0,
48 | 0.752558, -0.0391579, 0.657361, 0.0, 0.0765725, -0.996789, 0.0234082, 0.0,
49 | -0.544312, -0.309435, -0.779727, 0.0, -0.455358, -0.415572, 0.787368, 0.0,
50 | -0.874586, 0.483746, 0.0330131, 0.0, 0.245172, -0.0838623, 0.965846, 0.0,
51 | 0.382293, -0.432813, 0.81641, 0.0, -0.287735, -0.905514, 0.311853, 0.0,
52 | -0.667704, 0.704955, -0.239186, 0.0, 0.717885, -0.464002, -0.518983, 0.0,
53 | 0.976342, -0.214895, 0.0240053, 0.0, -0.0733096, -0.921136, 0.382276, 0.0,
54 | -0.986284, 0.151224, -0.0661379, 0.0, -0.899319, -0.429671, 0.0812908, 0.0,
55 | 0.652102, -0.724625, 0.222893, 0.0, 0.203761, 0.458023, -0.865272, 0.0,
56 | -0.030396, 0.698724, -0.714745, 0.0, -0.460232, 0.839138, 0.289887, 0.0,
57 | -0.0898602, 0.837894, 0.538386, 0.0, -0.731595, 0.0793784, 0.677102, 0.0,
58 | -0.447236, -0.788397, 0.422386, 0.0, 0.186481, 0.645855, -0.740335, 0.0,
59 | -0.259006, 0.935463, 0.240467, 0.0, 0.445839, 0.819655, -0.359712, 0.0,
60 | 0.349962, 0.755022, -0.554499, 0.0, -0.997078, -0.0359577, 0.0673977, 0.0,
61 | -0.431163, -0.147516, -0.890133, 0.0, 0.299648, -0.63914, 0.708316, 0.0,
62 | 0.397043, 0.566526, -0.722084, 0.0, -0.502489, 0.438308, -0.745246, 0.0,
63 | 0.0687235, 0.354097, 0.93268, 0.0, -0.0476651, -0.462597, 0.885286, 0.0,
64 | -0.221934, 0.900739, -0.373383, 0.0, -0.956107, -0.225676, 0.186893, 0.0,
65 | -0.187627, 0.391487, -0.900852, 0.0, -0.224209, -0.315405, 0.92209, 0.0,
66 | -0.730807, -0.537068, 0.421283, 0.0, -0.0353135, -0.816748, 0.575913, 0.0,
67 | -0.941391, 0.176991, -0.287153, 0.0, -0.154174, 0.390458, 0.90762, 0.0,
68 | -0.283847, 0.533842, 0.796519, 0.0, -0.482737, -0.850448, 0.209052, 0.0,
69 | -0.649175, 0.477748, 0.591886, 0.0, 0.885373, -0.405387, -0.227543, 0.0,
70 | -0.147261, 0.181623, -0.972279, 0.0, 0.0959236, -0.115847, -0.988624, 0.0,
71 | -0.89724, -0.191348, 0.397928, 0.0, 0.903553, -0.428461, -0.00350461, 0.0,
72 | 0.849072, -0.295807, -0.437693, 0.0, 0.65551, 0.741754, -0.141804, 0.0,
73 | 0.61598, -0.178669, 0.767232, 0.0, 0.0112967, 0.932256, -0.361623, 0.0,
74 | -0.793031, 0.258012, 0.551845, 0.0, 0.421933, 0.454311, 0.784585, 0.0,
75 | -0.319993, 0.0401618, -0.946568, 0.0, -0.81571, 0.551307, -0.175151, 0.0,
76 | -0.377644, 0.00322313, 0.925945, 0.0, 0.129759, -0.666581, -0.734052, 0.0,
77 | 0.601901, -0.654237, -0.457919, 0.0, -0.927463, -0.0343576, -0.372334, 0.0,
78 | -0.438663, -0.868301, -0.231578, 0.0, -0.648845, -0.749138, -0.133387, 0.0,
79 | 0.507393, -0.588294, 0.629653, 0.0, 0.726958, 0.623665, 0.287358, 0.0,
80 | 0.411159, 0.367614, -0.834151, 0.0, 0.806333, 0.585117, -0.0864016, 0.0,
81 | 0.263935, -0.880876, 0.392932, 0.0, 0.421546, -0.201336, 0.884174, 0.0,
82 | -0.683198, -0.569557, -0.456996, 0.0, -0.117116, -0.0406654, -0.992285, 0.0,
83 | -0.643679, -0.109196, -0.757465, 0.0, -0.561559, -0.62989, 0.536554, 0.0,
84 | 0.0628422, 0.104677, -0.992519, 0.0, 0.480759, -0.2867, -0.828658, 0.0,
85 | -0.228559, -0.228965, -0.946222, 0.0, -0.10194, -0.65706, -0.746914, 0.0,
86 | 0.0689193, -0.678236, 0.731605, 0.0, 0.401019, -0.754026, 0.52022, 0.0,
87 | -0.742141, 0.547083, -0.387203, 0.0, -0.00210603, -0.796417, -0.604745, 0.0,
88 | 0.296725, -0.409909, -0.862513, 0.0, -0.260932, -0.798201, 0.542945, 0.0,
89 | -0.641628, 0.742379, 0.192838, 0.0, -0.186009, -0.101514, 0.97729, 0.0,
90 | 0.106711, -0.962067, 0.251079, 0.0, -0.743499, 0.30988, -0.592607, 0.0,
91 | -0.795853, -0.605066, -0.0226607, 0.0, -0.828661, -0.419471, -0.370628, 0.0,
92 | 0.0847218, -0.489815, -0.8677, 0.0, -0.381405, 0.788019, -0.483276, 0.0,
93 | 0.282042, -0.953394, 0.107205, 0.0, 0.530774, 0.847413, 0.0130696, 0.0,
94 | 0.0515397, 0.922524, 0.382484, 0.0, -0.631467, -0.709046, 0.313852, 0.0,
95 | 0.688248, 0.517273, 0.508668, 0.0, 0.646689, -0.333782, -0.685845, 0.0,
96 | -0.932528, -0.247532, -0.262906, 0.0, 0.630609, 0.68757, -0.359973, 0.0,
97 | 0.577805, -0.394189, 0.714673, 0.0, -0.887833, -0.437301, -0.14325, 0.0,
98 | 0.690982, 0.174003, 0.701617, 0.0, -0.866701, 0.0118182, 0.498689, 0.0,
99 | -0.482876, 0.727143, 0.487949, 0.0, -0.577567, 0.682593, -0.447752, 0.0,
100 | 0.373768, 0.0982991, 0.922299, 0.0, 0.170744, 0.964243, -0.202687, 0.0,
101 | 0.993654, -0.035791, -0.106632, 0.0, 0.587065, 0.4143, -0.695493, 0.0,
102 | -0.396509, 0.26509, -0.878924, 0.0, -0.0866853, 0.83553, -0.542563, 0.0,
103 | 0.923193, 0.133398, -0.360443, 0.0, 0.00379108, -0.258618, 0.965972, 0.0,
104 | 0.239144, 0.245154, -0.939526, 0.0, 0.758731, -0.555871, 0.33961, 0.0,
105 | 0.295355, 0.309513, 0.903862, 0.0, 0.0531222, -0.91003, -0.411124, 0.0,
106 | 0.270452, 0.0229439, -0.96246, 0.0, 0.563634, 0.0324352, 0.825387, 0.0,
107 | 0.156326, 0.147392, 0.976646, 0.0, -0.0410141, 0.981824, 0.185309, 0.0,
108 | -0.385562, -0.576343, -0.720535, 0.0, 0.388281, 0.904441, 0.176702, 0.0,
109 | 0.945561, -0.192859, -0.262146, 0.0, 0.844504, 0.520193, 0.127325, 0.0,
110 | 0.0330893, 0.999121, -0.0257505, 0.0, -0.592616, -0.482475, -0.644999, 0.0,
111 | 0.539471, 0.631024, -0.557476, 0.0, 0.655851, -0.027319, -0.754396, 0.0,
112 | 0.274465, 0.887659, 0.369772, 0.0, -0.123419, 0.975177, -0.183842, 0.0,
113 | -0.223429, 0.708045, 0.66989, 0.0, -0.908654, 0.196302, 0.368528, 0.0,
114 | -0.95759, -0.00863708, 0.288005, 0.0, 0.960535, 0.030592, 0.276472, 0.0,
115 | -0.413146, 0.907537, 0.0754161, 0.0, -0.847992, 0.350849, -0.397259, 0.0,
116 | 0.614736, 0.395841, 0.68221, 0.0, -0.503504, -0.666128, -0.550234, 0.0,
117 | -0.268833, -0.738524, -0.618314, 0.0, 0.792737, -0.60001, -0.107502, 0.0,
118 | -0.637582, 0.508144, -0.579032, 0.0, 0.750105, 0.282165, -0.598101, 0.0,
119 | -0.351199, -0.392294, -0.850155, 0.0, 0.250126, -0.960993, -0.118025, 0.0,
120 | -0.732341, 0.680909, -0.0063274, 0.0, -0.760674, -0.141009, 0.633634, 0.0,
121 | 0.222823, -0.304012, 0.926243, 0.0, 0.209178, 0.505671, 0.836984, 0.0,
122 | 0.757914, -0.56629, -0.323857, 0.0, -0.782926, -0.339196, 0.52151, 0.0,
123 | -0.462952, 0.585565, 0.665424, 0.0, 0.61879, 0.194119, -0.761194, 0.0,
124 | 0.741388, -0.276743, 0.611357, 0.0, 0.707571, 0.702621, 0.0752872, 0.0,
125 | 0.156562, 0.819977, 0.550569, 0.0, -0.793606, 0.440216, 0.42, 0.0,
126 | 0.234547, 0.885309, -0.401517, 0.0, 0.132598, 0.80115, -0.58359, 0.0,
127 | -0.377899, -0.639179, 0.669808, 0.0, -0.865993, -0.396465, 0.304748, 0.0,
128 | -0.624815, -0.44283, 0.643046, 0.0, -0.485705, 0.825614, -0.287146, 0.0,
129 | -0.971788, 0.175535, 0.157529, 0.0, -0.456027, 0.392629, 0.798675, 0.0,
130 | -0.0104443, 0.521623, -0.853112, 0.0, -0.660575, -0.74519, 0.091282, 0.0,
131 | -0.0157698, -0.307475, -0.951425, 0.0, -0.603467, -0.250192, 0.757121, 0.0,
132 | 0.506876, 0.25006, 0.824952, 0.0, 0.255404, 0.966794, 0.00884498, 0.0,
133 | 0.466764, -0.874228, -0.133625, 0.0, 0.475077, -0.0682351, -0.877295, 0.0,
134 | -0.224967, -0.938972, -0.260233, 0.0, -0.377929, -0.814757, -0.439705, 0.0,
135 | -0.305847, 0.542333, -0.782517, 0.0, 0.26658, -0.902905, -0.337191, 0.0,
136 | 0.0275773, 0.322158, -0.946284, 0.0, 0.0185422, 0.716349, 0.697496, 0.0,
137 | -0.20483, 0.978416, 0.0273371, 0.0, -0.898276, 0.373969, 0.230752, 0.0,
138 | -0.00909378, 0.546594, 0.837349, 0.0, 0.6602, -0.751089, 0.000959236, 0.0,
139 | 0.855301, -0.303056, 0.420259, 0.0, 0.797138, 0.0623013, -0.600574, 0.0,
140 | 0.48947, -0.866813, 0.0951509, 0.0, 0.251142, 0.674531, 0.694216, 0.0,
141 | -0.578422, -0.737373, -0.348867, 0.0, -0.254689, -0.514807, 0.818601, 0.0,
142 | 0.374972, 0.761612, 0.528529, 0.0, 0.640303, -0.734271, -0.225517, 0.0,
143 | -0.638076, 0.285527, 0.715075, 0.0, 0.772956, -0.15984, -0.613995, 0.0,
144 | 0.798217, -0.590628, 0.118356, 0.0, -0.986276, -0.0578337, -0.154644, 0.0,
145 | -0.312988, -0.94549, 0.0899272, 0.0, -0.497338, 0.178325, 0.849032, 0.0,
146 | -0.101136, -0.981014, 0.165477, 0.0, -0.521688, 0.0553434, -0.851339, 0.0,
147 | -0.786182, -0.583814, 0.202678, 0.0, -0.565191, 0.821858, -0.0714658, 0.0,
148 | 0.437895, 0.152598, -0.885981, 0.0, -0.92394, 0.353436, -0.14635, 0.0,
149 | 0.212189, -0.815162, -0.538969, 0.0, -0.859262, 0.143405, -0.491024, 0.0,
150 | 0.991353, 0.112814, 0.0670273, 0.0, 0.0337884, -0.979891, -0.196654, 0.0
151 | ];
152 |
153 | static public inline function GradientCoherentNoise3D(x : Float, y : Float, z : Float, seed : Int, quality : QualityMode) : Float {
154 |
155 | var x0 = x > 0.0 ? Std.int(x) : Std.int(x) - 1;
156 | var x1 = x0 + 1;
157 | var y0 = y > 0.0 ? Std.int(y) : Std.int(y) - 1;
158 | var y1 = y0 + 1;
159 | var z0 = z > 0.0 ? Std.int(z) : Std.int(z) - 1;
160 | var z1 = z0 + 1;
161 | var xs = 0.0;
162 | var ys = 0.0;
163 | var zs = 0.0;
164 |
165 | switch(quality){
166 | case LOW:
167 | xs = x - x0;
168 | ys = y - y0;
169 | zs = z - z0;
170 | case MEDIUM:
171 | xs = MapCubicSCurve(x - x0);
172 | ys = MapCubicSCurve(y - y0);
173 | zs = MapCubicSCurve(z - z0);
174 | case HIGH:
175 | xs = MapQuinticSCurve(x - x0);
176 | ys = MapQuinticSCurve(y - y0);
177 | zs = MapQuinticSCurve(z - z0);
178 | }
179 | var n0 = GradientNoise3D(x, y, z, x0, y0, z0, seed);
180 | var n1 = GradientNoise3D(x, y, z, x1, y0, z0, seed);
181 | var ix0 = InterpolateLinear(n0, n1, xs);
182 | n0 = GradientNoise3D(x, y, z, x0, y1, z0, seed);
183 | n1 = GradientNoise3D(x, y, z, x1, y1, z0, seed);
184 | var ix1 = InterpolateLinear(n0, n1, xs);
185 | var iy0 = InterpolateLinear(ix0, ix1, ys);
186 | n0 = GradientNoise3D(x, y, z, x0, y0, z1, seed);
187 | n1 = GradientNoise3D(x, y, z, x1, y0, z1, seed);
188 | ix0 = InterpolateLinear(n0, n1, xs);
189 | n0 = GradientNoise3D(x, y, z, x0, y1, z1, seed);
190 | n1 = GradientNoise3D(x, y, z, x1, y1, z1, seed);
191 | ix1 = InterpolateLinear(n0, n1, xs);
192 | var iy1 = InterpolateLinear(ix0, ix1, ys);
193 | return InterpolateLinear(iy0, iy1, zs);
194 | }
195 |
196 | static public inline function GradientNoise3D(fx : Float, fy : Float, fz : Float, ix : Int, iy : Int, iz : Int, seed : Int) {
197 | var i = (GeneratorNoiseX * ix + GeneratorNoiseY * iy + GeneratorNoiseZ * iz +
198 | GeneratorSeed * seed) & 0xffffffff;
199 | i ^= (i >> GeneratorShift);
200 | i &= 0xff;
201 | var xvg = Randoms[(i << 2)];
202 | var yvg = Randoms[(i << 2) + 1];
203 | var zvg = Randoms[(i << 2) + 2];
204 | var xvp = (fx - ix);
205 | var yvp = (fy - iy);
206 | var zvp = (fz - iz);
207 | return ((xvg * xvp) + (yvg * yvp) + (zvg * zvp)) * 2.12;
208 | }
209 |
210 | static public inline function InterpolateCubic(a : Float, b : Float, c : Float, d : Float, position : Float) {
211 | var p = (d - c) - (a - b);
212 | var q = (a - b) - p;
213 | var r = c - a;
214 | var s = b;
215 | return p * position * position * position + q * position * position + r * position + s;
216 | }
217 |
218 | static public inline function InterpolateLinear(a : Float, b : Float, position : Float) {
219 | return ((1.0 - position) * a) + (position * b);
220 | }
221 |
222 |
223 | static inline function fmod(a : Float, b : Float) : Float {
224 | return a - Std.int(a / b) * b;
225 | }
226 |
227 | static public inline function MakeInt32Range(value : Float) {
228 | if (value >= 1073741824.0) {
229 | return (2.0 * fmod(value, 1073741824.0)) - 1073741824.0;
230 | }
231 | if (value <= -1073741824.0) {
232 | return (2.0 * fmod(value, 1073741824.0)) + 1073741824.0;
233 | }
234 | return value;
235 | }
236 |
237 | static public inline function MapCubicSCurve(value : Float) : Float {
238 | return value * value * (3.0 - 2.0 * value);
239 | }
240 |
241 | static public inline function MapQuinticSCurve(value : Float) : Float {
242 | var a3 = value * value * value;
243 | var a4 = a3 * value;
244 | var a5 = a4 * value;
245 | return (6.0 * a5) - (15.0 * a4) + (10.0 * a3);
246 | }
247 |
248 | static public inline function ValueNoise3D(x : Int, y : Int, z : Int, seed : Int) : Float {
249 | return 1.0 - (ValueNoise3DInt(x, y, z, seed) / 1073741824.0);
250 | }
251 |
252 | static public function ValueNoise3DInt(x : Int, y : Int, z : Int, seed : Int) : Int {
253 | var n = (GeneratorNoiseX * x + GeneratorNoiseY * y + GeneratorNoiseZ * z + GeneratorSeed * seed ) & 0x7fffffff;
254 | n = (n >> 13 ) ^ n;
255 | return (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff;
256 | }
257 |
258 | static public inline function Clamp(value : Int, min : Int, max : Int) {
259 | return value < min ? min : value > max ? max : value;
260 | }
261 |
262 | static public inline function Clampf(value : Float, min : Float, max : Float) {
263 | return value < min ? min : value > max ? max : value;
264 | }
265 | }
266 |
--------------------------------------------------------------------------------
/Sources/libnoise/builder/NoiseMap.hx:
--------------------------------------------------------------------------------
1 | package libnoise.builder;
2 |
3 | /// Implements a noise map, a 2-dimensional array of floating-point
4 | /// values.
5 | ///
6 | /// A noise map is designed to store coherent-noise values generated by a
7 | /// noise module, although it can store values from any source. A noise
8 | /// map is often used as a terrain height map or a grayscale texture.
9 | ///
10 | /// The size (width and height) of the noise map can be specified during
11 | /// object construction or at any other time.
12 | ///
13 | /// The GetValue() and SetValue() methods can be used to access individual
14 | /// values stored in the noise map.
15 | ///
16 | /// Border Values
17 | ///
18 | /// All of the values outside of the noise map are assumed to have a
19 | /// common value known as the border value.
20 | ///
21 | /// The GetValue() method returns the border value if the specified value
22 | /// lies outside of the noise map.
23 | class NoiseMap{
24 |
25 | /// The current width of the noise map.
26 | @:isVar public var width : Int;
27 |
28 | /// The current height of the noise map.
29 | @:isVar public var height : Int;
30 |
31 | /// Value used for all positions outside of the noise map.
32 | @:isVar public var borderValue : Float = 0;
33 |
34 | private var values : Array = [];
35 |
36 | public function new(width : Int, height : Int) {
37 | this.width = width;
38 | this.height = height;
39 | }
40 |
41 | /// Sets a value at a specified position in the noise map.
42 | ///
43 | /// @param x The x coordinate of the position.
44 | /// @param y The y coordinate of the position.
45 | /// @param value The value to set at the given position.
46 | ///
47 | /// This method does nothing if the noise map object is empty or the
48 | /// position is outside the bounds of the noise map.
49 | public inline function setValue (x : Int, y : Int, value : Float){
50 | if(x >= 0 && x <= width && y >= 0 && y <= height)
51 | values[x + width * y] = value;
52 | }
53 |
54 | /// Returns a value from the specified position in the noise map.
55 | ///
56 | /// @param x The x coordinate of the position.
57 | /// @param y The y coordinate of the position.
58 | ///
59 | /// @returns The value at that position.
60 | ///
61 | /// This method returns the border value if the coordinates exist
62 | /// outside of the noise map.
63 | public inline function getValue (x : Int, y : Int){
64 | if(x >= 0 && x <= width && y >= 0 && y <= height)
65 | return values[x + width * y];
66 | return borderValue;
67 | }
68 | }
--------------------------------------------------------------------------------
/Sources/libnoise/builder/NoiseMapBuilder.hx:
--------------------------------------------------------------------------------
1 | package libnoise.builder;
2 |
3 | /**
4 | Abstract base class for a noise-map builder
5 |
6 | A builder class builds a noise map by filling it with coherent-noise
7 | values generated from the surface of a three-dimensional mathematical
8 | object. Each builder class defines a specific three-dimensional
9 | surface, such as a cylinder, sphere, or plane.
10 |
11 | A builder class describes these input values using a coordinate system
12 | applicable for the mathematical object (e.g., a latitude/longitude
13 | coordinate system for the spherical noise-map builder.) It then
14 | "flattens" these coordinates onto a plane so that it can write the
15 | coherent-noise values into a two-dimensional noise map.
16 |
17 | Building the Noise Map
18 |
19 | To build the noise map, perform the following steps:
20 | - Pass the bounding coordinates to the SetBounds() method.
21 | - Pass the noise map size, in points, to the SetDestSize() method.
22 | - Pass a NoiseMap object to the SetDestNoiseMap() method.
23 | - Pass a noise module (derived from noise::module::Module) to the
24 | SetSourceModule() method.
25 | - Call the Build() method.
26 |
27 | You may also pass a callback function to the SetCallback() method.
28 | The Build() method calls this callback function each time it fills a
29 | row of the noise map with coherent-noise values. This callback
30 | function has a single integer parameter that contains a count of the
31 | rows that have been completed. It returns void.
32 |
33 | Note that SetBounds() is not defined in the abstract base class; it is
34 | only defined in the derived classes. This is because each model uses
35 | a different coordinate system.
36 | **/
37 | class NoiseMapBuilder{
38 |
39 | /// The height of the destination noise map, in points.
40 | ///
41 | /// This object does not change the height in the destination noise
42 | /// map object until the Build() method is called.
43 | @:isVar public var destHeight : Int;
44 |
45 | /// The height of the destination noise map, in points.
46 | ///
47 | /// This object does not change the height in the destination noise
48 | /// map object until the Build() method is called.
49 | @:isVar public var destWidth : Int;
50 |
51 | /// The destination noise map will contain the coherent-noise values
52 | /// from this noise map after a successful call to the Build() method.
53 | ///
54 | /// The destination noise map must exist throughout the lifetime of
55 | /// this object unless another noise map replaces that noise map.
56 | @:isVar public var destNoiseMap : NoiseMap;
57 |
58 | /// This object fills in a noise map with the coherent-noise values
59 | /// from this source module.
60 | ///
61 | /// The source module must exist throughout the lifetime of this
62 | /// object unless another noise module replaces that noise module.
63 | @:isVar public var sourceModule : ModuleBase;
64 |
65 | /// The callback function that Build() calls each time it fills a row
66 | /// of the noise map with coherent-noise values.
67 | ///
68 | /// This callback function has a single integer parameter that
69 | /// contains a count of the rows that have been completed.
70 | @:isVar public var callback : Int -> Void;
71 |
72 | public function new() {}
73 |
74 | /// Builds the noise map.
75 | ///
76 | /// @pre SetBounds() was previously called.
77 | /// @pre SetDestNoiseMap() was previously called.
78 | /// @pre SetSourceModule() was previously called.
79 | /// @pre The width and height values specified by SetDestSize() are
80 | /// positive.
81 | /// @pre The width and height values specified by SetDestSize() do not
82 | /// exceed the maximum possible width and height for the noise map.
83 | ///
84 | /// @post The original contents of the destination noise map is
85 | /// destroyed.
86 | ///
87 | /// @throw noise::ExceptionInvalidParam See the preconditions.
88 | /// @throw noise::ExceptionOutOfMemory Out of memory.
89 | ///
90 | /// If this method is successful, the destination noise map contains
91 | /// the coherent-noise values from the noise module specified by
92 | /// SetSourceModule().
93 | public function build():Void {
94 | throw "NoiseMapBuilder.build is abstract";
95 | }
96 |
97 | public function setDestSize(width : Int, heigth : Int):Void {
98 | destWidth = width;
99 | destHeight = heigth;
100 | }
101 | }
--------------------------------------------------------------------------------
/Sources/libnoise/builder/NoiseMapBuilderCylinder.hx:
--------------------------------------------------------------------------------
1 | package libnoise.builder;
2 |
3 | /// Builds a cylindrical noise map.
4 | ///
5 | /// This class builds a noise map by filling it with coherent-noise values
6 | /// generated from the surface of a cylinder.
7 | ///
8 | /// This class describes these input values using an (angle, height)
9 | /// coordinate system. After generating the coherent-noise value from the
10 | /// input value, it then "flattens" these coordinates onto a plane so that
11 | /// it can write the values into a two-dimensional noise map.
12 | ///
13 | /// The cylinder model has a radius of 1.0 unit and has infinite height.
14 | /// The cylinder is oriented along the @a y axis. Its center is at the
15 | /// origin.
16 | ///
17 | /// The x coordinate in the noise map represents the angle around the
18 | /// cylinder's y axis. The y coordinate in the noise map represents the
19 | /// height above the x-z plane.
20 | ///
21 | /// The application must provide the lower and upper angle bounds of the
22 | /// noise map, in degrees, and the lower and upper height bounds of the
23 | /// noise map, in units.
24 | import libnoise.model.Cylinder;
25 | class NoiseMapBuilderCylinder extends NoiseMapBuilder{
26 |
27 | /// Lower angle boundary of the cylindrical noise map, in degrees.
28 | @:isVar public var lowerAngleBound : Float;
29 |
30 | /// Lower height boundary of the cylindrical noise map, in units.
31 | @:isVar public var lowerHeightBound : Float;
32 |
33 | /// Upper angle boundary of the cylindrical noise map, in degrees.
34 | @:isVar public var upperAngleBound : Float;
35 |
36 | /// Upper height boundary of the cylindrical noise map, in units.
37 | @:isVar public var upperHeightBound : Float;
38 |
39 | public function new() { super(); }
40 |
41 | public function setBounds(lowerAngleBound:Float, upperAngleBound:Float, lowerHeightBound:Float, upperHeightBound:Float):Void {
42 | if(lowerAngleBound >= upperAngleBound || lowerHeightBound >= upperHeightBound)
43 | throw 'Invalid parameter';
44 | this.lowerHeightBound = lowerHeightBound;
45 | this.lowerAngleBound = lowerAngleBound;
46 | this.upperHeightBound = upperHeightBound;
47 | this.upperAngleBound = upperAngleBound;
48 | }
49 |
50 | override public function build():Void {
51 | if ( upperAngleBound <= lowerAngleBound
52 | || upperHeightBound <= lowerHeightBound
53 | || destWidth <= 0
54 | || destHeight <= 0
55 | || sourceModule == null
56 | || destNoiseMap == null)
57 | throw 'Invalid parameter';
58 |
59 | var cylinder : Cylinder = new Cylinder(sourceModule);
60 |
61 | var angleExtent = upperAngleBound - lowerAngleBound;
62 | var heightExtent = upperHeightBound - lowerHeightBound;
63 | var xDelta : Float = angleExtent / destWidth;
64 | var yDelta : Float = heightExtent / destHeight;
65 | var curAngle = lowerAngleBound;
66 | var curHeight = lowerHeightBound;
67 |
68 | for(y in 0...destHeight){
69 | curAngle = lowerAngleBound;
70 | for(x in 0...destWidth){
71 | var curValue = cylinder.getValue(curAngle, curHeight);
72 | this.destNoiseMap.setValue(x,y,curValue);
73 | curAngle += xDelta;
74 | }
75 | curHeight += yDelta;
76 | if(callback != null)
77 | callback(y);
78 | }
79 | }
80 | }
--------------------------------------------------------------------------------
/Sources/libnoise/builder/NoiseMapBuilderPlane.hx:
--------------------------------------------------------------------------------
1 | package libnoise.builder;
2 |
3 | /// Builds a planar noise map.
4 | ///
5 | /// This class builds a noise map by filling it with coherent-noise values
6 | /// generated from the surface of a plane.
7 | ///
8 | /// This class describes these input values using (x, z) coordinates.
9 | /// Their y coordinates are always 0.0.
10 | ///
11 | /// The application must provide the lower and upper x coordinate bounds
12 | /// of the noise map, in units, and the lower and upper z coordinate
13 | /// bounds of the noise map, in units.
14 | ///
15 | /// To make a tileable noise map with no seams at the edges, call the
16 | /// EnableSeamless() method.
17 | import libnoise.Utils;
18 | import libnoise.model.Plane;
19 | class NoiseMapBuilderPlane extends NoiseMapBuilder{
20 |
21 | /// Lower x boundary of the planar noise map, in units.
22 | @:isVar public var lowerXBound : Float;
23 |
24 | /// Lower z boundary of the planar noise map, in units.
25 | @:isVar public var lowerZBound : Float;
26 |
27 | /// Upper x boundary of the planar noise map, in units.
28 | @:isVar public var upperXBound : Float;
29 |
30 | /// Upper z boundary of the planar noise map, in units.
31 | @:isVar public var upperZBound : Float;
32 |
33 | /// A flag specifying whether seamless tiling is enabled.
34 | @:isVar public var isSeamlessEnabled : Bool;
35 |
36 | public function new() { super(); }
37 |
38 | /// Sets the boundaries of the planar noise map.
39 | ///
40 | /// @param lowerXBound The lower x boundary of the noise map, in
41 | /// units.
42 | /// @param upperXBound The upper x boundary of the noise map, in
43 | /// units.
44 | /// @param lowerZBound The lower z boundary of the noise map, in
45 | /// units.
46 | /// @param upperZBound The upper z boundary of the noise map, in
47 | /// units.
48 | ///
49 | /// @pre The lower x boundary is less than the upper x boundary.
50 | /// @pre The lower z boundary is less than the upper z boundary.
51 | public function setBounds(lowerXBound:Float, lowerZBound:Float, upperXBound:Float, upperZBound:Float):Void {
52 | if(lowerXBound >= upperXBound || lowerZBound >= upperZBound)
53 | throw 'Invalid parameter';
54 | this.lowerZBound = lowerZBound;
55 | this.lowerXBound = lowerXBound;
56 | this.upperZBound = upperZBound;
57 | this.upperXBound = upperXBound;
58 | }
59 |
60 | override public function build():Void {
61 | if ( upperXBound <= lowerXBound
62 | || upperZBound <= lowerZBound
63 | || destWidth <= 0
64 | || destHeight <= 0
65 | || sourceModule == null
66 | || destNoiseMap == null)
67 | throw 'Invalid parameter';
68 |
69 | var plane : Plane = new Plane(sourceModule);
70 |
71 | var xExtent = upperXBound - lowerXBound;
72 | var zExtent = upperZBound - lowerZBound;
73 | var xDelta : Float = xExtent / destWidth;
74 | var zDelta : Float = zExtent / destHeight;
75 | var xCur = lowerXBound;
76 | var zCur = lowerZBound;
77 |
78 | for(z in 0...destHeight){
79 | xCur = lowerXBound;
80 | for(x in 0...destWidth){
81 | var curValue : Float;
82 | if(!isSeamlessEnabled)
83 | curValue = plane.getValue(x, z);
84 | else{
85 | var swValue = plane.getValue (xCur , zCur );
86 | var seValue = plane.getValue (xCur + xExtent, zCur );
87 | var nwValue = plane.getValue (xCur , zCur + zExtent);
88 | var neValue = plane.getValue (xCur + xExtent, zCur + zExtent);
89 | var xBlend = 1.0 - ((xCur - lowerXBound) / xExtent);
90 | var zBlend = 1.0 - ((zCur - lowerZBound) / zExtent);
91 | var z0 = Utils.InterpolateLinear(swValue, seValue, xBlend);
92 | var z1 = Utils.InterpolateLinear(nwValue, neValue, xBlend);
93 | curValue = Utils.InterpolateLinear(z0, z1, zBlend);
94 | }
95 | this.destNoiseMap.setValue(x,z,curValue);
96 | xCur += xDelta;
97 | }
98 | zCur += zDelta;
99 | if(callback != null)
100 | callback(z);
101 | }
102 | }
103 | }
--------------------------------------------------------------------------------
/Sources/libnoise/builder/NoiseMapBuilderSphere.hx:
--------------------------------------------------------------------------------
1 | package libnoise.builder;
2 |
3 | /**
4 | Builds a spherical noise map.
5 |
6 | This class builds a noise map by filling it with coherent-noise values
7 | generated from the surface of a sphere.
8 |
9 | This class describes these input values using a (latitude, longitude)
10 | coordinate system. After generating the coherent-noise value from the
11 | input value, it then "flattens" these coordinates onto a plane so that
12 | it can write the values into a two-dimensional noise map.
13 |
14 | The sphere model has a radius of 1.0 unit. Its center is at the
15 | origin.
16 |
17 | The x coordinate in the noise map represents the longitude. The y
18 | coordinate in the noise map represents the latitude.
19 |
20 | The application must provide the southern, northern, western, and
21 | eastern bounds of the noise map, in degrees.
22 | **/
23 | import libnoise.model.Sphere;
24 | class NoiseMapBuilderSphere extends NoiseMapBuilder{
25 |
26 | /// Eastern boundary of the spherical noise map, in degrees.
27 | @:isVar public var eastLonBound : Float;
28 |
29 | /// Northern boundary of the spherical noise map, in degrees.
30 | @:isVar public var northLatBound : Float;
31 |
32 | /// Southern boundary of the spherical noise map, in degrees.
33 | @:isVar public var southLatBound : Float;
34 |
35 | /// Western boundary of the spherical noise map, in degrees.
36 | @:isVar public var westLonBound : Float;
37 |
38 | public function new() { super(); }
39 |
40 | /**
41 | Sets the coordinate boundaries of the noise map.
42 |
43 | @param southLatBound The southern boundary of the noise map, in
44 | degrees.
45 | @param northLatBound The northern boundary of the noise map, in
46 | degrees.
47 | @param westLonBound The western boundary of the noise map, in
48 | degrees.
49 | @param eastLonBound The eastern boundary of the noise map, in
50 | degrees.
51 |
52 | @pre The southern boundary is less than the northern boundary.
53 | @pre The western boundary is less than the eastern boundary.
54 | **/
55 | public function setBounds (southLatBound : Float, northLatBound : Float, westLonBound : Float, eastLonBound : Float)
56 | {
57 | if (southLatBound >= northLatBound
58 | || westLonBound >= eastLonBound) {
59 | throw 'Invalid parameter';
60 | }
61 |
62 | this.southLatBound = southLatBound;
63 | this.northLatBound = northLatBound;
64 | this.westLonBound = westLonBound ;
65 | this.eastLonBound = eastLonBound ;
66 | }
67 |
68 | override public function build():Void {
69 | if ( eastLonBound <= westLonBound
70 | || northLatBound <= southLatBound
71 | || destWidth <= 0
72 | || destHeight <= 0
73 | || sourceModule == null
74 | || destNoiseMap == null)
75 | throw 'Invalid parameter';
76 |
77 | var sphere : Sphere = new Sphere(sourceModule);
78 |
79 | var lonExtent = eastLonBound - westLonBound;
80 | var latExtent = northLatBound - southLatBound;
81 | var xDelta : Float = lonExtent / destWidth;
82 | var yDelta : Float = latExtent / destHeight;
83 | var curLon = westLonBound;
84 | var curLat = southLatBound;
85 |
86 | for(y in 0...destHeight){
87 | curLon = westLonBound;
88 | for(x in 0...destWidth){
89 | var curValue = sphere.getValue(curLat, curLon);
90 | this.destNoiseMap.setValue(x,y,curValue);
91 | curLon += xDelta;
92 | }
93 | curLat += yDelta;
94 | if(callback != null)
95 | callback(y);
96 | }
97 | }
98 | }
--------------------------------------------------------------------------------
/Sources/libnoise/generator/Billow.hx:
--------------------------------------------------------------------------------
1 | package libnoise.generator;
2 |
3 | class Billow extends ModuleBase {
4 |
5 | @range()
6 | public var frequency : Float;
7 | public var lacunarity : Float;
8 | public var persistence : Float;
9 | public var octaves : Int;
10 | public var seed : Int;
11 | public var quality : QualityMode;
12 |
13 | public function new(frequency : Float, lacunarity : Float, persistence : Float, octaves : Int, seed : Int, quality : QualityMode) {
14 | this.frequency = frequency;
15 | this.lacunarity = lacunarity;
16 | this.persistence = persistence;
17 | this.octaves = octaves;
18 | this.seed = seed;
19 | this.quality = quality;
20 | super(0);
21 | }
22 |
23 | override public function getValue(x : Float, y : Float, z : Float) : Float {
24 | var value = 0.0;
25 | var curp = 1.0;
26 | x *= frequency;
27 | y *= frequency;
28 | z *= frequency;
29 | for (i in 0...octaves) {
30 | var nx = Utils.MakeInt32Range(x);
31 | var ny = Utils.MakeInt32Range(y);
32 | var nz = Utils.MakeInt32Range(z);
33 | var _seed = (seed + i) & 0xffffffff;
34 | var signal = Utils.GradientCoherentNoise3D(nx, ny, nz, _seed, quality);
35 | signal = 2.0 * Math.abs(signal) - 1.0;
36 | value += signal * curp;
37 | x *= lacunarity;
38 | y *= lacunarity;
39 | z *= lacunarity;
40 | curp *= persistence;
41 | }
42 | return value + 0.5;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Sources/libnoise/generator/Checker.hx:
--------------------------------------------------------------------------------
1 | package libnoise.generator;
2 |
3 | class Checker extends ModuleBase {
4 |
5 | public function new() {
6 | super(0);
7 | }
8 |
9 | override public function getValue(x : Float, y : Float, z : Float) : Float{
10 | var ix = Std.int(Math.floor(Utils.MakeInt32Range(x)));
11 | var iy = Std.int(Math.floor(Utils.MakeInt32Range(y)));
12 | var iz = Std.int(Math.floor(Utils.MakeInt32Range(z)));
13 | return (ix & 1 ^ iy & 1 ^ iz & 1) != 0 ? -1.0 : 1.0;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Sources/libnoise/generator/Const.hx:
--------------------------------------------------------------------------------
1 | package libnoise.generator;
2 |
3 | class Const extends ModuleBase{
4 |
5 | var value : Int;
6 |
7 | public function new(value : Int) {
8 | super(0);
9 | this.value = value;
10 | }
11 |
12 | override public function getValue(x : Float, y : Float, z : Float) : Float{
13 | return value;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Sources/libnoise/generator/Cylinder.hx:
--------------------------------------------------------------------------------
1 | package libnoise.generator;
2 |
3 | class Cylinder extends ModuleBase{
4 | var frequency = 1.0;
5 |
6 | public function new(frequency : Float) {
7 | super(0);
8 | this.frequency = frequency;
9 | }
10 |
11 | override public function getValue(x : Float, y : Float, z : Float) : Float{
12 | x *= frequency;
13 | z *= frequency;
14 | var dfc = Math.sqrt(x * x + z * z);
15 | var dfss = dfc - Math.floor(dfc);
16 | var dfls = 1.0 - dfss;
17 | var nd = Math.min(dfss, dfls);
18 | return 1.0 - (nd * 4.0);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Sources/libnoise/generator/Perlin.hx:
--------------------------------------------------------------------------------
1 | package libnoise.generator;
2 |
3 | class Perlin extends ModuleBase {
4 |
5 | public var frequency : Float;
6 | public var lacunarity : Float;
7 | public var persistence : Float;
8 | public var octaves : Int;
9 | public var seed : Int;
10 | public var quality : QualityMode;
11 |
12 | public function new(frequency : Float, lacunarity : Float, persistence : Float, octaves : Int, seed : Int, quality : QualityMode) {
13 | this.frequency = frequency;
14 | this.lacunarity = lacunarity;
15 | this.persistence = persistence;
16 | this.octaves = octaves;
17 | this.seed = seed;
18 | this.quality = quality;
19 | super(0);
20 | }
21 |
22 | override public function getValue(x : Float, y : Float, z : Float) : Float {
23 | var value = 0.0;
24 | var cp = 1.0;
25 | x *= frequency;
26 | y *= frequency;
27 | z *= frequency;
28 |
29 | for(i in 0...octaves){
30 | var nx = Utils.MakeInt32Range(x);
31 | var ny = Utils.MakeInt32Range(y);
32 | var nz = Utils.MakeInt32Range(z);
33 | var _seed = (seed + i) & 0xffffffff;
34 | var signal = Utils.GradientCoherentNoise3D(nx, ny, nz, _seed, quality);
35 | value += signal * cp;
36 | x *= lacunarity;
37 | y *= lacunarity;
38 | z *= lacunarity;
39 | cp *= persistence;
40 | }
41 | return value;
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/Sources/libnoise/generator/RidgedMultifractal.hx:
--------------------------------------------------------------------------------
1 | package libnoise.generator;
2 |
3 | class RidgedMultifractal extends ModuleBase{
4 |
5 | var weights : Array = new Array();
6 | public var frequency : Float;
7 | public var lacunarity : Float;
8 | public var persistence : Float;
9 | public var octaves : Int;
10 | public var seed : Int;
11 | public var quality : QualityMode;
12 |
13 | public function new(frequency : Float, lacunarity : Float, octaves : Int, seed : Int, quality : QualityMode) {
14 | this.frequency = frequency;
15 | this.lacunarity = lacunarity;
16 | this.octaves = octaves;
17 | this.seed = seed;
18 | this.quality = quality;
19 | updateWeights();
20 | super(0);
21 | }
22 |
23 | override public function getValue(x : Float, y : Float, z : Float) : Float {
24 | x *= frequency;
25 | y *= frequency;
26 | z *= frequency;
27 | var value = 0.0;
28 | var weight = 1.0;
29 | var offset = 1.0;
30 | var gain = 2.0;
31 | for (i in 0...octaves) {
32 | var nx = Utils.MakeInt32Range(x);
33 | var ny = Utils.MakeInt32Range(y);
34 | var nz = Utils.MakeInt32Range(z);
35 | var _seed : Int = (seed + i) & 0x7fffffff;
36 | var signal = Utils.GradientCoherentNoise3D(nx, ny, nz, _seed, quality);
37 | signal = Math.abs(signal);
38 | signal = offset - signal;
39 | signal *= signal;
40 | signal *= weight;
41 | weight = signal * gain;
42 | weight = weight > 1.0 ? 1.0 : weight < 0 ? 0 : weight;
43 | value += (signal * weights[i]);
44 | x *= lacunarity;
45 | y *= lacunarity;
46 | z *= lacunarity;
47 | }
48 | return (value * 1.25) - 1.0;
49 | }
50 |
51 | function updateWeights(){
52 | var f = 1.0;
53 | for (i in 0...(Utils.OctavesMaximum))
54 | {
55 | weights.push(Math.pow(f, -1.0));
56 | f *= lacunarity;
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/Sources/libnoise/generator/Sphere.hx:
--------------------------------------------------------------------------------
1 | package libnoise.generator;
2 |
3 | class Sphere extends ModuleBase{
4 |
5 | var frequency = 1.0;
6 |
7 | public function new(frequency : Float) {
8 | super(0);
9 | this.frequency = frequency;
10 | }
11 |
12 | override public function getValue(x : Float, y : Float, z : Float) : Float{
13 | x *= frequency;
14 | y *= frequency;
15 | z *= frequency;
16 | var dfc = Math.sqrt(x * x + y * y + z * z);
17 | var dfss = dfc - Math.floor(dfc);
18 | var dfls = 1.0 - dfss;
19 | var nd = Math.min(dfss, dfls);
20 | return 1.0 - (nd * 4.0);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Sources/libnoise/generator/Voronoi.hx:
--------------------------------------------------------------------------------
1 | package libnoise.generator;
2 |
3 | class Voronoi extends ModuleBase {
4 |
5 | var frequency : Float;
6 | var displacement : Float;
7 | var seed : Int;
8 | var distance : Bool;
9 |
10 | public function new(frequency : Float, displacement : Float, seed : Int, distance : Bool) {
11 | this.frequency = frequency;
12 | this.displacement = displacement;
13 | this.seed = seed;
14 | this.distance = distance;
15 | super(0);
16 | }
17 |
18 | override public function getValue(x : Float, y : Float, z : Float) : Float {
19 | x *= frequency;
20 | y *= frequency;
21 | z *= frequency;
22 | var xi = (x > 0.0 ? Std.int(x) : Std.int(x - 1));
23 | var iy = (y > 0.0 ? Std.int(y) : Std.int(y - 1));
24 | var iz = (z > 0.0 ? Std.int(z) : Std.int(z - 1));
25 | var md = 2147483647.0;
26 | var xc : Float = 0;
27 | var yc : Float = 0;
28 | var zc : Float = 0;
29 | for (zcu in (iz - 2)...(iz + 3)) {
30 | for (ycu in (iy - 2)...(iy + 3)) {
31 | for (xcu in (xi - 2)...(xi + 3)) {
32 | var xp = xcu + Utils.ValueNoise3D(xcu, ycu, zcu, seed);
33 | var yp = ycu + Utils.ValueNoise3D(xcu, ycu, zcu, seed + 1);
34 | var zp = zcu + Utils.ValueNoise3D(xcu, ycu, zcu, seed + 2);
35 | var xd = xp - x;
36 | var yd = yp - y;
37 | var zd = zp - z;
38 | var d = xd * xd + yd * yd + zd * zd;
39 | if (d < md) {
40 | md = d;
41 | xc = xp;
42 | yc = yp;
43 | zc = zp;
44 | }
45 | }
46 | }
47 | }
48 | var v : Float;
49 | if (distance) {
50 | var xd = xc - x;
51 | var yd = yc - y;
52 | var zd = zc - z;
53 | v = (Math.sqrt(xd * xd + yd * yd + zd * zd)) * Utils.SQRT3 - 1.0;
54 | }
55 | else {
56 | v = 0.0;
57 | }
58 | return v + (displacement * Utils.ValueNoise3D(Std.int(Math.floor(xc)), Std.int(Math.floor(yc)),
59 | Std.int(Math.floor(zc)), 0));
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/Sources/libnoise/model/Cylinder.hx:
--------------------------------------------------------------------------------
1 | package libnoise.model;
2 |
3 | class Cylinder{
4 |
5 | @:isVar public var module : ModuleBase;
6 |
7 | public inline function new(sourceModule : ModuleBase){ this.module = sourceModule; }
8 |
9 | /// Returns the output value from the noise module given the
10 | /// (angle, height) coordinates of the specified input value located
11 | /// on the surface of the cylinder.
12 | ///
13 | /// @param angle The angle around the cylinder's center, in degrees.
14 | /// @param height The height along the @a y axis.
15 | ///
16 | /// @returns The output value from the noise module.
17 | ///
18 | /// This cylinder has a radius of 1.0 unit and has infinite height.
19 | /// It is oriented along the @a y axis. Its center is located at the
20 | /// origin.
21 | public inline function getValue(angle:Float, height:Float):Float {
22 | var x = Math.cos(angle * 0.017);
23 | var y = height;
24 | var z = Math.sin(angle * 0.017);
25 | return module.getValue(x,y,z);
26 | }
27 | }
--------------------------------------------------------------------------------
/Sources/libnoise/model/Plane.hx:
--------------------------------------------------------------------------------
1 | package libnoise.model;
2 |
3 | class Plane{
4 |
5 | @:isVar public var module : ModuleBase;
6 |
7 | public inline function new(sourceModule : ModuleBase){ this.module = sourceModule; }
8 |
9 | /**
10 | Returns the output value from the noise module given the
11 | ( @a x, @a z ) coordinates of the specified input value located
12 | on the surface of the plane.
13 |
14 | @param x The @a x coordinate of the input value.
15 | @param z The @a z coordinate of the input value.
16 |
17 | @returns The output value from the noise module.
18 | **/
19 | public inline function getValue(x : Float, z : Float):Float {
20 | return module.getValue(x,0,z);
21 | }
22 | }
--------------------------------------------------------------------------------
/Sources/libnoise/model/Sphere.hx:
--------------------------------------------------------------------------------
1 | package libnoise.model;
2 |
3 | class Sphere{
4 |
5 | @:isVar public var module : ModuleBase;
6 |
7 | public inline function new(sourceModule : ModuleBase){ this.module = sourceModule; }
8 |
9 | /**
10 | Returns the output value from the noise module given the
11 | (latitude, longitude) coordinates of the specified input value
12 | located on the surface of the sphere.
13 |
14 | @param lat The latitude of the input value, in degrees.
15 | @param lon The longitude of the input value, in degrees.
16 |
17 | @returns The output value from the noise module.
18 |
19 | Use a negative latitude if the input value is located on the
20 | southern hemisphere.
21 |
22 | Use a negative longitude if the input value is located on the
23 | western hemisphere.
24 | **/
25 | public inline function getValue(lat:Float, lon:Float):Float {
26 | var r = Math.cos(0.017 * lat);
27 | var x = r * Math.cos(0.017 * lon);
28 | var y = Math.sin(0.017 * lat);
29 | var z = r * Math.sin(0.017 * lon);
30 | return module.getValue(x,y,z);
31 | }
32 | }
--------------------------------------------------------------------------------
/Sources/libnoise/operator/Abs.hx:
--------------------------------------------------------------------------------
1 | package libnoise.operator;
2 |
3 | /**
4 | * Provides a noise module that outputs the absolute value of the output value from
5 | * a source module. [OPERATOR]
6 | */
7 | class Abs extends ModuleBase {
8 |
9 |
10 | /**
11 | * Initializes a new instance of Abs.
12 | * @param "input" The input module
13 | */
14 | public function new(input : ModuleBase) {
15 | super(1);
16 | set(0, input);
17 | }
18 |
19 | override public function getValue(x : Float, y : Float, z : Float) {
20 | return Math.abs(get(0).getValue(x, y, z));
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Sources/libnoise/operator/Add.hx:
--------------------------------------------------------------------------------
1 | package libnoise.operator;
2 |
3 | /**
4 | * Provides a noise module that outputs the sum of the two output values from two
5 | * source modules. [OPERATOR]
6 | */
7 | class Add extends ModuleBase {
8 |
9 |
10 | /**
11 | * Initializes a new instance of Add.
12 | * @param "lhs" The left hand input module.
13 | * @param "rhs" The left hand input module.
14 | */
15 | public function new(lhs : ModuleBase, rhs : ModuleBase) {
16 | super(2);
17 | set(0, lhs);
18 | set(1, rhs);
19 | }
20 |
21 | override public function getValue(x : Float, y : Float, z : Float) {
22 | var val1 = get(0).getValue(x,y,z);
23 | var val2 = get(1).getValue(x,y,z);
24 | return val1 + val2;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Sources/libnoise/operator/Blend.hx:
--------------------------------------------------------------------------------
1 | package libnoise.operator;
2 |
3 | /**
4 | * Provides a noise module that outputs a weighted blend of the output values from
5 | * two source modules given the output value supplied by a control module. [OPERATOR]
6 | */
7 | class Blend extends ModuleBase {
8 |
9 | public var controller(get, set) : ModuleBase;
10 |
11 | public inline function set_controller(value : ModuleBase){
12 | return set(2, value);
13 | }
14 |
15 | public inline function get_controller(){
16 | return get(2);
17 | }
18 |
19 | /**
20 | * Initializes a new instance of Blend.
21 | * @param "lhs" : The left hand input module.
22 | * @param "rhs" : The right hand input module.
23 | * @param "controller" The controller of the operator.
24 | * @param "input" The input module
25 | */
26 | public function new(rhs : ModuleBase, lhs : ModuleBase, controller : ModuleBase) {
27 | super(3);
28 | set(0, rhs);
29 | set(1, lhs);
30 | set(2, controller);
31 | }
32 |
33 | override public function getValue(x : Float, y : Float, z : Float) {
34 | var a = get(0).getValue(x,y,z);
35 | var b = get(1).getValue(x,y,z);
36 | var c = (get(2).getValue(x,y,z)+1.0)/2.0;
37 | return Utils.InterpolateLinear(a,b,c);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Sources/libnoise/operator/Cache.hx:
--------------------------------------------------------------------------------
1 | package libnoise.operator;
2 |
3 | /**
4 | * Provides a noise module that caches the last output value generated by a source
5 | * module. [OPERATOR]
6 | */
7 | class Cache extends ModuleBase {
8 |
9 | var value : Float;
10 | var cached : Bool;
11 | var cx : Float;
12 | var cy : Float;
13 | var cz : Float;
14 |
15 | /**
16 | * Initializes a new instance of Cache.
17 | * @param "input" The input module
18 | */
19 | public function new(input : ModuleBase) {
20 | super(1);
21 | set(0,input);
22 | }
23 |
24 | override public function getValue(x : Float, y : Float, z : Float){
25 | if (!(cached && cx == x && cy == y && cz == z))
26 | {
27 | value = get(0).getValue(x, y, z);
28 | cx = x;
29 | cy = y;
30 | cz = z;
31 | }
32 | cached = true;
33 | return value;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Sources/libnoise/operator/Clamp.hx:
--------------------------------------------------------------------------------
1 | package libnoise.operator;
2 |
3 | /**
4 | * Provides a noise module that clamps the output value from a source module to a
5 | * range of values. [OPERATOR]
6 | */
7 | class Clamp extends ModuleBase {
8 |
9 | public var min = -1.0;
10 | public var max = 1.0;
11 |
12 | /**
13 | * Initializes a new instance of Clamp.
14 | * @param "min" : The minimum value
15 | * @param "y" : The maximum value
16 | * @param "input" The input module
17 | */
18 | public function new(min : Float, max : Float, input : ModuleBase) {
19 | super(1);
20 | set(0,input);
21 | this.min = min;
22 | this.max = max;
23 | }
24 |
25 | override public function getValue(x : Float, y : Float, z : Float){
26 | #if debug
27 | if(min > max)
28 | throw "min should be inferior to max";
29 | #end
30 | var value = get(0).getValue(x,y,z);
31 | return value < min ? min : value > max ? max : value;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/Sources/libnoise/operator/Curve.hx:
--------------------------------------------------------------------------------
1 | package libnoise.operator;
2 |
3 | import haxe.ds.ArraySort;
4 |
5 | /**
6 | * Provides a noise module that maps the output value from a source module onto an
7 | * arbitrary function curve.
8 | */
9 | class Curve extends ModuleBase {
10 |
11 | var data : Array>;
12 |
13 | /**
14 | * Initializes a new instance of Curve.
15 | * @param "input" The input module
16 | */
17 |
18 | public function new(input : ModuleBase) {
19 | super(1);
20 | set(0, input);
21 |
22 | data = new Array>();
23 | }
24 |
25 | public inline function controlPointCount() : Int {
26 | return data.length;
27 | }
28 |
29 |
30 | /**
31 | * Add a control point to the curve
32 | * @param input : The curve input value.
33 | * @param output : The curve output value.
34 | */
35 |
36 | public function add(input : Float, output : Float) {
37 | var vec = new Array();
38 | vec[0] = input;
39 | vec[1] = output;
40 | for(v in data){
41 | if(v[0] == input)
42 | return;
43 | }
44 | data.push(vec);
45 | ArraySort.sort(data, function(a : Array, b : Array) {
46 | return a[0] < b[0] ? -1 : a[0] == b[0] ? 0 : 1;
47 | });
48 | }
49 |
50 | /**
51 | * Clear the control points
52 | */
53 |
54 | public inline function clear() {
55 | data = new Array>();
56 | }
57 |
58 | override public function getValue(x : Float, y : Float, z : Float) {
59 |
60 | var smv = get(0).getValue(x, y, z);
61 | var ip = 0;
62 | for (i in 0...data.length) {
63 | if (smv < data[ip++][0])
64 | break;
65 | }
66 |
67 | var i0 = Utils.Clamp(ip - 2, 0, data.length - 1);
68 | var i1 = Utils.Clamp(ip - 1, 0, data.length - 1);
69 | var i2 = Utils.Clamp(ip, 0, data.length - 1);
70 | var i3 = Utils.Clamp(ip + 1, 0, data.length - 1);
71 |
72 | if (i1 == i2)
73 | return data[i1][1];
74 |
75 | var ip0 = data[i1][0];
76 | var ip1 = data[i2][0];
77 | var a = (smv - ip0) / (ip1 - ip0);
78 | return Utils.InterpolateCubic(data[i0][1], data[i1][1], data[i2][1], data[i3][1], a);
79 |
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/Sources/libnoise/operator/Displace.hx:
--------------------------------------------------------------------------------
1 | package libnoise.operator;
2 |
3 | /**
4 | * Provides a noise module that uses three source modules to displace each
5 | * coordinate of the input value before returning the output value from
6 | * a source module. [OPERATOR]
7 | */
8 | class Displace extends ModuleBase {
9 |
10 | public var X(get,set) : ModuleBase;
11 | public inline function set_X(val : ModuleBase){
12 | return set(1, val);
13 | }
14 | public inline function get_X() : ModuleBase{
15 | return get(1);
16 | }
17 | public var Y(get,set) : ModuleBase;
18 | public inline function set_Y(val : ModuleBase){
19 | return set(2, val);
20 | }
21 | public inline function get_Y() : ModuleBase{
22 | return get(2);
23 | }
24 | public var Z(get,set) : ModuleBase;
25 | public inline function set_Z(val : ModuleBase){
26 | return set(3, val);
27 | }
28 | public inline function get_Z() : ModuleBase{
29 | return get(3);
30 | }
31 |
32 | /**
33 | * Initializes a new instance of Displace.
34 | * @param "input" The input module
35 | * @param "x" The displacement module of the x-axis
36 | * @param "y" The displacement module of the y-axis
37 | * @param "z" The displacement module of the z-axis
38 | */
39 | public function new(input : ModuleBase, x : ModuleBase, y : ModuleBase, z : ModuleBase) {
40 | super(4);
41 | set(0, input);
42 | set(1, x);
43 | set(2, y);
44 | set(3, z);
45 | }
46 |
47 | override public function getValue(x : Float, y : Float, z : Float) {
48 | var dx = x + get(1).getValue(x, y, z);
49 | var dy = y + get(2).getValue(x, y, z);
50 | var dz = z + get(3).getValue(x, y, z);
51 | return get(0).getValue(dx,dy,dz);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/Sources/libnoise/operator/Exponent.hx:
--------------------------------------------------------------------------------
1 | package libnoise.operator;
2 |
3 | /**
4 | * Provides a noise module that maps the output value from a source module onto an
5 | * exponential curve. [OPERATOR]
6 | */
7 | class Exponent extends ModuleBase {
8 |
9 | public var exponent = 1.0;
10 |
11 |
12 | /**
13 | * Initializes a new instance of Exponent.
14 | * @param "exponent" The exponent to use
15 | * @param "input" The input module
16 | */
17 |
18 | public function new(exponent : Float, input : ModuleBase) {
19 | super(1);
20 | set(0, input);
21 | this.exponent = exponent;
22 | }
23 |
24 | override public function getValue(x : Float, y : Float, z : Float) {
25 | var value = get(0).getValue(x, y, z);
26 | return Math.pow(Math.abs((value + 1) / 2.0), exponent) * 2 - 1;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Sources/libnoise/operator/Invert.hx:
--------------------------------------------------------------------------------
1 | package libnoise.operator;
2 |
3 |
4 | /**
5 | * Provides a noise module that inverts the output value from a source module. [OPERATOR]
6 | */
7 | class Invert extends ModuleBase {
8 |
9 | public function new(input : ModuleBase) {
10 | super(1);
11 | set(0, input);
12 | }
13 |
14 | override public function getValue(x : Float, y : Float, z : Float) : Float {
15 | return -get(0).getValue(x,y,z);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Sources/libnoise/operator/Max.hx:
--------------------------------------------------------------------------------
1 | package libnoise.operator;
2 |
3 |
4 | /**
5 | * Provides a noise module that outputs the larger of the two output values from
6 | * two source modules. [OPERATOR]
7 | */
8 | class Max extends ModuleBase {
9 |
10 | public function new(lhs : ModuleBase, rhs : ModuleBase) {
11 | super(2);
12 | set(0, lhs);
13 | set(1, rhs);
14 | }
15 |
16 | override public function getValue(x : Float, y : Float, z : Float) : Float {
17 | var a = get(0).getValue(x, y, z);
18 | var b = get(1).getValue(x, y, z);
19 | return Math.max(a,b);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Sources/libnoise/operator/Min.hx:
--------------------------------------------------------------------------------
1 | package libnoise.operator;
2 |
3 |
4 | /**
5 | * Provides a noise module that outputs the smaller of the two output values from
6 | * two source modules. [OPERATOR]
7 | */
8 | class Min extends ModuleBase {
9 |
10 | public function new(lhs : ModuleBase, rhs : ModuleBase) {
11 | super(2);
12 | set(0, lhs);
13 | set(1, rhs);
14 | }
15 |
16 | override public function getValue(x : Float, y : Float, z : Float) : Float {
17 | var a = get(0).getValue(x, y, z);
18 | var b = get(1).getValue(x, y, z);
19 | return Math.min(a,b);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Sources/libnoise/operator/Multiply.hx:
--------------------------------------------------------------------------------
1 | package libnoise.operator;
2 |
3 |
4 | /**
5 | * Provides a noise module that outputs the product of the two output values from
6 | * two source modules. [OPERATOR]
7 | */
8 | class Multiply extends ModuleBase {
9 |
10 | public function new(lhs : ModuleBase, rhs : ModuleBase) {
11 | super(2);
12 | set(0, lhs);
13 | set(1, rhs);
14 | }
15 |
16 | override public function getValue(x : Float, y : Float, z : Float) : Float {
17 | return get(0).getValue(x, y, z)*get(1).getValue(x, y, z);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Sources/libnoise/operator/Power.hx:
--------------------------------------------------------------------------------
1 | package libnoise.operator;
2 |
3 |
4 | /**
5 | * Provides a noise module that outputs value from a first source module
6 | * to the power of the output value from a second source module. [OPERATOR]
7 | */
8 | class Power extends ModuleBase {
9 |
10 | public function new(lhs : ModuleBase, rhs : ModuleBase) {
11 | super(2);
12 | set(0, lhs);
13 | set(1, rhs);
14 | }
15 |
16 | override public function getValue(x : Float, y : Float, z : Float) : Float {
17 | return Math.pow(get(0).getValue(x, y, z), get(1).getValue(x, y, z));
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Sources/libnoise/operator/Rotate.hx:
--------------------------------------------------------------------------------
1 | package libnoise.operator;
2 |
3 | /**
4 | * Provides a noise module that rotates the input value around the origin before
5 | * returning the output value from a source module. [OPERATOR]
6 | */
7 | class Rotate extends ModuleBase {
8 |
9 | var rx : Float;
10 | var x1Matrix : Float;
11 | var x2Matrix : Float;
12 | var x3Matrix : Float;
13 | var ry : Float;
14 | var y1Matrix : Float;
15 | var y2Matrix : Float;
16 | var y3Matrix : Float;
17 | var rz : Float;
18 | var z1Matrix : Float;
19 | var z2Matrix : Float;
20 | var z3Matrix : Float;
21 |
22 | //angles in degree
23 | public function new(rx = 0.0, ry = 0.0, rz = 0.0, input : ModuleBase) {
24 | super(1);
25 | set(0, input);
26 | this.rx = rx;
27 | this.ry = ry;
28 | this.rz = rz;
29 | setAngles(rx,ry,rz);
30 | }
31 |
32 | public function setAngles(_rx : Float, _ry : Float, _rz : Float){
33 | var xc = Math.cos(_rx * Utils.Deg2Rad);
34 | var yc = Math.cos(_ry * Utils.Deg2Rad);
35 | var zc = Math.cos(_rz * Utils.Deg2Rad);
36 | var xs = Math.sin(_rx * Utils.Deg2Rad);
37 | var ys = Math.sin(_ry * Utils.Deg2Rad);
38 | var zs = Math.sin(_rz * Utils.Deg2Rad);
39 | x1Matrix = ys * xs * zs + yc * zc;
40 | y1Matrix = xc * zs;
41 | z1Matrix = ys * zc - yc * xs * zs;
42 | x2Matrix = ys * xs * zc - yc * zs;
43 | y2Matrix = xc * zc;
44 | z2Matrix = -yc * xs * zc - ys * zs;
45 | x3Matrix = -ys * xc;
46 | y3Matrix = xs;
47 | z3Matrix = yc * xc;
48 | rx = _rx;
49 | ry = _ry;
50 | rz = _rz;
51 | }
52 |
53 | override public function getValue(x : Float, y : Float, z : Float) : Float {
54 | var nx = (x1Matrix * x) + (y1Matrix * y) + (z1Matrix * z);
55 | var ny = (x2Matrix * x) + (y2Matrix * y) + (z2Matrix * z);
56 | var nz = (x3Matrix * x) + (y3Matrix * y) + (z3Matrix * z);
57 | return get(0).getValue(nx, ny, nz); }
58 | }
--------------------------------------------------------------------------------
/Sources/libnoise/operator/Scale.hx:
--------------------------------------------------------------------------------
1 | package libnoise.operator;
2 |
3 |
4 | /**
5 | * Provides a noise module that scales the coordinates of the input value before
6 | * returning the output value from a source module. [OPERATOR]
7 | */
8 | class Scale extends ModuleBase {
9 |
10 | private var sx : Float;
11 | private var sy : Float;
12 | private var sz : Float;
13 |
14 | public function new(sx = 1.0, sy = 1.0, sz = 1.0, input : ModuleBase) {
15 | super(1);
16 | set(0, input);
17 | this.sx = sx;
18 | this.sy = sy;
19 | this.sz = sz;
20 | }
21 |
22 | override public function getValue(x : Float, y : Float, z : Float) : Float {
23 | return get(0).getValue(x * sx, y * sy, z * sz);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Sources/libnoise/operator/ScaleBias.hx:
--------------------------------------------------------------------------------
1 | package libnoise.operator;
2 |
3 | /**
4 | * Provides a noise module that applies a scaling factor and a bias to the output
5 | * value from a source module. [OPERATOR]
6 | */
7 | class ScaleBias extends ModuleBase{
8 |
9 | public var scale : Float;
10 | public var bias : Float;
11 |
12 | public function new(scale = 1.0, bias = 0.0, input : ModuleBase) {
13 | super(1);
14 | set(0, input);
15 | this.scale = scale;
16 | this.bias = bias;
17 | }
18 |
19 | override public function getValue(x: Float, y : Float, z : Float) : Float{
20 | return get(0).getValue(x,y,z) * scale + bias;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Sources/libnoise/operator/Select.hx:
--------------------------------------------------------------------------------
1 | package libnoise.operator;
2 |
3 | /**
4 | * Provide a noise module that outputs the value selected from one of the two sources
5 | * modules choosen by the output value from a control module [OPERATOR]
6 | */
7 | class Select extends ModuleBase {
8 |
9 | public var fallOff : Float;
10 | public var raw : Float;
11 | public var min : Float = -1.0;
12 | public var max : Float = 1.0;
13 |
14 | /**
15 | * @param min : The minimum value
16 | * @param max : The maximum value
17 | * @param fallOff : the fallOff value at the edge transition
18 | * @param inputA : The first input module
19 | * @param inputB : The second input module
20 | * @param controller : The controller module
21 | */
22 |
23 | public function new(min = -1.0, max = 1.0, fallOff = 0.0, inputA : ModuleBase, inputB : ModuleBase, controller : ModuleBase) {
24 | super(3);
25 | set(0, inputA);
26 | set(1, inputB);
27 | set(2, controller);
28 | this.min = min;
29 | this.max = max;
30 | this.fallOff = fallOff;
31 | }
32 |
33 | override public function getValue(x : Float, y : Float, z : Float) : Float {
34 |
35 | var cv = get(2).getValue(x, y, z);
36 | if (fallOff > 0) {
37 |
38 | var a : Float;
39 |
40 | if (cv < min - fallOff)
41 | return get(0).getValue(x, y, z);
42 |
43 | if (cv < min + fallOff) {
44 |
45 | var lc = min - fallOff;
46 | var uc = min + fallOff;
47 | a = Utils.MapCubicSCurve((cv - lc) / (uc - lc));
48 | return Utils.InterpolateLinear(get(0).getValue(x, y, z), get(1).getValue(x, y, z), a);
49 | }
50 |
51 | if (cv < max - fallOff)
52 | return get(1).getValue(x, y, z);
53 |
54 | if (cv < max + fallOff) {
55 |
56 | var lc = max - fallOff;
57 | var uc = max + fallOff;
58 | a = Utils.MapCubicSCurve((cv - lc) / (uc - lc));
59 | return Utils.InterpolateLinear(get(1).getValue(x, y, z), get(0).getValue(x, y, z), a);
60 | }
61 | return get(0).getValue(x,y,z);
62 | }
63 | if(cv < min || cv > max)
64 | return get(0).getValue(x,y,z);
65 |
66 | return get(1).getValue(x,y,z);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/Sources/libnoise/operator/Subtract.hx:
--------------------------------------------------------------------------------
1 | package libnoise.operator;
2 |
3 | class Subtract extends ModuleBase {
4 |
5 | /**
6 | *
7 | * @param lhs : The left hand input module
8 | * @param rhs : The right hand input module
9 | */
10 | public function new(lhs : ModuleBase, rhs : ModuleBase) {
11 | super(2);
12 | set(0, lhs);
13 | set(1, rhs);
14 | }
15 |
16 | override public function getValue(x : Float, y : Float, z : Float) : Float {
17 |
18 | #if debug
19 | if (get(0) == null)
20 | throw "modules[0] should not be null";
21 | if (get(1) == null)
22 | throw "modules[1] should not be null";
23 | #end
24 |
25 | return get(0).getValue(x,y,z) - get(1).getValue(x,y,z);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Sources/libnoise/operator/Terrace.hx:
--------------------------------------------------------------------------------
1 | package libnoise.operator;
2 |
3 | import haxe.ds.ArraySort;
4 | /**
5 | * Provides a noise module that maps the output value from a source module onto a
6 | * terrace-forming curve. [OPERATOR]
7 | */
8 |
9 | class Terrace extends ModuleBase {
10 |
11 | public var data : Array;
12 | public var inverted : Bool;
13 |
14 | public function new(input : ModuleBase, ?inverted = false) {
15 | super(1);
16 | set(0, input);
17 | this.inverted = inverted;
18 | this.data = new Array();
19 | }
20 |
21 | public inline function controlPointCount() : Int {
22 | return data.length;
23 | }
24 |
25 | public function clear() {
26 | data = new Array();
27 | }
28 |
29 | public function add(value : Float) {
30 | for (val in data)
31 | if (val == value)
32 | return;
33 | data.push(value);
34 | ArraySort.sort(data, function(a : Float, b : Float) return a < b ? -1 : a == b ? 0 : 1);
35 | }
36 |
37 | //auto-generate a terrace curve
38 |
39 | public function generate(steps : Int) {
40 | #if debug
41 | if (steps < 2)
42 | throw "Need at least two steps";
43 | #end
44 | clear();
45 | var ts = 2.0 / (steps - 1.0);
46 | var cv = -1.0;
47 | for (i in 0...steps) {
48 | add(cv);
49 | cv += ts;
50 | }
51 | }
52 |
53 | override public function getValue(x : Float, y : Float, z : Float) {
54 | #if debug
55 | if (length() < 1)
56 | throw "need a module";
57 | if (controlPointCount() < 2)
58 | throw "need at least 2 controls points";
59 | #end
60 |
61 | var smv = get(0).getValue(x, y, z);
62 | var ip = 0;
63 | for (i in 0...data.length) {
64 | if (smv < data[ip++])
65 | break;
66 | }
67 |
68 | var i0 = (ip - 1 < 0) ? 0 : (ip - 1 > data.length - 1) ? data.length - 1 : ip - 1;
69 | var i1 = (ip < 0) ? 0 : (ip > data.length - 1) ? data.length - 1 : ip;
70 |
71 | if (i0 == i1) {
72 | return data[i1];
73 | }
74 |
75 | var v0 = data[i0];
76 | var v1 = data[i1];
77 | var a = (smv - v0) / (v1 - v0);
78 |
79 | if (inverted) {
80 | a = 1.0 - a;
81 | var t = v0;
82 | v0 = v1;
83 | v1 = t;
84 | }
85 |
86 | a *= a;
87 | return Utils.InterpolateLinear(v0, v1, a);
88 | }
89 |
90 |
91 | }
92 |
--------------------------------------------------------------------------------
/Sources/libnoise/operator/Translate.hx:
--------------------------------------------------------------------------------
1 | package libnoise.operator;
2 |
3 | /**
4 | * Provides a noise module that moves the coordinates of the input value before
5 | * returning the output value from a source module. [OPERATOR]
6 | */
7 |
8 | class Translate extends ModuleBase {
9 |
10 | public var dx = 1.0;
11 | public var dy = 1.0;
12 | public var dz = 1.0;
13 |
14 | /**
15 | * Initializes a new instance of Translate.
16 | * @param "x" The translation on the x-axis
17 | * @param "y" The translation on the y-axis
18 | * @param "z" The translation on the z-axis
19 | * @param "input" The input module
20 | */
21 | public function new(dx : Float, dy : Float, dz : Float, input : ModuleBase) {
22 | super(1);
23 | set(0,input);
24 | this.dx = dx;
25 | this.dy = dy;
26 | this.dz = dz;
27 | }
28 |
29 | override public function getValue(x : Float, y : Float, z : Float){
30 | return get(0).getValue(x + dx, y + dy, z + dz);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Sources/libnoise/operator/Turbulence.hx:
--------------------------------------------------------------------------------
1 | package libnoise.operator;
2 |
3 | import libnoise.generator.Perlin;
4 | import libnoise.QualityMode;
5 |
6 | /**
7 | * Provides a noise module that that randomly displaces the input value before
8 | * returning the output value from a source module. [OPERATOR]
9 | **/
10 |
11 | class Turbulence extends ModuleBase{
12 |
13 | static inline var X0 : Float = (12414.0 / 65536.0);
14 | static inline var Y0 : Float = (65124.0 / 65536.0);
15 | static inline var Z0 : Float = (31337.0 / 65536.0);
16 | static inline var X1 : Float = (26519.0 / 65536.0);
17 | static inline var Y1 : Float = (18128.0 / 65536.0);
18 | static inline var Z1 : Float = (60493.0 / 65536.0);
19 | static inline var X2 : Float = (53820.0 / 65536.0);
20 | static inline var Y2 : Float = (11213.0 / 65536.0);
21 | static inline var Z2 : Float = (44845.0 / 65536.0);
22 |
23 | public var power = 1.0;
24 | var xDistort : Perlin;
25 | var yDistort : Perlin;
26 | var zDistort : Perlin;
27 |
28 | public function new(power : Float, input : ModuleBase, ?distortX : Perlin, ?distortY : Perlin, ?distortZ : Perlin) {
29 | super(1);
30 |
31 | set(0, input);
32 |
33 | this.power = power;
34 |
35 | if(distortX == null)
36 | this.xDistort = new Perlin(1.0, 2.0, 0.5, 6, 123, MEDIUM);
37 | else
38 | this.xDistort = distortX;
39 | if(distortY == null)
40 | this.yDistort = new Perlin(1.0, 2.0, 0.5, 6, 123, MEDIUM);
41 | else
42 | this.yDistort = distortY;
43 | if(distortZ == null)
44 | this.zDistort = new Perlin(1.0, 2.0, 0.5, 6, 123, MEDIUM);
45 | else
46 | this.zDistort = distortZ;
47 | }
48 |
49 | // set the roughness of the turbulence.
50 | public function setFrequency(frequency : Float){
51 | xDistort.frequency = frequency;
52 | yDistort.frequency = frequency;
53 | zDistort.frequency = frequency;
54 | }
55 |
56 | // set the roughness of the turbulence.
57 | public function setRoughness(roughness : Int){
58 | xDistort.octaves = roughness;
59 | yDistort.octaves = roughness;
60 | zDistort.octaves = roughness;
61 | }
62 |
63 | // set the seed of the turbulence.
64 | public function setSeed(seed : Int){
65 | xDistort.seed = seed;
66 | yDistort.seed = seed;
67 | zDistort.seed = seed;
68 | }
69 |
70 | override public function getValue(x : Float, y : Float, z : Float) : Float{
71 | var xd = x + (xDistort.getValue(x + X0, y + Y0, z + Z0) * power);
72 | var yd = y + (yDistort.getValue(x + X1, y + Y1, z + Z1) * power);
73 | var zd = z + (zDistort.getValue(x + X2, y + Y2, z + Z2) * power);
74 | return get(0).getValue(xd, yd, zd);
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/haxelib.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "libnoise",
3 | "url" : "https://github.com/memilian/libnoise/",
4 | "license": "LGPL",
5 | "tags": ["noise", "procedural"],
6 | "description": "Haxe port of libnoise, the coherent noise library",
7 | "version": "1.0.1",
8 | "classPath": "Sources/",
9 | "releasenote": "haxe 3.3.0 compatibility, added NoiseMaps",
10 | "contributors": ["memilian"],
11 | "dependencies": {}
12 | }
13 |
14 |
--------------------------------------------------------------------------------
/test.hxml:
--------------------------------------------------------------------------------
1 | -cp test/Sources
2 | -lib libnoise
3 | -lib format
4 | -main Test
5 | -cpp test/build-test/
6 |
7 |
--------------------------------------------------------------------------------
/test/Sources/Test.hx:
--------------------------------------------------------------------------------
1 | package ;
2 | import libnoise.operator.Add;
3 | import libnoise.operator.Add;
4 | import libnoise.operator.Abs;
5 | import libnoise.operator.Blend;
6 | import libnoise.operator.Cache;
7 | import libnoise.operator.Clamp;
8 | import libnoise.operator.Exponent;
9 | import libnoise.operator.Displace;
10 | import libnoise.Utils;
11 | import libnoise.operator.Curve;
12 | import libnoise.ModuleBase;
13 | import libnoise.operator.Invert;
14 | import libnoise.operator.Max;
15 | import libnoise.operator.Min;
16 | import libnoise.operator.Power;
17 | import libnoise.operator.Multiply;
18 | import libnoise.operator.Rotate;
19 | import libnoise.operator.Scale;
20 | import libnoise.operator.ScaleBias;
21 | import libnoise.operator.Select;
22 | import libnoise.operator.Subtract;
23 | import libnoise.operator.Terrace;
24 | import libnoise.operator.Translate;
25 | import libnoise.operator.Turbulence;
26 | import libnoise.generator.Voronoi;
27 | import libnoise.generator.Sphere;
28 | import libnoise.generator.Cylinder;
29 | import libnoise.generator.Const;
30 | import libnoise.generator.Checker;
31 | import libnoise.generator.RidgedMultifractal;
32 | import libnoise.generator.Billow;
33 | import libnoise.builder.NoiseMap;
34 | import libnoise.builder.NoiseMapBuilderPlane;
35 | import libnoise.builder.NoiseMapBuilderCylinder;
36 | import libnoise.builder.NoiseMapBuilderSphere;
37 | import libnoise.builder.NoiseMapBuilder;
38 |
39 | import format.png.Tools;
40 | import format.png.Writer;
41 | import format.png.Data;
42 | import sys.io.FileOutput;
43 | import sys.io.File;
44 | import haxe.io.BytesBuffer;
45 | import haxe.Timer;
46 | import haxe.io.Bytes;
47 |
48 | import libnoise.QualityMode;
49 | import libnoise.generator.Perlin;
50 |
51 | class Test {
52 |
53 | public static function main() {
54 | new Test();
55 | }
56 |
57 | //dimensions of output images
58 | var width = 512;
59 | var height = 512;
60 |
61 | //path to directory where images will be saved
62 | var outputPath = "test/images/";
63 |
64 | //default modules parameters
65 | var frequency = 0.01;
66 | var lacunarity = 2.0;
67 | var persistence = 0.5;
68 | var octaves = 16;
69 | var seed = 42;
70 | var quality = HIGH;
71 |
72 |
73 | public function new() {
74 | var testName = "";
75 | var module : ModuleBase;
76 |
77 | //Perlin generator
78 | testName = "perlin";
79 | module = new Perlin(frequency, lacunarity, persistence, octaves, seed, quality);
80 | generate([module], testName);
81 |
82 | //Billow generator
83 | testName = "billow";
84 | module = new Billow(frequency, lacunarity, persistence, octaves, seed, quality);
85 | generate([module], testName);
86 |
87 | //Ridged Multifractal generator
88 | testName = "ridged_multifractal";
89 | module = new RidgedMultifractal(frequency, persistence, 1, seed, quality);
90 | generate([module], testName);
91 |
92 | //Checker generator
93 | testName = "checker";
94 | module = new Checker();
95 | generate([module], testName);
96 |
97 | //Const generator
98 | testName = "const";
99 | module = new Const(1);
100 | generate([module], testName);
101 |
102 | //Cylinder generator
103 | testName = "cylinder";
104 | module = new Cylinder(frequency);
105 | generate([module], testName);
106 |
107 | //Sphere generator
108 | testName = "sphere";
109 | module = new Sphere(frequency);
110 | generate([module], testName);
111 |
112 | //Voronoi generator - distance on
113 | testName = "voronoi_distance_on";
114 | module = new Voronoi(frequency * 2, 1, seed, true);
115 | generate([module], testName);
116 |
117 | //Voronoi generator - distance off
118 | testName = "voronoi_distance_off";
119 | module = new Voronoi(frequency * 2, 1, seed, false);
120 | generate([module], testName);
121 |
122 | /**
123 | * Operators
124 | */
125 |
126 | //Abs operator
127 | testName = "abs";
128 | var absIn = new Billow(frequency, lacunarity, persistence, octaves, seed, quality);
129 | var abs = new Abs(absIn);
130 | generate([absIn, abs], testName);
131 |
132 | //Add operator
133 | testName = "add";
134 | var addIn1 = new Billow(frequency, lacunarity, persistence, octaves, seed, quality);
135 | var addIn2 = new RidgedMultifractal(frequency*2, lacunarity, 1, seed, quality);
136 | var add = new Add(addIn1, addIn2);
137 | generate([addIn1, addIn2, add], testName);
138 |
139 | //Blend operator
140 | testName = "blend";
141 | var blendIn1 = new Perlin(frequency/2, lacunarity, persistence, octaves, 657, quality);
142 | var blendIn2 = new Billow(frequency, lacunarity, persistence, octaves, seed, quality);
143 | var blendCtrl = new Sphere(0.006);
144 | var blend = new Blend(blendIn1, blendIn2, blendCtrl);
145 | generate([blendIn1, blendIn2, blendCtrl, blend], testName);
146 |
147 | //Cache operator
148 | testName = "cache";
149 | var cacheInp = new Billow(frequency, lacunarity, persistence, octaves, seed, quality);
150 | var cache = new Cache(cacheInp);
151 | generate([cacheInp, cache], testName);
152 |
153 | //Clamp operator
154 | testName = "clamp";
155 | var clampInp = new Billow(frequency, lacunarity, persistence, octaves, seed, quality);
156 | var clamp = new Clamp(0,0.5,clampInp);
157 | generate([clampInp, clamp], testName);
158 |
159 | //Curve operator
160 | testName = "Curve";
161 | var curveInpt = new Billow(frequency, lacunarity, persistence, octaves, seed, quality);
162 | var curve = new Curve(curveInpt);
163 | curve.add(-1, -1);
164 | curve.add(-0.5, 0);
165 | curve.add(0, -0.3);
166 | curve.add(1, 1);
167 | generate([curveInpt, curve], testName);
168 |
169 | //Displace operator
170 | testName = "displace";
171 | var dIn = new Sphere(0.003);
172 | var dX = new ScaleBias(10, 0, new Billow(frequency/2, lacunarity, persistence, octaves, seed, quality));
173 | var dY = new ScaleBias(30, 0, new RidgedMultifractal(frequency*2, lacunarity, octaves, seed, quality));
174 | var dZ = new Const(1);
175 | var disp = new Displace(dIn, dX, dY, dZ);
176 | generate([dIn, dX, dY, dZ, disp], testName);
177 |
178 | //Exponent operator
179 | testName = "exponent";
180 | var expIn = new Sphere(0.006);
181 | var exp = new Exponent(3, expIn);
182 | generate([expIn, exp], testName);
183 |
184 | //Invert operator
185 | testName = "invert";
186 | var inv1 = new Billow(frequency, lacunarity, persistence, octaves, seed, quality);
187 | var invert = new Invert(inv1);
188 | generate([inv1, invert], testName);
189 |
190 | //Max operator
191 | testName = "max";
192 | var max1 = new Billow(frequency, lacunarity, persistence, octaves, seed, quality);
193 | var max2 = new Cylinder(frequency);
194 | generate([max1, max2, new Max(max1, max2)], testName);
195 |
196 | //Min operator
197 | testName = "min";
198 | var min1 = new Billow(frequency, lacunarity, persistence, octaves, seed, quality);
199 | var min2 = new Cylinder(frequency);
200 | generate([min1, min2, new Min(min1, min2)], testName);
201 |
202 | //Multiply operator
203 | testName = "multiply";
204 | var pow1 = new Rotate(0, 0, 90, new Cylinder(frequency));
205 | var pow2 = new Cylinder(frequency);
206 | generate([pow1, pow2, new Multiply(pow1, pow2)], testName);
207 |
208 | //Power operator
209 | testName = "power";
210 | var pow1 = new Perlin(frequency, lacunarity, persistence, octaves, seed, quality);
211 | var pow2 = new Cylinder(frequency / 3);
212 | generate([pow1, pow2, new Power(pow1, pow2)], testName);
213 |
214 | //Rotate operator
215 | testName = "rotate";
216 | module = new Cylinder(frequency);
217 | var rotate = new Rotate(30, 0, 45, module);
218 | generate([module, rotate], testName);
219 |
220 | //Scale operator
221 | testName = "scale";
222 | module = new Perlin(frequency, lacunarity, persistence, octaves, seed, quality);
223 | var scale = new Scale(2.0, 2.0, 2.0, module);
224 | generate([module, scale], testName);
225 |
226 | //ScaleBias operator
227 | testName = "scaleBias";
228 | module = new Perlin(frequency, lacunarity, persistence, octaves, seed, quality);
229 | var scaleBias = new ScaleBias(0.5, 0.5, module);
230 | generate([module, scaleBias], testName);
231 |
232 | //Select operator
233 | testName = "select";
234 | var inpA = new Perlin(frequency, lacunarity, persistence, octaves, seed, quality);
235 | var inpB = new Billow(frequency * 2, lacunarity, persistence, octaves, seed, quality);
236 | var controller = inpA;
237 | var select = new Select(0.3, 1.0, 0.9, inpA, inpB, controller);
238 | generate([inpA, inpB, controller, select], testName);
239 |
240 | //Subtract operator
241 | testName = "subtract";
242 | module = new Perlin(frequency, lacunarity, persistence, octaves, seed, quality);
243 | var rhs = new Sphere(frequency);
244 | var subtract = new Subtract(module, rhs);
245 | generate([module, rhs, subtract], testName);
246 |
247 | //Terrace operator
248 | testName = "terrace_6_steps";
249 | module = new Perlin(frequency, lacunarity, persistence, octaves, seed, quality);
250 | var terrace = new Terrace(module, true);
251 | terrace.generate(10); //generate 10 controls points from -1 to 1
252 | generate([module, terrace], testName);
253 |
254 | //Translate operator
255 | testName = "translate_x";
256 | module = new Perlin(frequency, lacunarity, persistence, octaves, seed, quality);
257 | var translate = new Translate(width / 2, 0, 0, module);
258 | generate([module, translate], testName);
259 |
260 | //Turbulence operator
261 | testName = "turbulences";
262 | module = new Sphere(0.003);//new Voronoi(frequency * 2, 1, seed, false);
263 | var turb = new Turbulence(10, module);
264 | turb.setFrequency(0.03);
265 | generate([module, turb], testName);
266 |
267 |
268 | /**
269 | * NoiseMapBuilders
270 | **/
271 |
272 | module = new Perlin(frequency, lacunarity, persistence, octaves, seed, quality);
273 |
274 | testName = "Perlin_tileable";
275 | var planeMapBuilder = new NoiseMapBuilderPlane();
276 | planeMapBuilder.isSeamlessEnabled = true; //set tileable
277 | planeMapBuilder.sourceModule = module;
278 | planeMapBuilder.setDestSize(width, height);
279 | planeMapBuilder.setBounds(0,0,width, height);
280 | planeMapBuilder.destNoiseMap = new NoiseMap(width,height);
281 | generateFromBuilders([planeMapBuilder, planeMapBuilder], testName);
282 |
283 |
284 | //the cylinder is normalized, we need to increase frequency (or add a scale module)
285 | module = new Perlin(frequency * 100, lacunarity, persistence, octaves, seed, quality);
286 |
287 | testName = "Perlin_Cylinder";
288 | var cylinderMapBuilder = new NoiseMapBuilderCylinder();
289 | cylinderMapBuilder.sourceModule = module;
290 | cylinderMapBuilder.setDestSize(width, height);
291 | cylinderMapBuilder.setBounds(-180,180,0,2);
292 | cylinderMapBuilder.destNoiseMap = new NoiseMap(width,height);
293 | generateFromBuilders([cylinderMapBuilder], testName);
294 |
295 |
296 | //the sphere is normalized, we need to increase frequency (or add a scale module)
297 | module = new Perlin(frequency * 100, lacunarity, persistence, octaves, seed, quality);
298 |
299 | testName = "Perlin_Sphere";
300 | var sphereMapBuilder = new NoiseMapBuilderSphere();
301 | sphereMapBuilder.sourceModule = module;
302 | sphereMapBuilder.setDestSize(width, height);
303 | sphereMapBuilder.setBounds(-90,90,-180,180);
304 | sphereMapBuilder.destNoiseMap = new NoiseMap(width,height);
305 | generateFromBuilders([sphereMapBuilder], testName);
306 |
307 | }
308 |
309 | //generate a png containing the image of each modules next of each other
310 |
311 | public function generate(modules : Array, name : String) {
312 | var timeStart = Timer.stamp();
313 |
314 | var w = (modules.length) * width;
315 |
316 |
317 | //generate pixel values
318 | var data : BytesBuffer = new BytesBuffer();
319 | for (y in 0...height) {
320 | for (x in 0...w) {
321 | //pick a module based on the current x position
322 | var moduleIndex = Std.int(x / width);
323 | var xOff = moduleIndex * width;
324 |
325 | var value = getGreyValue(modules[moduleIndex].getValue(x - xOff, y, 0));
326 | data.addByte(value);
327 | }
328 | }
329 |
330 | createPng(data.getBytes(), w, height, name);
331 |
332 | var genTime = Timer.stamp() - timeStart;
333 | trace('Generated image $name in $genTime');
334 | }
335 |
336 | public function generateFromBuilders(builders : Array, name : String) {
337 | var timeStart = Timer.stamp();
338 |
339 | var w = (builders.length) * width;
340 |
341 | //generate noiseMaps
342 | for(builder in builders)
343 | builder.build();
344 |
345 | //generate pixel values
346 | var data : BytesBuffer = new BytesBuffer();
347 | for (y in 0...height) {
348 | for (x in 0...w) {
349 | //pick a noiseMap based on the current x position
350 | var idx = Std.int(x / width);
351 | var xOff = idx * width;
352 |
353 | var value = getGreyValue(builders[idx].destNoiseMap.getValue(x - xOff, y));
354 | data.addByte(value);
355 | }
356 | }
357 |
358 | createPng(data.getBytes(), w, height, name);
359 |
360 | var genTime = Timer.stamp() - timeStart;
361 | trace('Generated image $name in $genTime');
362 | }
363 |
364 | public function getGreyValue(val : Float) {
365 | var val = Std.int(128 * (val + 1));
366 | return val > 255 ? 255 : val < 0 ? 0 : val;
367 | }
368 |
369 | public function createPng(data : Bytes, w : Int, h : Int, name : String) {
370 | var pngData : Data = Tools.buildGrey(w, h, data);
371 | var handle : FileOutput = File.write('$outputPath$name.png', true);
372 | var writer : Writer = new Writer(handle);
373 | writer.write(pngData);
374 | }
375 | }
376 |
--------------------------------------------------------------------------------