├── LICENSE ├── README.md ├── favicon.ico ├── ico_expand.png ├── ico_link.png ├── index.html ├── index_embed.html ├── itchcover.png ├── og_icon.png ├── random.js └── title_penguin.png /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 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # icon-machine 2 | Web application for randomly generating pixel art icons. You can try it out [on this page][1]. 3 | 4 | Generated icons are [CC0][2]-licensed. The Javascript source code is GPL-licensed. 5 | 6 | [1]: https://www.brianmacintosh.com/iconmachine 7 | [2]: https://creativecommons.org/publicdomain/zero/1.0/ 8 | -------------------------------------------------------------------------------- /favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrianMacIntosh/icon-machine/135fa8c8ac8c2ee40c0688625c6917814f865b10/favicon.ico -------------------------------------------------------------------------------- /ico_expand.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrianMacIntosh/icon-machine/135fa8c8ac8c2ee40c0688625c6917814f865b10/ico_expand.png -------------------------------------------------------------------------------- /ico_link.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrianMacIntosh/icon-machine/135fa8c8ac8c2ee40c0688625c6917814f865b10/ico_link.png -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Icon Machine 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 39 | 40 | 96 | 97 | 98 | 99 | 100 | 101 |
Penguin in a TV
102 | 103 |
104 |
Icon Machine
105 |
106 | 107 |
108 |
109 |
110 | 114 |
115 |
116 |
Revert
117 |
118 | 119 | 124 | 130 | 137 |
138 |
139 | 140 |
Share
141 |
142 | 143 |
144 |
145 |

It generates random pixel art icons for potions or bladed weapons.

146 |

Icons generated by this page are licensed as CC0. You can download an icon or sheet by right-clicking on it.

147 |

Github
Source

148 |
149 | 150 |
151 | 152 | 153 | 154 | 155 | 156 | 157 | -------------------------------------------------------------------------------- /index_embed.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 25 | 26 | 82 | 83 | 84 | 85 | 86 | 87 |
Penguin in a TV
88 | 89 |
90 |
Icon Machine
91 |
92 | 93 |
94 |
95 |
96 | 100 |
101 |
102 |
Revert
103 |
104 | 105 | 110 | 115 | 122 |
123 |
124 | 125 | 126 |
127 | 128 |
129 | 130 |
131 | 132 | 133 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /itchcover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrianMacIntosh/icon-machine/135fa8c8ac8c2ee40c0688625c6917814f865b10/itchcover.png -------------------------------------------------------------------------------- /og_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrianMacIntosh/icon-machine/135fa8c8ac8c2ee40c0688625c6917814f865b10/og_icon.png -------------------------------------------------------------------------------- /random.js: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Icon Machine - Random Potion Icon Generator 4 | 5 | Copyright 2018-2021 Brian MacIntosh 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . 19 | */ 20 | 21 | window.RandomArt = 22 | { 23 | versionNumber: 2, 24 | 25 | displayScale: 2, 26 | dimension: 32, 27 | tileDimension: 1, 28 | iconClass: "anyweapon", 29 | 30 | allClasses: [ "potions", "blades", "spears" ], 31 | 32 | // Stores the state of the parameters from before the last zoom-in 33 | configPreZoom: null, 34 | 35 | Bounds: class 36 | { 37 | constructor(x, y, w, h) 38 | { 39 | if (y === undefined) 40 | { 41 | if (x === undefined) 42 | { 43 | this.x = 0; this.y = 0; this.w = 0; this.h = 0; 44 | } 45 | else 46 | { 47 | this.x = x.x; this.y = x.y; this.w = x.w; this.h = x.h; 48 | } 49 | } 50 | else 51 | { 52 | this.x = x; this.y = y; this.w = w; this.h = h; 53 | } 54 | } 55 | 56 | contains(v) 57 | { 58 | var x = v.x; 59 | var y = v.y; 60 | return x >= this.x && y >= this.y 61 | && x < this.x + this.w && y < this.y + this.h; 62 | } 63 | }, 64 | 65 | Vector: class 66 | { 67 | constructor(x, y) 68 | { 69 | if (y === undefined) 70 | { 71 | if (x === undefined) 72 | { 73 | this.x = 0; this.y = 0; 74 | } 75 | else 76 | { 77 | this.x = x.x; this.y = x.y; 78 | } 79 | } 80 | else 81 | { 82 | this.x = x; this.y = y; 83 | } 84 | } 85 | 86 | normalize() 87 | { 88 | var length = this.length(); 89 | this.x /= length; 90 | this.y /= length; 91 | return this; 92 | } 93 | 94 | length() 95 | { 96 | return Math.sqrt(this.x * this.x + this.y * this.y); 97 | } 98 | 99 | lengthSq() 100 | { 101 | return this.x * this.x + this.y * this.y; 102 | } 103 | 104 | distanceTo(x, y) 105 | { 106 | return Math.sqrt(this.distanceToSq(x, y)); 107 | } 108 | 109 | distanceToSq(x, y) 110 | { 111 | if (y === undefined) 112 | { 113 | var dx = this.x - x.x; var dy = this.y - x.y; 114 | } 115 | else 116 | { 117 | var dx = this.x - x; var dy = this.y - y; 118 | } 119 | return dx * dx + dy * dy; 120 | } 121 | 122 | addVector(v) 123 | { 124 | this.x += v.x; 125 | this.y += v.y; 126 | return this; 127 | } 128 | 129 | lerpTo(v, t) 130 | { 131 | this.x = (v.x - this.x) * t + this.x; 132 | this.y = (v.y - this.y) * t + this.y; 133 | return this; 134 | } 135 | 136 | multiplyScalar(v) 137 | { 138 | this.x *= v; 139 | this.y *= v; 140 | return this; 141 | } 142 | 143 | dotProduct(x, y) 144 | { 145 | if (y === undefined) 146 | return this.x * v.x + this.y * v.y; 147 | else 148 | return this.x * x + this.y * y; 149 | } 150 | 151 | set(x, y) 152 | { 153 | if (y === undefined) 154 | { 155 | this.x = x.x; this.y = x.y; 156 | } 157 | else 158 | { 159 | this.x = x; this.y = y; 160 | } 161 | return this; 162 | } 163 | }, 164 | 165 | initialize: function() 166 | { 167 | if (this.initialized) return; 168 | this.initialized = true; 169 | 170 | this.randomFloat = this.randomFloatDefault; 171 | 172 | this.canvas = document.getElementById("generator"); 173 | this.canvas.addEventListener("click", function(e){RandomArt.handleCanvasClick(e);}); 174 | this.context = this.canvas.getContext('2d'); 175 | this.contextTranslation = new this.Vector(0, 0); 176 | 177 | this.canvasParent = document.getElementById("generatorCanvas"); 178 | 179 | this.restoreConfigPreZoomButton = document.getElementById("restoreConfigPreZoomButton"); 180 | this.shareLinkAnchor = document.getElementById("shareLink"); 181 | this.displayScaleSelect = document.getElementById("displayScale"); 182 | this.dimensionSelect = document.getElementById("dimension"); 183 | this.tileDimensionSelect = document.getElementById("tileDimension"); 184 | this.iconClassSelect = document.getElementById("iconClass"); 185 | this.seedInput = document.getElementById("seed"); 186 | 187 | // set default config from URL 188 | var params = {}; 189 | var stringParams = location.search.substring(1).split('&'); 190 | for (var i = 0; i < stringParams.length; i++) 191 | { 192 | var nv = stringParams[i].split('='); 193 | if (!nv[0]) continue; 194 | params[nv[0]] = nv[1] || true; 195 | } 196 | if (params.dim) 197 | { 198 | this.dimension = parseInt(params.dim); 199 | this.dimensionSelect.value = this.dimension; 200 | } 201 | if (params.tiledim) 202 | { 203 | this.tileDimension = parseInt(params.tiledim); 204 | this.tileDimensionSelect.value = this.tileDimension; 205 | } 206 | if (params.class) 207 | { 208 | this.iconClass = params.class; 209 | 210 | for (var i = 0; i < this.iconClassSelect.options.length; i++) 211 | { 212 | if (this.iconClassSelect.options[i].value == this.iconClass) 213 | { 214 | this.iconClassSelect.selectedIndex = i; 215 | } 216 | } 217 | } 218 | if (params.seed) 219 | { 220 | this.seedInput.value = params.seed; 221 | this.resizeCanvas(); // accounts for dimensions changed by parameters 222 | } 223 | else 224 | { 225 | this.randomizeSeed(); 226 | } 227 | 228 | this.updateDisplayScale(); 229 | this.clearConfigPreZoom(); 230 | this.updateShareLink(); 231 | }, 232 | 233 | translateContext: function(x, y) 234 | { 235 | this.context.translate(x, y); 236 | this.contextTranslation.x += x; 237 | this.contextTranslation.y += y; 238 | }, 239 | 240 | // Resets the RNG using the specified seed 241 | seedRng: function(seed) 242 | { 243 | this.seedGenerator = this.xmur3(seed); 244 | this.checkpointRng(); 245 | }, 246 | 247 | // Generates a random seed with the specified random float function 248 | createRandomSeed: function(randomFunc) 249 | { 250 | randomFunc = randomFunc || Math.random; 251 | var randomString = ""; 252 | for (var i = 0; i < 16; i++) 253 | { 254 | var randomChar = Math.floor(randomFunc()*62); 255 | if (randomChar < 10) randomChar = 48+randomChar; 256 | else if (randomChar < 36) randomChar = 65-10+randomChar; 257 | else randomChar = 97-36+randomChar; 258 | randomString += String.fromCharCode(randomChar); 259 | } 260 | return randomString; 261 | }, 262 | 263 | // Generates and sets a random seed with the specified random float function 264 | randomizeSeed: function(randomFunc) 265 | { 266 | var randomString = this.createRandomSeed(randomFunc); 267 | this.seedInput.value = randomString; 268 | this.seedRng(randomString); 269 | this.updateShareLink(); 270 | this.clearConfigPreZoom(); 271 | this.generateNewImage(); 272 | }, 273 | 274 | // Creates an RNG "checkpoint" that proofs the results against code changes (somewhat) 275 | checkpointRng: function() 276 | { 277 | if (this.seedGenerator) 278 | { 279 | this.randomFloat = this.sfc32(this.seedGenerator(), this.seedGenerator(), this.seedGenerator(), this.seedGenerator()); 280 | } 281 | }, 282 | 283 | // Hash function for seeding the RNG 284 | // https://stackoverflow.com/a/47593316 285 | xmur3: function(str) 286 | { 287 | for(var i = 0, h = 1779033703 ^ str.length; i < str.length; i++) 288 | h = Math.imul(h ^ str.charCodeAt(i), 3432918353), 289 | h = h << 13 | h >>> 19; 290 | return function() { 291 | h = Math.imul(h ^ h >>> 16, 2246822507); 292 | h = Math.imul(h ^ h >>> 13, 3266489909); 293 | return (h ^= h >>> 16) >>> 0; 294 | } 295 | }, 296 | 297 | // RNG 298 | /// https://stackoverflow.com/a/47593316 299 | sfc32: function(a, b, c, d) 300 | { 301 | return function() { 302 | a >>>= 0; b >>>= 0; c >>>= 0; d >>>= 0; 303 | var t = (a + b) | 0; 304 | a = b ^ b >>> 9; 305 | b = c + (c << 3) | 0; 306 | c = (c << 21 | c >>> 11); 307 | d = d + 1 | 0; 308 | t = t + d | 0; 309 | c = c + t | 0; 310 | return (t >>> 0) / 4294967296; 311 | } 312 | }, 313 | 314 | /** 315 | * Returns a random integer in the range [min, max) 316 | */ 317 | randomRange: function(min, max) 318 | { 319 | return Math.floor(this.randomRangeFloat(min, max)); 320 | }, 321 | 322 | /** 323 | * Returns a random integer in the range [min, max), skewed low 324 | */ 325 | randomRangeLow: function(min, max) 326 | { 327 | return Math.floor(this.randomRangeFloatLow(min, max)); 328 | }, 329 | 330 | /** 331 | * Returns a random integer in the range [min, max), skewed high 332 | */ 333 | randomRangeHigh: function(min, max) 334 | { 335 | return Math.floor(this.randomRangeFloatHigh(min, max)); 336 | }, 337 | 338 | /** 339 | * Returns 1 or -1. 340 | */ 341 | randomSign: function() 342 | { 343 | return this.randomFloat() > 0.5 ? 1 : -1; 344 | }, 345 | 346 | /** 347 | * Returns a random float in the range [min, max) 348 | */ 349 | randomRangeFloat: function(min, max) 350 | { 351 | return this.randomFloat() * (max - min) + min; 352 | }, 353 | 354 | /** 355 | * Returns a random float in the range [min, max), skewed to the ends 356 | */ 357 | randomRangeFloatExtreme: function(min, max) 358 | { 359 | return this.randomSign() * this.randomFloatHigh((max - min) / 2) + (max + min) / 2; 360 | }, 361 | 362 | /** 363 | * Returns a random float in the range [min, max), skewed low. 364 | */ 365 | randomRangeFloatLow: function(min, max) 366 | { 367 | return this.randomFloatLow() * (max - min) + min; 368 | }, 369 | 370 | /** 371 | * Returns a random float in the range [min, max), skewed high. 372 | */ 373 | randomRangeFloatHigh: function(min, max) 374 | { 375 | return this.randomFloatHigh() * (max - min) + min; 376 | }, 377 | 378 | /** 379 | * Returns a random float between 0 and 1. 380 | */ 381 | randomFloatDefault: function() 382 | { 383 | return Math.random(); 384 | }, 385 | 386 | /** 387 | * Returns a random float between 0 and 1. Overwritten by seeding. 388 | */ 389 | randomFloat: undefined, 390 | 391 | /** 392 | * Returns a random float between 0 and 1, weighted to the extremes. 393 | */ 394 | randomFloatExtreme: function() 395 | { 396 | var rand = this.randomFloat()*2 - 1; 397 | return rand * rand; 398 | }, 399 | 400 | /** 401 | * Returns a random float between 0 and 1, weighted down. 402 | */ 403 | randomFloatLow: function() 404 | { 405 | var v = this.randomFloat(); 406 | return v * v; 407 | }, 408 | 409 | /** 410 | * Returns a random float between 0 and 1, weighted up. 411 | */ 412 | randomFloatHigh: function() 413 | { 414 | return 1-this.randomFloatLow(); 415 | }, 416 | 417 | /** 418 | * Returns a random RGB color. 419 | */ 420 | randomColor: function() 421 | { 422 | return { 423 | r:this.randomRange(0, 256), 424 | g:this.randomRange(0, 256), 425 | b:this.randomRange(0, 256), 426 | }; 427 | }, 428 | 429 | floatLerp: function(a, b, t) 430 | { 431 | return (b - a) * t + a; 432 | }, 433 | 434 | diagToPosition: function(diag, bounds) 435 | { 436 | var ortho = Math.floor(diag / Math.sqrt(2)); 437 | return new this.Vector(ortho, bounds.h - 1 - ortho); 438 | }, 439 | 440 | clamp: function(val, min, max) 441 | { 442 | return Math.min(max, Math.max(val, min)); 443 | }, 444 | 445 | hsvToRgb: function(color) 446 | { 447 | var c = color.v * color.s; 448 | var x = c * (1 - Math.abs((color.h / 60) % 2 - 1)); 449 | var m = color.v - c; 450 | if (color.h < 60) var outColor = { r: c, g: x, b: 0 }; 451 | else if (color.h < 120) var outColor = { r: x, g: c, b: 0 }; 452 | else if (color.h < 180) var outColor = { r: 0, g: c, b: x }; 453 | else if (color.h < 240) var outColor = { r: 0, g: x, b: c }; 454 | else if (color.h < 300) var outColor = { r: x, g: 0, b: c }; 455 | else var outColor = { r: c, g: 0, b: x }; 456 | outColor.r = Math.round((outColor.r + m) * 255); 457 | outColor.g = Math.round((outColor.g + m) * 255); 458 | outColor.b = Math.round((outColor.b + m) * 255); 459 | return outColor; 460 | }, 461 | 462 | colorLerp: function(a, b, t) 463 | { 464 | t = Math.max(0, Math.min(1, t)); 465 | var c = { 466 | r: (b.r - a.r) * t + a.r, 467 | g: (b.g - a.g) * t + a.g, 468 | b: (b.b - a.b) * t + a.b, 469 | }; 470 | var aa = a.a ? a.a : 1; 471 | var ba = b.a ? b.a : 1; 472 | c.a = (ba - aa) * t + aa; 473 | return c; 474 | }, 475 | 476 | colorDarken: function(color, t) 477 | { 478 | var c = { 479 | r: color.r * (1-t), 480 | g: color.g * (1-t), 481 | b: color.b * (1-t), 482 | } 483 | if (color.a !== undefined) c.a = color.a; 484 | return c; 485 | }, 486 | 487 | colorLighten: function(color, t) 488 | { 489 | t = 1-t; 490 | var c = { 491 | r: (1 - (1 - color.r/255) * t) * 255, 492 | g: (1 - (1 - color.g/255) * t) * 255, 493 | b: (1 - (1 - color.b/255) * t) * 255, 494 | } 495 | if (color.a !== undefined) c.a = color.a; 496 | return c; 497 | }, 498 | 499 | /** 500 | * Returns a random color where each channel is within maxamt/2 of the specified color. 501 | */ 502 | colorRandomize: function(color, maxamt) 503 | { 504 | var maxamtHalf = Math.floor(maxamt/2); 505 | var c = { 506 | r: Math.max(0, Math.min(255, color.r + this.randomRange(-maxamtHalf, maxamtHalf))), 507 | g: Math.max(0, Math.min(255, color.g + this.randomRange(-maxamtHalf, maxamtHalf))), 508 | b: Math.max(0, Math.min(255, color.b + this.randomRange(-maxamtHalf, maxamtHalf))), 509 | } 510 | if (color.a !== undefined) c.a = color.a; 511 | return c; 512 | }, 513 | 514 | /** 515 | * Returns a random color where each channel at least range/2 away from the specified color. 516 | */ 517 | colorInvertRandomize: function(color, range) 518 | { 519 | var c = { 520 | r: (color.r + Math.floor(range/2) + this.randomRange(0, 255-range)) % 256, 521 | g: (color.g + Math.floor(range/2) + this.randomRange(0, 255-range)) % 256, 522 | b: (color.b + Math.floor(range/2) + this.randomRange(0, 255-range)) % 256, 523 | } 524 | if (color.a !== undefined) c.a = color.a; 525 | return c; 526 | }, 527 | 528 | colorStr: function(color) 529 | { 530 | if (color.a !== undefined) 531 | return "rgba(" + Math.floor(color.r) + "," + Math.floor(color.g) + "," + Math.floor(color.b) + "," + color.a + ")"; 532 | else 533 | return "rgb(" + Math.floor(color.r) + "," + Math.floor(color.g) + "," + Math.floor(color.b) + ")"; 534 | }, 535 | 536 | handleCanvasClick: function(e) 537 | { 538 | if (this.tileDimension > 1) 539 | { 540 | this.configPreZoom = { 541 | seed: this.seedInput.value, 542 | tileDimension: this.tileDimensionSelect.value 543 | }; 544 | this.restoreConfigPreZoomButton.style.display = "initial"; 545 | var rect = this.canvas.getBoundingClientRect(); 546 | var localX = (e.clientX - rect.left) / this.displayScale; 547 | var localY = (e.clientY - rect.top) / this.displayScale; 548 | var tileX = Math.floor(localX / this.dimension); 549 | var tileY = Math.floor(localY / this.dimension); 550 | this.tileDimensionSelect.value = "1"; 551 | this.seedInput.value = this.tileSeeds[tileX + tileY * this.tileDimension]; 552 | this.setTileDimension(1); 553 | } 554 | }, 555 | 556 | notifyDisplayScaleChanged: function() 557 | { 558 | this.initialize(); 559 | this.clearConfigPreZoom(); 560 | this.setDisplayScale(parseFloat(this.displayScaleSelect.options[this.displayScaleSelect.selectedIndex].value)); 561 | }, 562 | 563 | notifySizeChanged: function() 564 | { 565 | this.initialize(); 566 | this.clearConfigPreZoom(); 567 | this.setDimension(parseInt(this.dimensionSelect.options[this.dimensionSelect.selectedIndex].value)); 568 | }, 569 | 570 | notifyTileDimensionChanged: function() 571 | { 572 | this.initialize(); 573 | this.clearConfigPreZoom(); 574 | this.setTileDimension(parseInt(this.tileDimensionSelect.options[this.tileDimensionSelect.selectedIndex].value)); 575 | }, 576 | 577 | notifyIconClassChanged: function() 578 | { 579 | this.initialize(); 580 | this.clearConfigPreZoom(); 581 | this.setIconClass(this.iconClassSelect.options[this.iconClassSelect.selectedIndex].value); 582 | }, 583 | 584 | notifySeedChanged: function() 585 | { 586 | this.initialize(); 587 | this.clearConfigPreZoom(); 588 | this.generateNewImage(); 589 | this.updateShareLink(); 590 | }, 591 | 592 | restoreConfigPreZoom: function() 593 | { 594 | if (this.configPreZoom) 595 | { 596 | this.restoreConfig(this.configPreZoom); 597 | this.clearConfigPreZoom(); 598 | } 599 | }, 600 | 601 | clearConfigPreZoom: function() 602 | { 603 | this.configPreZoom = null; 604 | this.restoreConfigPreZoomButton.style.display = "none"; 605 | }, 606 | 607 | restoreConfig: function(config) 608 | { 609 | //TODO: minimize rebuild calls 610 | if (config.dimension) 611 | { 612 | this.dimensionSelect.value = config.dimension; 613 | this.setDimension(parseInt(config.dimension)); 614 | } 615 | if (config.tileDimension) 616 | { 617 | this.tileDimensionSelect.value = config.tileDimension; 618 | this.setTileDimension(parseInt(config.tileDimension)); 619 | } 620 | if (config.iconClass) 621 | { 622 | this.iconClassSelect.value = config.iconClass; 623 | this.setIconClass(config.iconClass); 624 | } 625 | if (config.seed) 626 | { 627 | this.seedInput.value = config.seed; 628 | } 629 | this.generateNewImage(); 630 | }, 631 | 632 | updateShareLink: function() 633 | { 634 | if (this.shareLinkAnchor) 635 | { 636 | this.shareLinkAnchor.href = "/iconmachine?" 637 | + "dim=" + this.dimension 638 | + "&tiledim=" + this.tileDimension 639 | + "&class=" + this.iconClass 640 | + "&seed=" + this.seedInput.value; 641 | } 642 | }, 643 | 644 | setDisplayScale: function(scale) 645 | { 646 | this.initialize(); 647 | this.displayScale = scale; 648 | this.updateDisplayScale(); 649 | }, 650 | 651 | setDimension: function(dimension) 652 | { 653 | this.initialize(); 654 | this.dimension = dimension; 655 | this.resizeCanvas(); 656 | this.updateShareLink(); 657 | }, 658 | 659 | setTileDimension: function(tileDimension) 660 | { 661 | this.initialize(); 662 | this.tileDimension = tileDimension; 663 | this.canvas.style.cursor = this.tileDimension > 1 ? "pointer" : "inherit"; 664 | this.resizeCanvas(); 665 | this.updateShareLink(); 666 | }, 667 | 668 | setIconClass: function(iconClass) 669 | { 670 | this.initialize(); 671 | this.iconClass = iconClass; 672 | this.generateNewImage(); 673 | this.updateShareLink(); 674 | if (window.history) window.history.replaceState({}, "Icon Machine | " + this.iconClass, '/iconmachine?class=' + this.iconClass); 675 | }, 676 | 677 | resizeCanvas: function() 678 | { 679 | this.canvasParent.style.width = this.canvas.width = this.dimension * this.tileDimension; 680 | this.canvasParent.style.height = this.canvas.height = this.dimension * this.tileDimension; 681 | this.updateDisplayScale(); 682 | this.generateNewImage(); 683 | }, 684 | 685 | updateDisplayScale: function() 686 | { 687 | this.canvasParent.style.padding = (0.5 * this.canvas.width * (this.displayScale - 1)) + "px"; 688 | this.canvas.style.transform = "scale(" + this.displayScale + ")"; 689 | }, 690 | 691 | clearCanvas: function() 692 | { 693 | this.context.fillStyle = "rgba(0,0,0,1)"; 694 | this.context.clearRect(0, 0, this.canvas.width, this.canvas.height); 695 | }, 696 | 697 | drawPixel: function(x, y) 698 | { 699 | this.context.fillRect(Math.floor(x), Math.floor(y), 1, 1); 700 | }, 701 | 702 | /** 703 | * Adds a 1-pixel black border around the current drawing. 704 | */ 705 | addBorder: function(style) 706 | { 707 | style = style || "black"; 708 | 709 | var width = this.dimension; 710 | var height = this.dimension; 711 | 712 | var readData = this.context.getImageData(this.contextTranslation.x, this.contextTranslation.y, width, height); 713 | var mutableData = this.context.getImageData(this.contextTranslation.x, this.contextTranslation.y, width, height); 714 | for (var x = 0; x < width; x++) 715 | for (var y = 0; y < height; y++) 716 | { 717 | var pixelStart = (x + y * width) * 4; 718 | 719 | // if this pixel is empty or edge 720 | if (readData.data[pixelStart + 3] == 0 721 | || x == 0 || y == 0 || x == width - 1 || y == height - 1) 722 | { 723 | // and any orthogonal pixel isn't 724 | var nxPixStart = ((x-1) + y * width) * 4; 725 | var nyPixStart = (x + (y-1) * width) * 4; 726 | var pxPixStart = ((x+1) + y * width) * 4; 727 | var pyPixStart = (x + (y+1) * width) * 4; 728 | if (x > 0 && readData.data[nxPixStart + 3] > 0 729 | || x < width - 1 && readData.data[pxPixStart + 3] > 0 730 | || y > 0 && readData.data[nyPixStart + 3] > 0 731 | || y < height - 1 && readData.data[pyPixStart + 3] > 0) 732 | { 733 | // add black border pixel 734 | mutableData.data[pixelStart + 0] = 0; 735 | mutableData.data[pixelStart + 1] = 0; 736 | mutableData.data[pixelStart + 2] = 0; 737 | mutableData.data[pixelStart + 3] = 255; 738 | } 739 | } 740 | } 741 | this.context.putImageData(mutableData, this.contextTranslation.x, this.contextTranslation.y); 742 | }, 743 | 744 | generateNewImage: function() 745 | { 746 | this.initialize(); 747 | 748 | var seed = this.seedInput.value; 749 | 750 | // meta-rng 751 | var metaSeedGenerator = this.xmur3(seed); 752 | var metaRandom = this.sfc32(metaSeedGenerator(), metaSeedGenerator(), metaSeedGenerator(), metaSeedGenerator()); 753 | 754 | this.tileSeeds = []; 755 | 756 | for (var y = 0; y < this.tileDimension; y++) 757 | { 758 | for (var x = 0; x < this.tileDimension; x++) 759 | { 760 | var drawClass = this.iconClass; 761 | if (drawClass == "any") 762 | { 763 | var randomIndex = Math.floor(this.allClasses.length * metaRandom()); 764 | drawClass = this.allClasses[randomIndex]; 765 | } 766 | else if (drawClass == "anyweapon") 767 | { 768 | //HACK: magic numbers, hardcoded indices 769 | var randomIndex = 1 + Math.floor((this.allClasses.length - 1) * metaRandom()); 770 | drawClass = this.allClasses[randomIndex]; 771 | } 772 | 773 | this.seedRng(seed); 774 | this.tileSeeds.push(seed); 775 | 776 | this.translateContext(x * this.dimension, y * this.dimension); 777 | switch (drawClass) 778 | { 779 | case "potions": this.drawRandomPotion(); break; 780 | case "blades": this.drawRandomBlade(); break; 781 | case "spears": this.drawRandomSpear(); break; 782 | } 783 | this.translateContext(-x * this.dimension, -y * this.dimension); 784 | 785 | // next seed 786 | seed = this.createRandomSeed(metaRandom); 787 | } 788 | } 789 | }, 790 | 791 | drawRandomPotion: function() 792 | { 793 | this.initialize(); 794 | this.checkpointRng(); 795 | 796 | var width = this.dimension; 797 | var height = this.dimension; 798 | var dscale = height / 32; 799 | var centerXL = width/2-1; 800 | 801 | this.clearCanvas(); 802 | 803 | // height of bottle lip 804 | var lipHeight = Math.ceil(this.randomRange(2, 5) * dscale); 805 | // height of stopper sticking out of bottle 806 | var stopperTopHeight = Math.ceil(this.randomRange(2, 5) * dscale); 807 | // depth of stopper into the bottle 808 | var stopperDepth = this.randomRange(lipHeight + 1, lipHeight + Math.round(4 * dscale)); 809 | // width of stopper inside bottle 810 | var stopperWidth = Math.ceil(this.randomRange(2, 6) * dscale) * 2; 811 | // width of bottle neck 812 | var neckWidth = stopperWidth + 2; 813 | // width of bottle lip 814 | var lipWidth = neckWidth + Math.ceil(this.randomRange(2, 4) * dscale) * 2; 815 | // width of outer stopper 816 | var stopperTopWidth = Math.min(stopperWidth + 2, lipWidth - 2); 817 | // top of stopper 818 | var stopperTop = 2; 819 | // top of lip 820 | var lipTop = stopperTop + stopperTopHeight; 821 | // top of neck 822 | var neckTop = lipTop + lipHeight; 823 | // bottom of bottle 824 | var bottleBottom = height - 2; 825 | // fluid start 826 | var fluidTop = neckTop + this.randomRange(height/8, (bottleBottom-neckTop)*0.6); 827 | // min dist between contour changes 828 | var contourInterval = Math.round(4 * dscale); 829 | 830 | var stopperLight = { r:222, g:152, b:100 }; 831 | var stopperDark = { r:118, g:49, b:0 }; 832 | 833 | var innerBorderLight = { r:213, g:226, b:239 }; 834 | var innerBorderDark = { r:181, g:196, b:197 }; 835 | 836 | var glassLight = { r:227, g:244, b:248, a: 165/255 }; 837 | var glassDark = { r:163, g:187, b:199, a: 165/255 }; 838 | 839 | var fluidColor = this.randomColor(); 840 | var fluidColor2 = this.colorRandomize(fluidColor, 300); 841 | 842 | // generate shape of neck/body 843 | var contour = []; 844 | contour[neckTop] = neckWidth/2; 845 | var velocity = 0; 846 | var acceleration = 0; 847 | var direction = 1; 848 | var bodyTop = neckTop + 1; 849 | for (var b = bodyTop; b <= bottleBottom; b++) 850 | { 851 | var d = Math.floor(velocity); 852 | velocity += acceleration; 853 | contour[b] = Math.max(neckWidth/2, Math.min(width/2-2, contour[b-1]+d)); 854 | 855 | if (b % contourInterval == 0 && this.randomFloat()<=0.5) 856 | { 857 | //velocity = direction*this.randomRange(0,11)/2; 858 | acceleration = direction*this.randomRange(0,5)/2; 859 | direction = -direction; 860 | } 861 | } 862 | 863 | // draw outer stopper 864 | var stopperLeft = centerXL - stopperTopWidth/2 + 1; 865 | for (var x = 0; x < stopperTopWidth; x++) 866 | { 867 | var n = (x / (stopperTopWidth - 1))-0.5; 868 | this.context.fillStyle = this.colorStr(this.colorLerp(stopperLight, stopperDark, n)); 869 | this.context.fillRect(x + stopperLeft, stopperTop, 1, stopperTopHeight); 870 | } 871 | 872 | // draw body 873 | var previousContour = lipWidth; 874 | for (var y = neckTop; y < contour.length; y++) 875 | { 876 | var contourWidth = contour[y]*2; 877 | 878 | // draw fluid 879 | if (y >= fluidTop) 880 | { 881 | var vn = (y - fluidTop) / (bottleBottom - fluidTop); 882 | var left = centerXL - contourWidth/2; 883 | for (var x = 1; x < contourWidth; x++) 884 | { 885 | var n = x/(contourWidth-1)-(0.5+this.randomFloat()*0.1); 886 | this.context.fillStyle = this.colorStr( 887 | this.colorLerp( 888 | this.colorLerp(fluidColor, fluidColor2, vn), 889 | this.colorLerp(this.colorDarken(fluidColor, 1), this.colorDarken(fluidColor2, 1), vn), 890 | n)); 891 | this.drawPixel(left + x, y); 892 | } 893 | } 894 | 895 | // draw glass 896 | if (y >= neckTop && y <= fluidTop) 897 | { 898 | var left = centerXL - contourWidth/2; 899 | for (var x = 1; x < contourWidth; x++) 900 | { 901 | var n = x/(contourWidth-1); 902 | this.context.fillStyle = this.colorStr(this.colorLerp(glassLight, glassDark, n)); 903 | this.drawPixel(left + x, y); 904 | } 905 | } 906 | 907 | if (contourWidth == previousContour) 908 | { 909 | // contour is the same 910 | this.context.fillStyle = this.colorStr(innerBorderLight); 911 | this.drawPixel(centerXL - contourWidth/2 + 1, y); 912 | this.context.fillStyle = this.colorStr(innerBorderDark); 913 | this.drawPixel(centerXL + contourWidth/2, y); 914 | } 915 | else 916 | { 917 | var yOff = previousContour < contourWidth ? y-1 : y; 918 | var yInner = previousContour < contourWidth ? y : y-1; 919 | var minContour = Math.min(contourWidth, previousContour); 920 | var lineWidth = Math.abs(previousContour - contourWidth)/2; 921 | var lineOffset = lineWidth-1; 922 | this.context.fillStyle = this.colorStr(innerBorderLight); 923 | this.context.fillRect(centerXL - minContour/2 - lineWidth + 1, yInner, lineWidth, 1); 924 | this.drawPixel(centerXL - contourWidth/2 + 1, y); 925 | this.context.fillStyle = this.colorStr(innerBorderDark); 926 | this.context.fillRect(centerXL + minContour/2 + 1, yInner, lineWidth, 1); 927 | this.drawPixel(centerXL + contourWidth/2, y); 928 | } 929 | 930 | previousContour = contourWidth; 931 | } 932 | 933 | // draw overlay stuff 934 | var previousContour = lipWidth; 935 | for (var y = neckTop; y < contour.length; y++) 936 | { 937 | var contourWidth = contour[y]*2; 938 | 939 | // draw top-left reflection 940 | if (previousContour < contourWidth) 941 | { 942 | var reflectWidth = Math.max(1, contourWidth - previousContour); 943 | 944 | // crunch toward middle 945 | var crunch = 1 - 0.3 * contourWidth / width; 946 | var reflectOffset = Math.round((2 - contourWidth/2) * crunch); 947 | 948 | this.context.save(); 949 | this.context.globalCompositeOperation = "soft-light"; 950 | this.context.fillStyle = "white"; 951 | this.context.fillRect(centerXL + reflectOffset, y + 2, reflectWidth * crunch, 1); 952 | this.context.restore(); 953 | } 954 | 955 | previousContour = contourWidth; 956 | } 957 | 958 | // draw inner stopper 959 | var stopperInnerLeft = centerXL - stopperWidth/2 + 1; 960 | for (var x = 0; x < stopperWidth; x++) 961 | { 962 | var n = (x / (stopperWidth - 1))-0.5; 963 | this.context.fillStyle = this.colorStr(this.colorLerp(stopperLight, stopperDark, n)); 964 | this.context.fillRect(x + stopperInnerLeft, lipTop, 1, stopperDepth); 965 | } 966 | 967 | // draw lip (over stopper) 968 | var lipLeft = centerXL - lipWidth/2 + 1; 969 | this.context.fillStyle = this.colorStr(innerBorderLight); 970 | this.context.fillRect(lipLeft, lipTop, 1, lipHeight); 971 | this.context.fillStyle = this.colorStr(innerBorderDark); 972 | this.context.fillRect(lipLeft + lipWidth - 1, lipTop, 1, lipHeight); 973 | for (var x = 1; x < lipWidth-1; x++) 974 | { 975 | var n = ((x-1) / (lipWidth-3))-0.5; 976 | this.context.fillStyle = this.colorStr(this.colorLerp(glassLight, glassDark, n)); 977 | this.context.fillRect(x + lipLeft, lipTop, 1, lipHeight); 978 | } 979 | 980 | // draw bottom border 981 | var borderLeft = centerXL - contour[bottleBottom] + 1; 982 | var borderWidth = contour[bottleBottom]*2; 983 | for (var x = 0; x < borderWidth; x++) 984 | { 985 | var n = (x/(borderWidth-1))-0.5; 986 | this.context.fillStyle = this.colorStr(this.colorLerp(innerBorderLight, innerBorderDark, n)); 987 | this.drawPixel(borderLeft + x, bottleBottom); 988 | } 989 | 990 | this.addBorder(); 991 | }, 992 | 993 | drawRandomBlade: function() 994 | { 995 | //TODO: 996 | //- serration 997 | 998 | //TODO: make sure everything is dimensionally scaled 999 | 1000 | this.initialize(); 1001 | this.checkpointRng(); 1002 | 1003 | var bounds = new this.Bounds(0, 0, this.dimension, this.dimension); 1004 | var bounds1 = new this.Bounds(1, 1, bounds.w - 2, bounds.h - 2); 1005 | var dscale = bounds.h / 32; 1006 | 1007 | this.clearCanvas(); 1008 | 1009 | // length of the pommel 1010 | var pommelLength = Math.ceil(this.randomFloatLow() * 2 * dscale); 1011 | // length of the hilt 1012 | var hiltLength = Math.ceil(this.randomRange(6, 11) * dscale); 1013 | // width of the xguard 1014 | var xguardWidth = Math.ceil(this.randomRange(1, 4) * dscale); 1015 | 1016 | // draw the blade 1017 | var bladeParams = { 1018 | startDiag: pommelLength + hiltLength + xguardWidth, 1019 | taperFactor: this.randomFloatLow(), 1020 | startRadius: Math.ceil(this.randomRange(2, 4) * dscale) 1021 | }; 1022 | var bladeResults = this.drawBladeHelper(bladeParams); 1023 | 1024 | // draw the hilt 1025 | var hiltStartDiag = Math.floor(pommelLength * Math.sqrt(2)); 1026 | var hiltParams = { 1027 | startDiag: hiltStartDiag, 1028 | lengthDiag: Math.floor(bladeResults.startOrtho - hiltStartDiag), 1029 | maxRadius: bladeResults.startRadius, 1030 | fractionalRadiusAllowed: false 1031 | }; 1032 | this.drawGripHelper(hiltParams); 1033 | 1034 | // draw the crossguard 1035 | var crossguardParams = { 1036 | positionDiag: bladeResults.startOrtho, 1037 | halfLength: bladeResults.startRadius * (1 + 2*this.randomFloatLow()) + 1 1038 | }; 1039 | var crossguardResults = this.drawCrossguardHelper(crossguardParams); 1040 | 1041 | // draw the pommel 1042 | var pommelRadius = pommelLength * Math.sqrt(2) / 2; 1043 | var pommelParams = { 1044 | center: new this.Vector(Math.floor(pommelRadius + 1), Math.ceil(bounds.h - pommelRadius - 2)), 1045 | radius: pommelRadius, 1046 | colorLight: crossguardResults.colorLight, 1047 | colorDark: crossguardResults.colorDark 1048 | }; 1049 | this.drawRoundOrnamentHelper(pommelParams); 1050 | 1051 | this.addBorder(); 1052 | }, 1053 | 1054 | drawRandomSpear: function() 1055 | { 1056 | //TODO: 1057 | //- ribbons 1058 | //- better taper on points 1059 | //- fix discontiguous crossguards 1060 | //- possible center element in large pommel 1061 | //- more, wilder crossguards 1062 | 1063 | //TODO: make sure everything is dimensionally scaled 1064 | 1065 | this.initialize(); 1066 | this.checkpointRng(); 1067 | 1068 | var bounds = new this.Bounds(0, 0, this.dimension, this.dimension); 1069 | var bounds1 = new this.Bounds(1, 1, bounds.w - 2, bounds.h - 2); 1070 | var canvasDiag = Math.sqrt(bounds.w * bounds.w + bounds.h * bounds.h); 1071 | var dscale = bounds.h / 32; 1072 | 1073 | this.clearCanvas(); 1074 | 1075 | var gripLengthMin = 8; 1076 | // length of the tip 1077 | var tipLength = Math.ceil(this.randomRange(10, 20) * dscale); 1078 | // diagonal start of the tip 1079 | var tipStartDiag = canvasDiag - tipLength; 1080 | // diagonal start of the grip 1081 | var gripStartDiag = Math.ceil(this.randomRange(0, tipStartDiag - gripLengthMin)); 1082 | // length of the grip 1083 | var gripLength = Math.ceil(this.randomRange(gripLengthMin, tipStartDiag - gripStartDiag) * dscale); 1084 | 1085 | // draw the tip 1086 | var tipParams = { 1087 | startDiag: tipStartDiag, 1088 | taperFactor: this.randomFloat() * 0.5 + 0.5, 1089 | startRadius: Math.ceil(this.randomRange(1, 2) * dscale) 1090 | }; 1091 | var tipResults = this.drawBladeHelper(tipParams); 1092 | 1093 | // draw the haft 1094 | var haftParams = { 1095 | startDiag: 0, 1096 | lengthDiag: tipStartDiag, 1097 | maxRadius: tipResults.startRadius * 2, 1098 | fractionalRadiusAllowed: true 1099 | }; 1100 | if (this.randomFloat() > 0.95) 1101 | { 1102 | haftParams.color = tipResults.hiltColor; 1103 | } 1104 | var haftResults = this.drawHaftHelper(haftParams); 1105 | 1106 | // draw the grip 1107 | if (this.randomFloat() > 0.65) 1108 | { 1109 | var gripParams = { 1110 | startDiag: gripStartDiag, 1111 | lengthDiag: gripLength / Math.sqrt(2), //HACK: 1112 | minRadius: haftResults.radius, 1113 | maxRadius: haftResults.radius, 1114 | fractionalRadiusAllowed: true 1115 | }; 1116 | this.drawGripHelper(gripParams); 1117 | } 1118 | 1119 | // draw the crossguard 1120 | if (this.randomFloat() > 0.4) 1121 | { 1122 | var crossguardParams = { 1123 | positionDiag: tipResults.startOrtho, 1124 | halfLength: tipResults.startRadius * (1 + 8 * this.randomFloatExtreme()) + 4, 1125 | omegaChance: 0.4, 1126 | omegaAmount: Math.PI/10, 1127 | thickness: this.randomRangeFloat(1, 2) 1128 | }; 1129 | var crossguardResults = this.drawCrossguardHelper(crossguardParams); 1130 | } 1131 | 1132 | // draw ribbon(s) 1133 | var ribbonCount = this.randomRangeLow(0, 4); 1134 | for (var ribbonIndex = 0; ribbonIndex < ribbonCount; ++ribbonIndex) 1135 | { 1136 | //TODO: 1137 | } 1138 | 1139 | // draw pommel 1140 | if (this.randomFloat() > 0.4) 1141 | { 1142 | var pommelRadius = Math.ceil((0.5 + this.randomFloatLow() * 0.5) * dscale); 1143 | var pommelParams = { 1144 | center: new this.Vector(Math.floor(pommelRadius), Math.ceil(bounds.h - pommelRadius - 1)), 1145 | radius: pommelRadius 1146 | }; 1147 | 1148 | if (crossguardResults && this.randomFloat() > 0.5) 1149 | { 1150 | // match crossguard colors 1151 | pommelParams.colorLight = crossguardResults.colorLight; 1152 | pommelParams.colorDark = crossguardResults.colorDark; 1153 | } 1154 | else 1155 | { 1156 | // generate new colors 1157 | pommelParams.colorLight = this.hsvToRgb({ h: this.randomRange(0, 360), s: this.randomFloat(), v: this.randomRangeFloat(0, 1) }); 1158 | } 1159 | 1160 | //HACK: erase haft that might go below pommel 1161 | //HACK: off by one? 1162 | this.context.clearRect(-1, bounds.h, pommelRadius + 1, -(pommelRadius + 1)); 1163 | 1164 | this.drawRoundOrnamentHelper(pommelParams); 1165 | } 1166 | 1167 | // draw crossguard device 1168 | if (this.randomFloat() > 0.55) 1169 | { 1170 | var deviceRadius = Math.ceil((0.5 + this.randomFloatLow() * 1.5) * dscale); 1171 | var deviceParams = { 1172 | center: this.diagToPosition(haftParams.startDiag + haftParams.lengthDiag - Math.floor(deviceRadius / 2), bounds), 1173 | radius: deviceRadius 1174 | }; 1175 | 1176 | if (crossguardResults && this.randomFloat() > 0.4) 1177 | { 1178 | // match crossguard colors 1179 | deviceParams.colorLight = crossguardResults.colorLight; 1180 | deviceParams.colorDark = crossguardResults.colorDark; 1181 | } 1182 | else 1183 | { 1184 | // generate new colors 1185 | deviceParams.colorLight = this.hsvToRgb({ h: this.randomRange(0, 360), s: this.randomFloat(), v: this.randomRangeFloat(0, 1) }); 1186 | } 1187 | 1188 | this.drawRoundOrnamentHelper(deviceParams); 1189 | } 1190 | 1191 | this.addBorder(); 1192 | }, 1193 | 1194 | // Helper function that draws a blade with parameters 1195 | // The blade is oriented from the bottom-left corner of the tile to the top-right 1196 | // Parameters: 1197 | // - (required) startDiag: The distance from the bottom-left corner to the base of the blade 1198 | // - (required) taperFactor: Determines the angle of the taper of the blade tip (as a ratio of the blade length) 1199 | // - (required) startRadius: The radius of the base of the blade 1200 | //TODO: expose more properties 1201 | // Returns an object containing: 1202 | // - startDiag: The distance from the bottom-left corner to the base of the blade 1203 | // - startOrtho: The distance from the left and bottom edges to the base of the blade 1204 | // - startRadius: The radius of the blade at its base 1205 | // - hiltColor: The basic tint color of the blade at the hilt 1206 | // - tipColor: The basic tint color of the blade at the tip 1207 | //TODO: return more info 1208 | drawBladeHelper: function(params) 1209 | { 1210 | this.checkpointRng(); 1211 | 1212 | var bounds = new this.Bounds(0, 0, this.dimension, this.dimension); 1213 | var bounds1 = new this.Bounds(1, 1, bounds.w - 2, bounds.h - 2); 1214 | var dscale = bounds.h / 32; 1215 | 1216 | // minimum blade width 1217 | var minimumBladeWidth = 1; 1218 | // size of each step in sampling the blade curve 1219 | var bladeSampleStepSize = Math.sqrt(2); 1220 | // width of the lighter edge pixels 1221 | var bladeEdgeWidth = 1; 1222 | // minimum width of the blade core before edge can be drawn 1223 | var bladeCoreEdgeExcludeWidth = 1; 1224 | // chance of the blade aquiring a random jog (per pixel) 1225 | var bladeJogChance = 0.04; 1226 | // chance to jog is reduced during the first this many pixels 1227 | var bladeJogChanceLeadIn = Math.ceil(12 * dscale); 1228 | // max magnitude of a blade jog 1229 | var bladeJogAmount = Math.PI / 4; 1230 | // chance of the blade acquiring a curve (per pixel) 1231 | var bladeOmegaChance = 0.02; 1232 | // max magnitude of blade omega add 1233 | var bladeOmegaAmount = Math.PI / 32; 1234 | // maximum absolute omega 1235 | var bladeMaxOmega = Math.PI / 32; 1236 | 1237 | // amplitude of the cosine wave applied to blade width 1238 | var bladeWidthCosineAmp = Math.ceil(Math.max(0, this.randomFloatLow()*1.2-0.2) * 2 * dscale); 1239 | // wavelength of the cosine wave applied to blade width 1240 | var bladeWidthCosineWavelength = Math.ceil(this.randomRange(3 * Math.max(1, bladeWidthCosineAmp), 12) * dscale); 1241 | // offset of the cosine wave applied to blade width 1242 | var bladeWidthCosineOffset = this.randomRangeFloat(0, Math.PI * 2); 1243 | 1244 | // amplitude of the blade core wiggle curve 1245 | var bladeWiggleAmp = Math.max(0, this.randomFloat()*8-7) * Math.PI/4 * dscale; 1246 | // wavelength of the blade core wiggle curve 1247 | var bladeWiggleWavelength = Math.ceil(this.randomRangeFloat(6, 18) * dscale); 1248 | 1249 | // produce blade shape 1250 | var bladeCorePoints = []; 1251 | var bladeStartOrtho = Math.floor(params.startDiag / Math.sqrt(2)); 1252 | var currentPoint = new this.Vector(bladeStartOrtho, bounds.h - 1 - bladeStartOrtho); 1253 | var currentDist = 0; 1254 | var currentWidthL = params.startRadius; 1255 | var currentWidthR = params.startRadius + this.randomRange(-1, 2); 1256 | var velocity = new this.Vector(); 1257 | var velocityScaled = new this.Vector(); 1258 | var angle = -Math.PI / 4; 1259 | var omega = 0; // velocity rotation in radians per pixel 1260 | do 1261 | { 1262 | var bladeWidthCosine = bladeWidthCosineAmp * Math.cos(bladeWidthCosineOffset + currentDist / bladeWidthCosineWavelength); 1263 | var useAngle = angle + bladeWiggleAmp * Math.sin(Math.PI * 2 * currentDist/bladeWiggleWavelength); 1264 | velocity.set(Math.cos(useAngle), Math.sin(useAngle)); 1265 | 1266 | var newPoint = new this.Vector(currentPoint); 1267 | newPoint.widthL = Math.max(1, currentWidthL + bladeWidthCosine); 1268 | newPoint.widthR = Math.max(1, currentWidthR + bladeWidthCosine); 1269 | newPoint.normal = new this.Vector(-velocity.y, velocity.x).normalize(); 1270 | newPoint.forward = new this.Vector(velocity).normalize(); 1271 | newPoint.dist = currentDist; 1272 | bladeCorePoints.push(newPoint); 1273 | 1274 | if (this.randomFloat() <= bladeJogChance * Math.min(1, currentDist/bladeJogChanceLeadIn)) 1275 | { 1276 | angle += this.randomRangeFloat(-bladeJogAmount, bladeJogAmount); 1277 | } 1278 | if (this.randomFloat() <= bladeOmegaChance) 1279 | { 1280 | omega += this.randomRangeFloat(-bladeOmegaAmount, bladeOmegaAmount); 1281 | omega = Math.sign(omega) * Math.min(bladeMaxOmega, Math.abs(omega)); 1282 | } 1283 | 1284 | velocityScaled.set(velocity).multiplyScalar(bladeSampleStepSize); 1285 | currentPoint.addVector(velocityScaled); 1286 | currentDist += bladeSampleStepSize; 1287 | angle += omega * bladeSampleStepSize; 1288 | } while(bounds1.contains(currentPoint)); 1289 | // blade core postprocessing 1290 | for (var i = 0; i < bladeCorePoints.length; i++) 1291 | { 1292 | // calculate normalized distance 1293 | bladeCorePoints[i].normalizedDist = bladeCorePoints[i].dist / currentDist; 1294 | 1295 | // apply taper 1296 | var invTaperFactor = 1 - params.taperFactor; 1297 | var taper = bladeCorePoints[i].normalizedDist <= invTaperFactor 1298 | ? 1 1299 | : (1-bladeCorePoints[i].normalizedDist) / params.taperFactor; 1300 | bladeCorePoints[i].widthL *= taper; 1301 | bladeCorePoints[i].widthR *= taper; 1302 | } 1303 | 1304 | // forward-axis color of the blade at the tip 1305 | var colorBladeLinearTipHsv = { 1306 | h: this.randomRangeFloat(0, 360), 1307 | s: this.randomFloat() < 0.3 ? this.randomFloatExtreme() * 0.6 : 0, 1308 | v: this.randomRangeFloat(0.75, 1) 1309 | }; 1310 | var colorBladeLinearTip = this.hsvToRgb(colorBladeLinearTipHsv); 1311 | // forward-axis color of the blade at the hilt 1312 | var colorBladeLinearHilt = this.colorRandomize(this.colorDarken(colorBladeLinearTip, 0.7), 16); 1313 | // amount to lighten blade edge 1314 | var bladeEdgeLighten = 0.5; 1315 | // amount to darken blade far half 1316 | var bladeRightDarken = 0.5; 1317 | 1318 | // draw blade 1319 | for (var x = 0; x < bounds.w; x++) 1320 | for (var y = 0; y < bounds.h; y++) 1321 | { 1322 | // never draw behind first core point 1323 | var dotProduct = bladeCorePoints[0].forward.dotProduct(x - bladeCorePoints[0].x, y - bladeCorePoints[0].y); 1324 | if (dotProduct < 0) continue; 1325 | 1326 | // find the minimum distance to the blade core 1327 | //OPT: obviously inefficient 1328 | var coreDistanceNorm = Infinity; 1329 | var bestPoint = null; 1330 | for (var i = 0; i < bladeCorePoints.length; i++) 1331 | { 1332 | // normalizes distance based on width 1333 | var corePoint = bladeCorePoints[i]; 1334 | var dotProduct = corePoint.normal.dotProduct(x - corePoint.x, y - corePoint.y); 1335 | var useWidth = dotProduct < 0 ? corePoint.widthL : corePoint.widthR; 1336 | var distanceNorm = corePoint.distanceTo(x, y) / useWidth; 1337 | if (distanceNorm < coreDistanceNorm) 1338 | { 1339 | coreDistanceNorm = distanceNorm; 1340 | bestPoint = bladeCorePoints[i]; 1341 | } 1342 | } 1343 | if (bestPoint == null) continue; 1344 | 1345 | var dotProduct = bestPoint.normal.dotProduct(x - bestPoint.x + 0.5, y - bestPoint.y + 0.5); 1346 | var useWidth = dotProduct < 0 ? bestPoint.widthL : bestPoint.widthR; 1347 | var coreDistance = bestPoint.distanceTo(x, y); 1348 | if (coreDistance <= useWidth 1349 | || coreDistance <= minimumBladeWidth) 1350 | { 1351 | var color = this.colorLerp(colorBladeLinearHilt, colorBladeLinearTip, bestPoint.normalizedDist); 1352 | 1353 | // do not change core 1354 | //if (bestPoint.x == x && bestPoint.y == y) 1355 | //{ } 1356 | //else 1357 | { 1358 | var edgeColor = this.colorLighten(color, bladeEdgeLighten); 1359 | var darkColor = this.colorDarken(color, bladeRightDarken); 1360 | var nonEdgeColor = dotProduct > 0 ? darkColor : color; 1361 | // lighten edge 1362 | if (useWidth > bladeCoreEdgeExcludeWidth) 1363 | { 1364 | var edgeWidthMin = useWidth - bladeEdgeWidth; 1365 | var edgeAmount = (coreDistance - edgeWidthMin) / bladeEdgeWidth; 1366 | edgeAmount = 1 - (1-edgeAmount)*(1-edgeAmount); 1367 | color = this.colorLerp(nonEdgeColor, edgeColor, edgeAmount); 1368 | } 1369 | } 1370 | 1371 | this.context.fillStyle = this.colorStr(color); 1372 | this.drawPixel(x, y); 1373 | } 1374 | } 1375 | 1376 | return { 1377 | startDiag: params.startDiag, 1378 | startOrtho: bladeStartOrtho, 1379 | startRadius: params.startRadius, 1380 | hiltColor: colorBladeLinearHilt, 1381 | tipColor: colorBladeLinearTip 1382 | }; 1383 | }, 1384 | 1385 | // Helper function that draws a crossguard with parameters 1386 | // The crossguard is oriented perpendicular to the diagonal from the bottom-left corner of the tile to the top-right 1387 | // Parameters: 1388 | // - (required) positionDiag: The distance from the bottom-left corner to the origin of the crossguard 1389 | // - (required) halfLength: Half the length of the crossguard 1390 | // - (optional) omegaChance: Chance for the xguard to acquire a curve (per pixel) 1391 | // - (optional) omegaAmount: Max magnitude of xguard omega add 1392 | // - (optional) thickness: The thickness of the xguard 1393 | //TODO: expose more properties 1394 | // Returns an object containing: 1395 | // - colorLight: The light color of the crossguard 1396 | // - colorDark: The dark color of the crossguard 1397 | drawCrossguardHelper: function(params) 1398 | { 1399 | this.checkpointRng(); 1400 | 1401 | var bounds = new this.Bounds(0, 0, this.dimension, this.dimension); 1402 | var dscale = bounds.h / 32; 1403 | 1404 | // the color of the xguard 1405 | var xguardColorLight = this.hsvToRgb({ h: this.randomRange(0, 360), s: this.randomFloatLow()*0.5, v: this.randomRangeFloat(0.7, 1) }); 1406 | // the shadow color of the xguard 1407 | var xguardColorDark = this.colorDarken(xguardColorLight, 0.6); 1408 | // the amount of symmetry for the xguard 1409 | var xguardSymmetry = this.randomFloat() < 0.3 ? 0 : 1; 1410 | // the thickness of the xguard 1411 | var xguardThickness = params.thickness || this.randomRangeFloatHigh(1, 2.5); 1412 | // the bottom taper of the xguard 1413 | var xguardBottomTaper = this.randomFloat(); 1414 | // the top taper of the xguard 1415 | var xguardTopTaper = this.floatLerp(this.randomFloat(), xguardBottomTaper, this.randomFloatExtreme()); 1416 | // chance for the xguard to acquire a curve (per pixel) 1417 | var xguardOmegaChance = params.omegaChance || 0.3; 1418 | // max magnitude of xguard omega add 1419 | var xguardOmegaAmount = params.omegaAmount || (Math.PI/8); 1420 | // maximum absolute xguard omega 1421 | var xguardMaxOmega = (0 + (xguardThickness-1)^2) * Math.PI/7; 1422 | // number of steps after an omega change before another can be added 1423 | var xguardOmegaCooldown = 3; 1424 | // size of each step in sampling the xguard curve 1425 | var xguardSampleStepSize = Math.sqrt(2); 1426 | 1427 | // produce xguard shape 1428 | var currentPoint = new this.Vector(params.positionDiag, bounds.h - 1 - params.positionDiag); 1429 | currentPoint = [currentPoint, new this.Vector(currentPoint)]; 1430 | var xguardControlPoints = [[],[]]; 1431 | var xguardAngle = [-Math.PI * 3/4, Math.PI/4]; 1432 | var xguardOmega = [0,0]; 1433 | var xguardOmegaCoolTimer = [0,0]; 1434 | var deltaStep = xguardSampleStepSize / Math.sqrt(2); //HACK: divide for back compat 1435 | for (var xguardProgress = 0; xguardProgress <= params.halfLength; xguardProgress += xguardSampleStepSize) 1436 | { 1437 | for (var side = 0; side <= 1; side++) 1438 | { 1439 | var velocity = new this.Vector(Math.cos(xguardAngle[side]), Math.sin(xguardAngle[side])); 1440 | 1441 | var newPoint = new this.Vector(currentPoint[side]); 1442 | if (side == 1) 1443 | { 1444 | var symmetricPoint = new this.Vector(bounds.h - 1 - currentPoint[0].y, bounds.w - 1 - currentPoint[0].x); 1445 | newPoint.lerpTo(symmetricPoint, xguardSymmetry); 1446 | } 1447 | newPoint.widthT = xguardThickness/2; 1448 | newPoint.widthB = xguardThickness/2; 1449 | newPoint.normal = new this.Vector(velocity.y, -velocity.x).multiplyScalar(side*2-1); 1450 | newPoint.dist = xguardProgress; 1451 | xguardControlPoints[side].push(newPoint); 1452 | } 1453 | for (var side = 0; side <= 1; side++) 1454 | { 1455 | var velocity = new this.Vector(Math.cos(xguardAngle[side]), Math.sin(xguardAngle[side])); 1456 | 1457 | xguardOmegaCoolTimer[side] -= xguardSampleStepSize; 1458 | if (xguardOmegaCoolTimer[side] <= 0 && this.randomFloat() < xguardOmegaChance) 1459 | { 1460 | xguardOmegaCoolTimer[side] = xguardOmegaCooldown; 1461 | xguardOmega[side] += this.randomRangeFloatExtreme(-xguardOmegaAmount, xguardOmegaAmount); 1462 | xguardOmega[side] = Math.sign(xguardOmega[side]) * Math.min(xguardMaxOmega, Math.abs(xguardOmega[side])); 1463 | } 1464 | 1465 | var xguardStep = new this.Vector(velocity).multiplyScalar(xguardSampleStepSize); 1466 | currentPoint[side].addVector(xguardStep); 1467 | xguardAngle[side] += xguardOmega[side] * deltaStep; 1468 | } 1469 | } 1470 | // xguard core postprocessing 1471 | for (var side = 0; side <= 1; side++) 1472 | { 1473 | var controlPoints = xguardControlPoints[side]; 1474 | for (var i = 0; i < controlPoints.length; i++) 1475 | { 1476 | // calculate normalized distance 1477 | controlPoints[i].normalizedDist = controlPoints[i].dist / params.halfLength; 1478 | 1479 | // apply taper 1480 | controlPoints[i].widthT *= Math.min(1, (1 - controlPoints[i].normalizedDist) / xguardTopTaper); 1481 | controlPoints[i].widthB *= Math.min(1, (1 - controlPoints[i].normalizedDist) / xguardBottomTaper); 1482 | } 1483 | } 1484 | 1485 | // draw xguard 1486 | for (var x = 0; x < bounds.w; x++) 1487 | for (var y = 0; y < bounds.h; y++) 1488 | { 1489 | // find the minimum distance to the xguard core 1490 | //OPT: obviously inefficient 1491 | var coreDistanceSq = Infinity; 1492 | var bestPoint = null; 1493 | for (var side = 0; side <= 1; side++) 1494 | { 1495 | var controlPoints = xguardControlPoints[side]; 1496 | for (var i = 0; i < controlPoints.length; i++) 1497 | { 1498 | var distanceSq = controlPoints[i].distanceToSq(x, y); 1499 | if (distanceSq < coreDistanceSq) 1500 | { 1501 | coreDistanceSq = distanceSq; 1502 | bestPoint = controlPoints[i]; 1503 | } 1504 | } 1505 | } 1506 | 1507 | var dotProduct = bestPoint.normal.dotProduct(x - bestPoint.x, y - bestPoint.y); 1508 | var useWidth = dotProduct < 0 ? bestPoint.widthB : bestPoint.widthT; 1509 | var coreDistance = Math.sqrt(coreDistanceSq); 1510 | if (coreDistance <= useWidth) 1511 | { 1512 | var distFromTop = dotProduct < 0 ? bestPoint.widthT + coreDistance : bestPoint.widthT - coreDistance; 1513 | var darkAmt = distFromTop / (bestPoint.widthB + bestPoint.widthT); 1514 | this.context.fillStyle = this.colorStr(this.colorLerp(xguardColorLight, xguardColorDark, darkAmt)); 1515 | this.drawPixel(x, y); 1516 | } 1517 | } 1518 | 1519 | return { 1520 | colorLight: xguardColorLight, 1521 | colorDark: xguardColorDark 1522 | }; 1523 | }, 1524 | 1525 | // Helper function that draws a grip with parameters 1526 | // The grip is oriented from the bottom-left corner of the canvas to the top-right 1527 | // Parameters: 1528 | // - startDiag (required): The distance from the bottom-left corner to the start of the grip 1529 | // - lengthDiag (required): The length of the grip 1530 | // - minRadius (optional): The minimum radius of the grip 1531 | // - maxRadius (required): The maximum radius of the grip 1532 | // - fractionalRadiusAllowed (optional): Allow fractional radius? (won't be centered) 1533 | //TODO: expose more parameters 1534 | drawGripHelper: function(params) 1535 | { 1536 | this.checkpointRng(); 1537 | 1538 | var bounds = new this.Bounds(0, 0, this.dimension, this.dimension); 1539 | var dscale = bounds.h / 32; 1540 | 1541 | // the radius of the grip in pixel diagonals 1542 | var minRadius = params.minRadius ? params.minRadius : 1; 1543 | var maxRadius = params.maxRadius; 1544 | if (params.fractionalRadiusAllowed) 1545 | var hiltRadius = 0.5 * Math.ceil(this.randomRange(minRadius * 2, maxRadius * 2) * dscale); 1546 | else 1547 | var hiltRadius = Math.ceil(this.randomRange(minRadius, maxRadius) * dscale); 1548 | 1549 | // wavelength of the grip texture (in diagonal pixels) 1550 | var hiltWavelength = Math.max(2, Math.ceil(this.randomRange(3,6) * dscale)); 1551 | // amplitude of the grip wave 1552 | var hiltWaveAmplitude = Math.ceil(this.randomRange(1,3) * dscale); 1553 | // the color of the grip 1554 | var hiltColorLight = this.hsvToRgb({ h: this.randomRange(0, 360), s: this.randomFloat(), v: this.randomRangeFloat(0.7, 1) }); 1555 | // the color of the grip inner shadows 1556 | var hiltColorDark = this.colorDarken(hiltColorLight, 1); 1557 | 1558 | var outerThis = this; 1559 | 1560 | var rodParams = { 1561 | radius: hiltRadius, 1562 | startDiag: params.startDiag, 1563 | lengthDiag: params.lengthDiag * Math.sqrt(2), //HACK: backwards compat, can be refactored out from the blade function 1564 | colorFunc: function(l) 1565 | { 1566 | var gripWave = Math.abs(Math.cos(Math.PI * 2 * l / hiltWavelength)); 1567 | return outerThis.colorLerp(hiltColorDark, hiltColorLight, gripWave); 1568 | } 1569 | }; 1570 | this.drawRodHelper(rodParams); 1571 | }, 1572 | 1573 | // Helper function that draws a haft with parameters 1574 | // Oriented from the bottom-left corner of the canvas to the top-right 1575 | // Parameters: 1576 | // - startDiag (required): The distance from the bottom-left corner to the start of the haft 1577 | // - lengthDiag (required): The length of the haft 1578 | // - minRadius (optional): The minimum radius of the haft 1579 | // - maxRadius (optional): The maximum radius of the haft 1580 | // - fractionalRadiusAllowed (optional): Allow fractional radius? (won't be centered) 1581 | // - color (optional): The color of the haft 1582 | // Returns an object containing: 1583 | // - radius: the radius of the haft 1584 | drawHaftHelper: function(params) 1585 | { 1586 | this.checkpointRng(); 1587 | 1588 | var bounds = new this.Bounds(0, 0, this.dimension, this.dimension); 1589 | var dscale = bounds.h / 32; 1590 | 1591 | // the radius of the haft in pixel diagonals 1592 | var minRadius = params.minRadius ? params.minRadius : 1; 1593 | var maxRadius = params.maxRadius; 1594 | if (params.fractionalRadiusAllowed) 1595 | var haftRadius = 0.5 * Math.ceil(this.randomRange(minRadius * 2, maxRadius * 2) * dscale); 1596 | else 1597 | var haftRadius = Math.ceil(this.randomRange(minRadius, maxRadius) * dscale); 1598 | 1599 | // the color of the haft 1600 | var haftColor = params.color 1601 | ? params.color 1602 | : this.hsvToRgb({ h: this.randomRange(35, 45), s: this.randomFloat(), v: this.randomRangeFloat(0.5, 0.95) }); 1603 | 1604 | var rodParams = { 1605 | radius: haftRadius, 1606 | startDiag: params.startDiag, 1607 | lengthDiag: params.lengthDiag, 1608 | colorFunc: function() { return haftColor; } 1609 | }; 1610 | this.drawRodHelper(rodParams); 1611 | 1612 | return { 1613 | radius: haftRadius 1614 | }; 1615 | }, 1616 | 1617 | // Helper-helper function for drawing diagonal rods of uniform thickness 1618 | // Oriented from the bottom-left corner of the canvas to the top-right 1619 | // - startDiag (required): The distance from the bottom-left corner to the start of the rod 1620 | // - lengthDiag (required): The length of the rod 1621 | // - radius (required): The radius of the rod 1622 | // - colorFunc (required): Function that gets the color of the rod by the pixel index along it 1623 | drawRodHelper: function(params) 1624 | { 1625 | var radius = Math.max(1, params.radius); 1626 | var bounds = new this.Bounds(0, 0, this.dimension, this.dimension); 1627 | var radSteps = radius / 0.5; 1628 | 1629 | var fractionalRadius = (radius % 1) != 0; 1630 | var startAxis = Math.ceil(params.startDiag / Math.sqrt(2)); 1631 | var lengthAxis = params.lengthDiag / Math.sqrt(2); 1632 | for (var l = 0; l < lengthAxis; l += 0.5) 1633 | { 1634 | var al = startAxis + l; 1635 | 1636 | // determine draw parameters 1637 | var core = new this.Vector(al, bounds.h - 1 - al); 1638 | var fractionalStep = (al % 1) != 0; 1639 | if (!fractionalStep) 1640 | { 1641 | core.x = core.x; 1642 | core.y = core.y; 1643 | 1644 | var left = -Math.floor((radSteps - 2) / 4); 1645 | var right = Math.floor((radSteps - 1) / 4); 1646 | } 1647 | else 1648 | { 1649 | core.x = Math.floor(core.x); 1650 | core.y = Math.floor(core.y); 1651 | 1652 | var left = -Math.floor((radSteps - 3) / 4); 1653 | var right = Math.floor((radSteps - 0) / 4); 1654 | } 1655 | 1656 | // draw grip line 1657 | var sliceColor = params.colorFunc(l); 1658 | this.context.fillStyle = this.colorStr(sliceColor); 1659 | for (var h = left; h <= right; h++) 1660 | { 1661 | if (left == right) 1662 | { 1663 | var darkenAmt = fractionalStep ? 0 : 1; 1664 | } 1665 | else 1666 | { 1667 | var darkenAmt = (h - left) / (right - left); 1668 | } 1669 | darkenAmt *= 0.3; 1670 | 1671 | this.context.fillStyle = this.colorStr(this.colorDarken(sliceColor, darkenAmt)); 1672 | this.drawPixel(core.x + h, core.y + h); 1673 | } 1674 | } 1675 | }, 1676 | 1677 | // Helper function that draws a round ornament with parameters 1678 | // Parameters: 1679 | // - center (required): [vector] the center of the ornament 1680 | // - colorLight (defaults): The light color of the ornament 1681 | // - colorDark (defaults): The dark color of the ornament 1682 | //TODO: expose more parameters 1683 | drawRoundOrnamentHelper: function(params) 1684 | { 1685 | this.checkpointRng(); 1686 | 1687 | var pommelColorLight = params.colorLight 1688 | || this.hsvToRgb({ h: this.randomRange(0, 360), s: this.randomFloatLow()*0.5, v: this.randomRangeFloat(0.7, 1) }); 1689 | var pommelColorDark = params.colorDark 1690 | || this.colorDarken(pommelColorLight, 0.6); 1691 | var pommelRadius = params.radius; 1692 | var shadowCenter = new this.Vector(0.5, 1).normalize().multiplyScalar(pommelRadius).addVector(params.center); 1693 | var highlightCenter = new this.Vector(-1, -1).normalize().multiplyScalar(pommelRadius * 0.7).addVector(params.center); 1694 | for (var x = Math.floor(params.center.x - pommelRadius); x <= Math.ceil(params.center.x + pommelRadius); x++) 1695 | for (var y = Math.floor(params.center.y - pommelRadius); y <= Math.ceil(params.center.y + pommelRadius); y++) 1696 | { 1697 | var radius = params.center.distanceTo(x, y); 1698 | if (radius <= pommelRadius) 1699 | { 1700 | var shadowDist = shadowCenter.distanceTo(x, y); 1701 | var highlightDist = highlightCenter.distanceTo(x, y); 1702 | var darkAmt = 1-Math.min(1, 0.8 * shadowDist / pommelRadius); 1703 | var lightAmt = 1-Math.min(1, highlightDist / pommelRadius); 1704 | this.context.fillStyle = this.colorStr(this.colorLighten(this.colorLerp(pommelColorLight, pommelColorDark, darkAmt), lightAmt)); 1705 | this.drawPixel(x, y); 1706 | } 1707 | } 1708 | } 1709 | } 1710 | -------------------------------------------------------------------------------- /title_penguin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrianMacIntosh/icon-machine/135fa8c8ac8c2ee40c0688625c6917814f865b10/title_penguin.png --------------------------------------------------------------------------------