Repository: Cride5/visualcube
Branch: master
Commit: 5e3d38a53437
Files: 12
Total size: 140.2 KB
Directory structure:
gitextract_hbkv5873/
├── .gitignore
├── COPYING
├── COPYING.LESSER
├── Dockerfile
├── README.md
├── cube_lib.php
├── db_schema.sql
├── screen.css
├── visualcube.php
├── visualcube_api.php
├── visualcube_config.php
└── visualcube_dbprune.sh
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
*~
.dropbox
nbproject
local
================================================
FILE: COPYING
================================================
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
================================================
FILE: COPYING.LESSER
================================================
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
================================================
FILE: Dockerfile
================================================
from php:7.4-apache
RUN apt update
RUN apt install --yes imagemagick
COPY . /var/www/html/
================================================
FILE: README.md
================================================
# VisualCube
Generate custom Rubik's cube visualisations from your browser address bar.
### Installation Instructions
These instructions are for installing the script on your own web server. If you do not have access to your own server, or would just like to try out the software, please visit:
http://cube.rider.biz/visualcube.php
#### Using Docker
```
docker build -t visualcube .
docker run -p 80:80 --rm visualcube
```
##### Prerequisites
* Access to an Apache web server with PHP and ImageMagic installed.
* A MySQL database. This is optional, but will improve performance if you have a high traffic website.
##### Steps
1. Download and extract the code into a web-accessible folder.
2. Edit the configuration variables in visualcube_config.php
3. Point your browser to: www.yourwebsite.com/visualcube.php
4. (Optional) Edit DB_USER, DB_PASS and DB_NAME in visualcube_dbprune.sh and install the cron job.
5. (Optional) Configure mod_rewrite to redirect image suffixes to corresponding fmt=xxx form. See below.
##### Configuring mod_rewrite
Add a .htaccess file to the same folder as visualcube.php with something like the following:
```
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.example\.com)$
RewriteRule ^visualcube\.(gif|png|jpg|jpeg|tiff|ico)$ http://www.example.com/visualcube.php?%{QUERY_STRING}&fmt=$1 [L]
```
### Features
* Fully 3D cube visualisation
* Cube dimensions from 1x1x1 to NxNxN. Currently capped at 9x9 for performance.
* Algorithm support
* Complete orientation control
* Multiple image formats
* Custom image size
* Cube and facelet transparency
* Custom colour schemes and background
* Image caching for speedy access
* Cookie configurable variables
* Arrow overlays
* Highly configurable URL-based API
* Open Source
================================================
FILE: cube_lib.php
================================================
<?php
/*
File: cube_lib.php
Date: 02 Apr 2010
Author(s): Conrad Rider (www.crider.co.uk)
Description: Php library for modelling a Rubik's cube
This file is part of VisualCube.
VisualCube is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
VisualCube is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with VisualCube. If not, see <http://www.gnu.org/licenses/>.
Copyright (C) 2010 Conrad Rider
*/
// Face constants
global $U, $R, $F, $D, $L, $B;
$U = 0; $R = 1; $F = 2; $D = 3; $L = 4; $B = 5;
// Corner Constants
global $URF, $UFL, $ULB, $UBR, $DFR, $DLF, $DBL, $DRB;
$URF = 0; $UFL = 1; $ULB = 2; $UBR = 3; $DFR = 4; $DLF = 5; $DBL = 6; $DRB = 7;
// Edge constants
global $UR, $UF, $UL, $UB, $DR, $DF, $DL, $DB, $FR, $FL, $BL, $BR;
$UR = 0; $UF = 1; $UL = 2; $UB = 3; $DR = 4; $DF = 5; $DL = 6; $DB = 7; $FR = 8; $FL = 9; $BL = 10; $BR = 11;
// Mapping from face constants to face letters
global $FACE_NAMES;
$FACE_NAMES = Array(
$U => 'u',
$R => 'r',
$F => 'f',
$D => 'd',
$L => 'l',
$B => 'b',
);
// A solved cube
global $SOLVED_CUBE;
$SOLVED_CUBE = Array(
Array( $U, $R, $F, $D, $L, $B ),
Array( $URF, $UFL, $ULB, $UBR, $DFR, $DLF, $DBL, $DRB ),
Array( 0, 0, 0, 0, 0, 0, 0, 0 ),
Array( $UR, $UF, $UL, $UB, $DR, $DF, $DL, $DB, $FR, $FL, $BL, $BR ),
Array( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ));
// Partial cubes used to verify the correct parts are solved
global $VCUBE;
$VCUBE = Array(
// Verify a solved first layer 2x2
'2FL' => Array(
Array( -1, -1, -1, -1, -1, -1 ),
Array( -1, -1, -1, -1, $DFR, $DLF, $DBL, $DRB ),
Array( -1, -1, -1, -1, 0, 0, 0, 0 ),
Array( -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 ),
Array( -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 )),
// Verify an oriented first layer 2x2
'2OFL' => Array(
Array( -1, -1, -1, -1, -1, -1 ),
Array( -1, -1, -1, -1, -1, -1, -1, -1),
Array( -1, -1, -1, -1, 0, 0, 0, 0 ),
Array( -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 ),
Array( -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 )),
// Verify orientation is completely solved for 2x2 PBL
'2O' => Array(
Array( -1, -1, -1, -1, -1, -1 ),
Array( -1, -1, -1, -1, -1, -1, -1, -1 ),
Array( 0, 0, 0, 0, 0, 0, 0, 0 ),
Array( -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 ),
Array( -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 )),
// Verify a solved F2L on 3x3
'F2L' => Array(
Array( $U, $R, $F, $D, $L, $B ),
Array( -1, -1, -1, -1, $DFR, $DLF, $DBL, $DRB ),
Array( -1, -1, -1, -1, 0, 0, 0, 0 ),
Array( -1, -1, -1, -1, $DR, $DF, $DL, $DB, $FR, $FL, $BL, $BR ),
Array( -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 )),
// Verify a solved F2L and OCLL (for OCLL, COLL, ZBLL)
'F2L_OCLL' => Array(
Array( $U, $R, $F, $D, $L, $B ),
Array( -1, -1, -1, -1, $DFR, $DLF, $DBL, $DRB ),
Array( -1, -1, -1, -1, 0, 0, 0, 0 ),
Array( -1, -1, -1, -1, $DR, $DF, $DL, $DB, $FR, $FL, $BL, $BR ),
Array( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )),
// Verify a solved F2L and T OCLL (for T ZBLL)
'F2L_OCLL_T' => Array(
Array( $U, $R, $F, $D, $L, $B ),
Array( -1, -1, -1, -1, $DFR, $DLF, $DBL, $DRB ),
Array( 0, 1, 2, 0, 0, 0, 0, 0 ),
Array( -1, -1, -1, -1, $DR, $DF, $DL, $DB, $FR, $FL, $BL, $BR ),
Array( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )),
// Verify a solved F2L and U OCLL (for Headlights ZBLL)
'F2L_OCLL_U' => Array(
Array( $U, $R, $F, $D, $L, $B ),
Array( -1, -1, -1, -1, $DFR, $DLF, $DBL, $DRB ),
Array( 0, 2, 1, 0, 0, 0, 0, 0 ),
Array( -1, -1, -1, -1, $DR, $DF, $DL, $DB, $FR, $FL, $BL, $BR ),
Array( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )),
// Verify a solved F2L and L OCLL (for L ZBLL)
'F2L_OCLL_L' => Array(
Array( $U, $R, $F, $D, $L, $B ),
Array( -1, -1, -1, -1, $DFR, $DLF, $DBL, $DRB ),
Array( 0, 2, 0, 1, 0, 0, 0, 0 ),
Array( -1, -1, -1, -1, $DR, $DF, $DL, $DB, $FR, $FL, $BL, $BR ),
Array( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )),
// Verify a solved F2L and H OCLL (for H ZBLL)
'F2L_OCLL_H' => Array(
Array( $U, $R, $F, $D, $L, $B ),
Array( -1, -1, -1, -1, $DFR, $DLF, $DBL, $DRB ),
Array( 2, 1, 2, 1, 0, 0, 0, 0 ),
Array( -1, -1, -1, -1, $DR, $DF, $DL, $DB, $FR, $FL, $BL, $BR ),
Array( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )),
// Verify a solved F2L and PI OCLL (for PI ZBLL)
'F2L_OCLL_PI' => Array(
Array( $U, $R, $F, $D, $L, $B ),
Array( -1, -1, -1, -1, $DFR, $DLF, $DBL, $DRB ),
Array( 1, 2, 2, 1, 0, 0, 0, 0 ),
Array( -1, -1, -1, -1, $DR, $DF, $DL, $DB, $FR, $FL, $BL, $BR ),
Array( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )),
// Verify a solved F2L and Sune OCLL (for Sune ZBLL)
'F2L_OCLL_S' => Array(
Array( $U, $R, $F, $D, $L, $B ),
Array( -1, -1, -1, -1, $DFR, $DLF, $DBL, $DRB ),
Array( 0, 2, 2, 2, 0, 0, 0, 0 ),
Array( -1, -1, -1, -1, $DR, $DF, $DL, $DB, $FR, $FL, $BL, $BR ),
Array( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )),
// Verify a solved F2L and Anti-sune OCLL (for Anti-sune ZBLL)
'F2L_OCLL_AS' => Array(
Array( $U, $R, $F, $D, $L, $B ),
Array( -1, -1, -1, -1, $DFR, $DLF, $DBL, $DRB ),
Array( 1, 0, 1, 1, 0, 0, 0, 0 ),
Array( -1, -1, -1, -1, $DR, $DF, $DL, $DB, $FR, $FL, $BL, $BR ),
Array( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )),
// Verify a solved F2L and OLL (for PLL)
'F2L_OLL' => Array(
Array( $U, $R, $F, $D, $L, $B ),
Array( -1, -1, -1, -1, $DFR, $DLF, $DBL, $DRB ),
Array( 0, 0, 0, 0, 0, 0, 0, 0 ),
Array( -1, -1, -1, -1, $DR, $DF, $DL, $DB, $FR, $FL, $BL, $BR ),
Array( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )),
// Verify a solved F2L and LL corners (for ELL)
'F2L_CLL' => Array(
Array( $U, $R, $F, $D, $L, $B ),
Array( $URF, $UFL, $ULB, $UBR, $DFR, $DLF, $DBL, $DRB ),
Array( 0, 0, 0, 0, 0, 0, 0, 0 ),
Array( -1, -1, -1, -1, $DR, $DF, $DL, $DB, $FR, $FL, $BL, $BR ),
Array( -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 )),
// Verify a solved F2B (for CMLL)
'F2B' => Array(
Array( -1, $R, -1, -1, $L, -1 ),
Array( -1, -1, -1, -1, $DFR, $DLF, $DBL, $DRB ),
Array( -1, -1, -1, -1, 0, 0, 0, 0 ),
Array( -1, -1, -1, -1, $DR, -1, $DL, -1, $FR, $FL, $BL, $BR ),
Array( -1, -1, -1, -1, 0, -1, 0, -1, 0, 0, 0, 0 )),
// Verify a solved F2L minus last slot (for ELS)
'F2LS' => Array(
Array( $U, $R, $F, $D, $L, $B ),
Array( -1, -1, -1, -1, -1, $DLF, $DBL, $DRB ),
Array( -1, -1, -1, -1, -1, 0, 0, 0 ),
Array( -1, -1, -1, -1, $DR, $DF, $DL, $DB, -1, $FL, $BL, $BR ),
Array( -1, -1, -1, -1, 0, 0, 0, 0, -1, 0, 0, 0 )),
// Verify a solved F2L, minus last slot, with EO and solved FR (for CLS)
'F2LS_EO' => Array(
Array( $U, $R, $F, $D, $L, $B ),
Array( -1, -1, -1, -1, -1, $DLF, $DBL, $DRB ),
Array( -1, -1, -1, -1, -1, 0, 0, 0 ),
Array( -1, -1, -1, -1, $DR, $DF, $DL, $DB, $FR, $FL, $BL, $BR ),
Array( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ))
);
// An array storing all cubie-level moves
global $CUBIE_MOVES;
$CUBIE_MOVES = Array(
Array( // U
Array( $U, $R, $F, $D, $L, $B ),
Array( $UBR, $URF, $UFL, $ULB, $DFR, $DLF, $DBL, $DRB ),
Array( 0, 0, 0, 0, 0, 0, 0, 0 ),
Array( $UB, $UR, $UF, $UL, $DR, $DF, $DL, $DB, $FR, $FL, $BL, $BR ),
Array( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )),
Array( // R
Array( $U, $R, $F, $D, $L, $B ),
Array( $DFR, $UFL, $ULB, $URF, $DRB, $DLF, $DBL, $UBR ),
Array( 2, 0, 0, 1, 1, 0, 0, 2 ),
Array( $FR, $UF, $UL, $UB, $BR, $DF, $DL, $DB, $DR, $FL, $BL, $UR ),
Array( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )),
Array( // F
Array( $U, $R, $F, $D, $L, $B ),
Array( $UFL, $DLF, $ULB, $UBR, $URF, $DFR, $DBL, $DRB ),
Array( 1, 2, 0, 0, 2, 1, 0, 0 ),
Array( $UR, $FL, $UL, $UB, $DR, $FR, $DL, $DB, $UF, $DF, $BL, $BR ),
Array( 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0 )),
Array( // D
Array( $U, $R, $F, $D, $L, $B ),
Array( $URF, $UFL, $ULB, $UBR, $DLF, $DBL, $DRB, $DFR ),
Array( 0, 0, 0, 0, 0, 0, 0, 0 ),
Array( $UR, $UF, $UL, $UB, $DF, $DL, $DB, $DR, $FR, $FL, $BL, $BR ),
Array( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )),
Array( // L
Array( $U, $R, $F, $D, $L, $B ),
Array( $URF, $ULB, $DBL, $UBR, $DFR, $UFL, $DLF, $DRB ),
Array( 0, 1, 2, 0, 0, 2, 1, 0 ),
Array( $UR, $UF, $BL, $UB, $DR, $DF, $FL, $DB, $FR, $UL, $DL, $BR ),
Array( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )),
Array( // B
Array( $U, $R, $F, $D, $L, $B ),
Array( $URF, $UFL, $UBR, $DRB, $DFR, $DLF, $ULB, $DBL ),
Array( 0, 0, 1, 2, 0, 0, 2, 1 ),
Array( $UR, $UF, $UL, $BR, $DR, $DF, $DL, $BL, $FR, $FL, $UB, $DB ),
Array( 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1 )),
Array( // E
Array( $U, $F, $L, $D, $B, $R ),
Array( $URF, $UFL, $ULB, $UBR, $DFR, $DLF, $DBL, $DRB ),
Array( 0, 0, 0, 0, 0, 0, 0, 0 ),
Array( $UR, $UF, $UL, $UB, $DR, $DF, $DL, $DB, $FL, $BL, $BR, $FR ),
Array( 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1 )),
Array( // M
Array( $B, $R, $U, $F, $L, $D ),
Array( $URF, $UFL, $ULB, $UBR, $DFR, $DLF, $DBL, $DRB ),
Array( 0, 0, 0, 0, 0, 0, 0, 0 ),
Array( $UR, $UB, $UL, $DB, $DR, $UF, $DL, $DF, $FR, $FL, $BL, $BR ),
Array( 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0 )),
Array( // S
Array( $L, $U, $F, $R, $D, $B ),
Array( $URF, $UFL, $ULB, $UBR, $DFR, $DLF, $DBL, $DRB ),
Array( 0, 0, 0, 0, 0, 0, 0, 0 ),
Array( $UL, $UF, $DL, $UB, $UR, $DF, $DR, $DB, $FR, $FL, $BL, $BR ),
Array( 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0 )));
// Now that the elementry moves are defined, the rest of the moves can be built
$CUBIE_MOVES = Array(
$CUBIE_MOVES[0],
$CUBIE_MOVES[1],
$CUBIE_MOVES[2],
$CUBIE_MOVES[3],
$CUBIE_MOVES[4],
$CUBIE_MOVES[5],
prod(array_copy($CUBIE_MOVES[0]), $CUBIE_MOVES[6], 3),
prod(array_copy($CUBIE_MOVES[1]), $CUBIE_MOVES[7], 3),
prod(array_copy($CUBIE_MOVES[2]), $CUBIE_MOVES[8], 1),
prod(array_copy($CUBIE_MOVES[3]), $CUBIE_MOVES[6], 1),
prod(array_copy($CUBIE_MOVES[4]), $CUBIE_MOVES[7], 1),
prod(array_copy($CUBIE_MOVES[5]), $CUBIE_MOVES[8], 3),
$CUBIE_MOVES[6],
$CUBIE_MOVES[7],
$CUBIE_MOVES[8],
prod(prod(array_copy($CUBIE_MOVES[0]), $CUBIE_MOVES[3], 3), $CUBIE_MOVES[6], 3),
prod(prod(array_copy($CUBIE_MOVES[1]), $CUBIE_MOVES[4], 3), $CUBIE_MOVES[7], 3),
prod(prod(array_copy($CUBIE_MOVES[2]), $CUBIE_MOVES[5], 3), $CUBIE_MOVES[8], 1));
// Mapping from power to chr to represent it
global $ALG_POW;
$ALG_POW = Array ('', "2", "'");
// Returns the case identified by this alg (or -1 if not belonging to group),
// as well an amended alg with any rotations required to make it fit the group
function gen_state($moves, $puzzle, $group_id, $is_ll){
global $SOLVED_CUBE, $CUBIE_MOVES, $VCUBE;
//println("\nGENSTATE:\ninput moves=$moves");
$moves = trim_rotations($moves, $is_ll);
//println("trimmed moves=$moves");
// 1. Apply different combinations of initial
// and final moves until a solved state is found
$prtns = Array("", "x", "x'", "x2", "z", "z'", "y", "y'");
$frtns = Array("", "x", "x'", "x2", "z", "z'", "y", "y'");
$valid = false;
for($i = 0; $i < count($frtns) && !$valid; $i++){
for($j = 0; $j < count($prtns) && !$valid; $j++){
$cube = case_cube($prtns[$j].$moves.$frtns[$i]);
//println("testing cube: ".$prtns[$j].$moves.$frtns[$i]);
//printcube($cube, 3);
if(is_member($cube, $group_id)){
$prtn = $prtns[$j];
$frtn = $frtns[$i];
$moves = "$prtn$moves$frtn";
$valid = true;
}
}
}
// Stop here if alg not valid
if(!$valid) return Array(-1, $moves);
//println("corrected moves=$prtn$moves$frtn");
// 2. Find angle to apply alg which results in lowest state id
// This is necessery to ensure all rotations of same alg are given same state
// Generate 4 case cubes
$cubes = case_cubes2($moves, Array("", "y", "y2", "y'"));
$state = PHP_INT_MAX;
foreach($cubes as $cube){
//printcube($cube, 3);
// Check cube from all y rotation angles
for($i = 0; $i < 4; $i++){
// Generate identifier for state (depends on alg purpose)
$s = cube_state($cube, $group_id);
//println($s);
// Set it as main ID if lowest found so-far
if($s < $state && $s != -1) $state = $s;
// Rotate cube by y
$cube = prod($cube, $CUBIE_MOVES[move_id('y')], 1);
}
}
//println("detected state=$state");
// Return cube state and moves which make cube state valid
return Array($state, $prtn, $frtn);
}
// Rotate input alg to match reference alg's orientation and output corrected alg
function orient_alg($alg, $ref, $puzzle, $group_id){
global $SOLVED_CUBE, $CUBIE_MOVES, $ALG_POW;
// Remove initial y rotations from alg
$alg = preg_replace('/^y[2\']?/', '', $alg);
$cubes = case_cubes2($alg, Array("", "y", "y2", "y'"));
$ref_cube = case_cube($ref);
//print_r2($ref_cube[1]);
//print_r2($ref_cube[3]);
$match = false;
foreach($cubes as $cube){
// Now apply up to 3 y twists until the case matches
$r = 0;
while(!$match && $r < 4){
// Detection of identical case (inc cube oriented correctly)
// For OLL all LL orientations should match
switch($group_id){
case 1: // OLL
$match = cube_match(array_slice($cube[2], 0, 4), array_slice($ref_cube[2], 0, 4)); // CO
break;
case 2: // PBL (permutation of all corners)
$match = cube_match($cube[1], $ref_cube[1]); // CP
break;
case 3: // CLL (LL orientation + permutation)
$match = cube_match(array_slice($cube[2], 0, 4), array_slice($ref_cube[2], 0, 4)) // CO
&& cube_match(array_slice($cube[1], 0, 4), array_slice($ref_cube[1], 0, 4)); // CP
break;
case 4: // OLL
$match = cube_match(array_slice($cube[2], 0, 4), array_slice($ref_cube[2], 0, 4)) // CO
&& cube_match(array_slice($cube[4], 0, 4), array_slice($ref_cube[4], 0, 4)); // EO
break;
case 5: // PLL
$match = cube_match(array_slice($cube[1], 0, 4), array_slice($ref_cube[1], 0, 4)) // CP
&& cube_match(array_slice($cube[3], 0, 4), array_slice($ref_cube[3], 0, 4)); // EP
break;
case 6: // CLL
$match = cube_match(array_slice($cube[1], 0, 4), array_slice($ref_cube[1], 0, 4)) // CP
&& cube_match(array_slice($cube[2], 0, 4), array_slice($ref_cube[2], 0, 4)); // CO
break;
case 7: // ELL
$match = cube_match(array_slice($cube[3], 0, 4), array_slice($ref_cube[3], 0, 4)) // EP
&& cube_match(array_slice($cube[4], 0, 4), array_slice($ref_cube[4], 0, 4)); // EO
break;
case 8: // CMLL
$match = cube_match(array_slice($cube[1], 0, 4), array_slice($ref_cube[1], 0, 4)) // CP
&& cube_match(array_slice($cube[2], 0, 4), array_slice($ref_cube[2], 0, 4)); // CO
break;
case 9: // COLL
$match = cube_match(array_slice($cube[1], 0, 4), array_slice($ref_cube[1], 0, 4)) // CP
&& cube_match(array_slice($cube[2], 0, 4), array_slice($ref_cube[2], 0, 4)); // CO
break;
case 10: // ZBLL
$match = cube_match(array_slice($cube[1], 0, 4), array_slice($ref_cube[1], 0, 4)) // CP
&& cube_match(array_slice($cube[2], 0, 4), array_slice($ref_cube[2], 0, 4)) // CO
&& cube_match(array_slice($cube[3], 0, 4), array_slice($ref_cube[3], 0, 4)); // EP
break;
case 11: // ELS
$match = cube_match(array_slice($cube[4], 0, 4), array_slice($ref_cube[4], 0, 4)) // EO
&& els_FR($cube) == els_FR($ref_cube);
break;
case 12: // CLS
cube_match(array_slice($cube[2], 0, 4), array_slice($ref_cube[2], 0, 4)); // CO
break;
case 13: // ZBLL-T
$match = cube_match(array_slice($cube[1], 0, 4), array_slice($ref_cube[1], 0, 4)) // CP
&& cube_match(array_slice($cube[2], 0, 4), array_slice($ref_cube[2], 0, 4)) // CO
&& cube_match(array_slice($cube[3], 0, 4), array_slice($ref_cube[3], 0, 4)); // EP
break;
case 14: // ZBLL-U
$match = cube_match(array_slice($cube[1], 0, 4), array_slice($ref_cube[1], 0, 4)) // CP
&& cube_match(array_slice($cube[2], 0, 4), array_slice($ref_cube[2], 0, 4)) // CO
&& cube_match(array_slice($cube[3], 0, 4), array_slice($ref_cube[3], 0, 4)); // EP
break;
case 15: // ZBLL-L
$match = cube_match(array_slice($cube[1], 0, 4), array_slice($ref_cube[1], 0, 4)) // CP
&& cube_match(array_slice($cube[2], 0, 4), array_slice($ref_cube[2], 0, 4)) // CO
&& cube_match(array_slice($cube[3], 0, 4), array_slice($ref_cube[3], 0, 4)); // EP
break;
case 16: // ZBLL-H
$match = cube_match(array_slice($cube[1], 0, 4), array_slice($ref_cube[1], 0, 4)) // CP
&& cube_match(array_slice($cube[2], 0, 4), array_slice($ref_cube[2], 0, 4)) // CO
&& cube_match(array_slice($cube[3], 0, 4), array_slice($ref_cube[3], 0, 4)); // EP
break;
case 17: // ZBLL-Pi
$match = cube_match(array_slice($cube[1], 0, 4), array_slice($ref_cube[1], 0, 4)) // CP
&& cube_match(array_slice($cube[2], 0, 4), array_slice($ref_cube[2], 0, 4)) // CO
&& cube_match(array_slice($cube[3], 0, 4), array_slice($ref_cube[3], 0, 4)); // EP
break;
case 18: // ZBLL-S
$match = cube_match(array_slice($cube[1], 0, 4), array_slice($ref_cube[1], 0, 4)) // CP
&& cube_match(array_slice($cube[2], 0, 4), array_slice($ref_cube[2], 0, 4)) // CO
&& cube_match(array_slice($cube[3], 0, 4), array_slice($ref_cube[3], 0, 4)); // EP
break;
case 19: // ZBLL-As
$match = cube_match(array_slice($cube[1], 0, 4), array_slice($ref_cube[1], 0, 4)) // CP
&& cube_match(array_slice($cube[2], 0, 4), array_slice($ref_cube[2], 0, 4)) // CO
&& cube_match(array_slice($cube[3], 0, 4), array_slice($ref_cube[3], 0, 4)); // EP
break;
}
//if($match) println("r:$r true");
//else println("r:$r false");
//print_r2($cube[1]);
//print_r2($cube[3]);
// If no match found rotate cube and incrament rotation counter
if(!$match){
$cube = prod($cube, $CUBIE_MOVES[move_id('y')], 1);
$r++;
}
}
if($match) break;
}
// Rotation required is the inverse of rotations used to match case
if($r > 0) $alg = "y".$ALG_POW[3 - $r].$alg;
return $alg;
}
// Returns the location of the FR edge for ELS
function els_FR($cube){
global $FR;
$frp = 0; // assuming its in position
for($j = 0; $j < 4; $j++){ if($cube[3][$j] == $FR){ $frp = $i + 1; break; }}
return $frp;
}
// TODO: This function failes on alg... x' U' R U L' U2 R' U' L' U' L2 u r2 U' z ... part of ZBLL-PI, or H
// U' l2 u R2 U' R' U' L' U2 R' U L U' ... from ZBLL-PI
// Returns true if the cube state is a member of the given group
function is_member($cube, $group_id){
//echo "is member of? $group_id :";
//printcube($cube, 3);
global $CUBIE_MOVES;
// Check cube from all y rotation angles
for($i = 0; $i < 4; $i++){
//println("|".$cube[2][0].", ".$cube[2][1].", ".$cube[2][2].", ".$cube[2][3]."|");
//printcube($cube, 3);
for($j = 0; $j < 4; $j++){
if(is_member_strict($cube, $group_id)) return true;
// Rotate cube
$cube = prod($cube, $CUBIE_MOVES[move_id('y')], 1);
}
// Rotate U-Layer
$cube = prod($cube, $CUBIE_MOVES[move_id('U')], 1);
}
return false;
}
// Returns true if the cube state is a member of the given group when AUF is allowed
function is_member_auf($cube, $group_id){
//echo "is member of? $group_id :";
//printcube($cube, 3);
global $CUBIE_MOVES;
// Check cube from all auf rotation angles
for($i = 0; $i < 4; $i++){
//println("|".$cube[2][0].", ".$cube[2][1].", ".$cube[2][2].", ".$cube[2][3]."|");
//printcube($cube, 3);
if(is_member_strict($cube, $group_id)) return true;
// Rotate U-Layer
$cube = prod($cube, $CUBIE_MOVES[move_id('U')], 1);
}
return false;
}
function is_member_strict($cube, $group_id){
global $VCUBE;
switch($group_id){
case 1: if(cube_match($cube, $VCUBE['2OFL'] )) return true; break; // OLL
case 2: if(cube_match($cube, $VCUBE['2O'] )) return true; break; // PBL
case 3: if(cube_match($cube, $VCUBE['2FL'] )) return true; break; // CLL
case 4: if(cube_match($cube, $VCUBE['F2L'] )) return true; break; // OLL
case 5: if(cube_match($cube, $VCUBE['F2L_OLL'] )) return true; break; // PLL
case 6: if(cube_match($cube, $VCUBE['F2L'] )) return true; break; // CLL
case 7: if(cube_match($cube, $VCUBE['F2L_CLL'] )) return true; break; // ELL
case 8: if(cube_match($cube, $VCUBE['F2B'] )) return true; break; // CMLL
case 9: if(cube_match($cube, $VCUBE['F2L_OCLL'])) return true; break; // COLL
case 10: if(cube_match($cube, $VCUBE['F2L_OCLL'])) return true; break; // ZBLL
case 11: if(cube_match($cube, $VCUBE['F2LS'] )) return true; break; // ELS
case 12: if(cube_match($cube, $VCUBE['F2LS_EO'] )) return true; break; // CLS
case 13: if(cube_match($cube, $VCUBE['F2L_OCLL_T'])) return true; break; // ZBLL-T
case 14: if(cube_match($cube, $VCUBE['F2L_OCLL_U'])) return true; break; // ZBLL-U
case 15: if(cube_match($cube, $VCUBE['F2L_OCLL_L'])) return true; break; // ZBLL-L
case 16: if(cube_match($cube, $VCUBE['F2L_OCLL_H'])) return true; break; // ZBLL-H
case 17: if(cube_match($cube, $VCUBE['F2L_OCLL_PI'])) return true; break; // ZBLL-PI
case 18: if(cube_match($cube, $VCUBE['F2L_OCLL_S'])) return true; break; // ZBLL-S
case 19: if(cube_match($cube, $VCUBE['F2L_OCLL_AS'])) return true; break; // ZBLL-AS
}
return false;
}
// Returns a value uniquely identifying this cube state in this group
function cube_state($cube, $group_id){
switch($group_id){
case 1: return encode_o(array_slice($cube[2], 0, 3), 3); // CO (2x2 OLL)
case 2: return encode_p($cube[1]); // CP (all corners) (PBL)
case 3: return encode_o(array_slice($cube[2], 0, 3), 3) // CO (2x2 CLL)
+ encode_p(array_slice($cube[1], 0, 4)) * 27; // CP
case 4: return encode_o(array_slice($cube[2], 0, 3), 3) // CO (OLL)
+ encode_o(array_slice($cube[4], 0, 3), 2) * 27; // EO (* 3^3)
case 5: return encode_p(array_slice($cube[1], 0, 4), 3) // CP (PLL)
+ encode_p(array_slice($cube[3], 0, 4)) * 24; // EO (* 4!)
case 6: return encode_o(array_slice($cube[2], 0, 3), 3) // CO (CLL)
+ encode_p(array_slice($cube[1], 0, 4)) * 27; // CP
case 7: return encode_o(array_slice($cube[4], 0, 3), 2) // EO (ELL)
+ encode_p(array_slice($cube[3], 0, 4)) * 8; // EP
case 8: return encode_o(array_slice($cube[2], 0, 3), 3) // CO (CMLL)
+ encode_p(array_slice($cube[1], 0, 4)) * 27; // CP
case 9: return encode_o(array_slice($cube[2], 0, 3), 3) // CO (COLL)
+ encode_p(array_slice($cube[1], 0, 4)) * 27; // CP
case 10: return encode_o(array_slice($cube[2], 0, 3), 3) // CO (ZBLL)
+ encode_p(array_slice($cube[1], 0, 4)) * 27 // CP
+ encode_p(array_slice($cube[3], 0, 4)) * 27 * 24; // EP
case 11: // ELS
// This must encode orientation of the 4 top edges (fifth is determined by other 4)
// along with the position of the FR edge
return encode_o(array_slice($cube[4], 0, 4), 2)
+ els_FR($cube) * 16; // EO(5 edges) + position of FR
case 12: // CLS must track the orientation of the 5 corners (determined by o of 4 top ones)
return encode_o(array_slice($cube[2], 0, 4), 3); // CO
case 13: return encode_o(array_slice($cube[2], 0, 3), 3) // CO (ZBLL-T)
+ encode_p(array_slice($cube[1], 0, 4)) * 27 // CP
+ encode_p(array_slice($cube[3], 0, 4)) * 27 * 24; // EP
case 14: return encode_o(array_slice($cube[2], 0, 3), 3) // CO (ZBLL-U)
+ encode_p(array_slice($cube[1], 0, 4)) * 27 // CP
+ encode_p(array_slice($cube[3], 0, 4)) * 27 * 24; // EP
case 15: return encode_o(array_slice($cube[2], 0, 3), 3) // CO (ZBLL-L)
+ encode_p(array_slice($cube[1], 0, 4)) * 27 // CP
+ encode_p(array_slice($cube[3], 0, 4)) * 27 * 24; // EP
case 16: return encode_o(array_slice($cube[2], 0, 3), 3) // CO (ZBLL-Pi)
+ encode_p(array_slice($cube[1], 0, 4)) * 27 // CP
+ encode_p(array_slice($cube[3], 0, 4)) * 27 * 24; // EP
case 17: return encode_o(array_slice($cube[2], 0, 3), 3) // CO (ZBLL-H)
+ encode_p(array_slice($cube[1], 0, 4)) * 27 // CP
+ encode_p(array_slice($cube[3], 0, 4)) * 27 * 24; // EP
case 18: return encode_o(array_slice($cube[2], 0, 3), 3) // CO (ZBLL-S)
+ encode_p(array_slice($cube[1], 0, 4)) * 27 // CP
+ encode_p(array_slice($cube[3], 0, 4)) * 27 * 24; // EP
case 19: return encode_o(array_slice($cube[2], 0, 3), 3) // CO (ZBLL-AS)
+ encode_p(array_slice($cube[1], 0, 4)) * 27 // CP
+ encode_p(array_slice($cube[3], 0, 4)) * 27 * 24; // EP
}
return -1;
}
// Returs the cube-state the given alg solves
function case_cube($alg){
global $SOLVED_CUBE, $F2L_CUBE, $CUBIE_MOVES;
// Apply inverse to get state which alg solves
$alg = invert_alg($alg);
$cube = array_copy($SOLVED_CUBE);
return apply_alg($alg, $cube);
}
// Returns a set of case cubes representing the state of the
// cube the alg solves, given the rotation was applied first
function case_cubes($alg, $prerot){
global $SOLVED_CUBE;
// Apply inverse to get state which alg solves
$alg = invert_alg($alg);
foreach($prerot as $i => $rtn){
$cubes[$i] = apply_alg($alg.invert_alg($rtn), array_copy($SOLVED_CUBE));
}
return $cubes;
}
// Returns a set of case cubes representing the state of the
// cube the alg solves, given the rotation was applied last
function case_cubes2($alg, $postrot){
global $SOLVED_CUBE;
// Apply inverse to get state which alg solves
$alg = invert_alg($alg);
foreach($postrot as $i => $rtn){
$cubes[$i] = apply_alg(invert_alg($rtn).$alg, array_copy($SOLVED_CUBE));
}
return $cubes;
}
// Returns the move required to rotate the cube to an upright position
function upright($cube){
global $U, $R, $F, $D, $L, $B, $CUBIE_MOVES;
// search for U face centre
$upos = 0;
foreach($cube[0] as $i => $c){
if($c == $U){
$upos = $i;
break;
}
}
$move = "";
switch($upos){
case $R : $move = "z'"; break;
case $L : $move = "z"; break;
case $F : $move = "x"; break;
case $B : $move = "x'"; break;
case $D : $move = "x2"; break;
}
return $move;
}
// Convert cubie cube to face cube, using the default facelet identifiers
function face_cube($cube, $dim){
// Construct default facelet id scheme
for($f = 0; $f < 6; $f++){
for($i = 0; $i < $dim; $i++){
for($j = 0; $j < $dim; $j++) $fd .= $f;
}
}
return facelet_cube($cube, $dim, $fd);
}
// Convert cubie cube to facelet cube mapping each facelet
// to the given facelet id sequence
function facelet_cube($cube, $d, $fi){
global $U, $R, $F, $D, $L, $B;
// Facelet constants
// Dimension/2
$h = (int)($d/2);
// Dimension squared
$s = $d * $d;
// Half of dimension squared
$m = (int)($s/2);
// Map centre positions to facelet ids
$mfid = Array($fi[$U*$s+$m], $fi[$R*$s+$m], $fi[$F*$s+$m], $fi[$D*$s+$m], $fi[$L*$s+$m], $fi[$B*$s+$m]);
// Map the corner positions to facelet ids
$cfid = Array(
Array($fi[ ($U+1)*$s-1], $fi[ $R*$s], $fi[ $F*$s+$d-1]),
Array($fi[($U+1)*$s-$d], $fi[ $F*$s], $fi[ $L*$s+$d-1]),
Array($fi[ $U*$s], $fi[ $L*$s], $fi[ $B*$s+$d-1]),
Array($fi[ $U*$s+$d-1], $fi[ $B*$s], $fi[ $R*$s+$d-1]),
Array($fi[ $D*$s+$d-1], $fi[($F+1)*$s-1], $fi[($R+1)*$s-$d]),
Array($fi[ $D*$s], $fi[($L+1)*$s-1], $fi[($F+1)*$s-$d]),
Array($fi[($D+1)*$s-$d], $fi[($B+1)*$s-1], $fi[($L+1)*$s-$d]),
Array($fi[ ($D+1)*$s-1], $fi[($R+1)*$s-1], $fi[($B+1)*$s-$d]));
// Map the edge positions to facelet ids
$efid = Array(
Array($fi[$U*$s+$m+$h], $fi[ $R*$s+$h]), Array($fi[($U+1)*$s-1-$h], $fi[ $F*$s+$h]),
Array($fi[$U*$s+$m-$h], $fi[ $L*$s+$h]), Array($fi[ $U*$s+$h], $fi[ $B*$s+$h]),
Array($fi[$D*$s+$m+$h], $fi[($R+1)*$s-1-$h]), Array($fi[ $D*$s+$h], $fi[($F+1)*$s-1-$h]),
Array($fi[$D*$s+$m-$h], $fi[($L+1)*$s-1-$h]), Array($fi[($D+1)*$s-1-$h], $fi[($B+1)*$s-1-$h]),
Array($fi[$F*$s+$m+$h], $fi[ $R*$s+$m-$h]), Array($fi[ $F*$s+$m-$h], $fi[ $L*$s+$m+$h]),
Array($fi[$B*$s+$m+$h], $fi[ $L*$s+$m-$h]), Array($fi[ $B*$s+$m-$h], $fi[ $R*$s+$m+$h]));
//print_r($efid);
/*
// Map the corner positions to facelets
$ccol = Array(
Array($U, $R, $F), Array($U, $F, $L), Array($U, $L, $B), Array($U, $B, $R),
Array($D, $F, $R), Array($D, $L, $F), Array($D, $B, $L), Array($D, $R, $B));
// Map the edge positions to facelets
$ecol = Array(
Array($U, $R), Array($U, $F), Array($U, $L),
Array($U, $B), Array($D, $R), Array($D, $F),
Array($D, $L), Array($D, $B), Array($F, $R),
Array($F, $L), Array($B, $L), Array($B, $R));
*/
// Map of centre facelet positions
$mpos = Array($U*$s+$m, $R*$s+$m, $F*$s+$m, $D*$s+$m, $L*$s+$m, $B*$s+$m);
// Map of corner facelet positions (for any dimensoin of cube)
$cpos = Array(
Array( ($U+1)*$s-1, $R*$s, $F*$s+$d-1), Array(($U+1)*$s-$d, $F*$s, $L*$s+$d-1),
Array( $U*$s, $L*$s, $B*$s+$d-1), Array( $U*$s+$d-1, $B*$s, $R*$s+$d-1),
Array( $D*$s+$d-1, ($F+1)*$s-1, ($R+1)*$s-$d), Array( $D*$s, ($L+1)*$s-1, ($F+1)*$s-$d),
Array(($D+1)*$s-$d, ($B+1)*$s-1, ($L+1)*$s-$d), Array( ($D+1)*$s-1, ($R+1)*$s-1, ($B+1)*$s-$d));
// Map edge facelet positions (for any dimensoin)
$epos = Array(
Array($U*$s+$m+$h, $R*$s+$h), Array(($U+1)*$s-1-$h, $F*$s+$h), Array($U*$s+$m-$h, $L*$s+$h),
Array( $U*$s+$h, $B*$s+$h), Array( $D*$s+$m+$h, ($R+1)*$s-1-$h), Array( $D*$s+$h, ($F+1)*$s-1-$h),
Array($D*$s+$m-$h, ($L+1)*$s-1-$h), Array(($D+1)*$s-1-$h, ($B+1)*$s-1-$h), Array($F*$s+$m+$h, $R*$s+$m-$h),
Array($F*$s+$m-$h, $L*$s+$m+$h), Array( $B*$s+$m+$h, $L*$s+$m-$h), Array($B*$s+$m-$h, $R*$s+$m+$h));
// Corners
for($i = 0; $i < 8; $i++){
$j = $cube[1][$i]; // cornercubie with index j is at
// cornerposition with index i
$o = $cube[2][$i]; // Orientation of this cubie
for($n = 0; $n < 3; $n++) $fo[$cpos[$i][($n + $o) % 3]] = $cfid[$j][$n];
}
//print_r($mfid);
//echo "\n<br/>";
// Pieces only applicable to odd sized puzzles
if($d % 2 == 1){
// Centers
for($i = 0; $i < 6; $i++){
//echo "\n<br/>".$cube[0][$i];
$fo[$mpos[$i]] = $mfid[$cube[0][$i]];
}
// Centre edges
for($i = 0; $i < 12; $i++){
$j = $cube[3][$i]; // edgecubie with index j is at edgeposition with index i
$o = $cube[4][$i]; // Orientation of this cubie
for($n = 0; $n < 2; $n++) $fo[$epos[$i][($n + $o) % 2]] = $efid[$j][$n];
}
}
//print_r( $fo);
return $fo;
}
// Convert cubie cube to letter cube (letters representing facelets)
function letter_cube($cube, $dim){
global $FACE_NAMES;
$fc = face_cube($cube, $dim);
for($i = 0; $i < count($fc); $i++){
$lc[$i] = $FACE_NAMES[$fc[$i]];
}
return implode($lc);
}
// Convert cubie cube to colour cube
function col_cube($cube, $dim){
// Sheme mapping
$FACE_COL = Array(
'u' => 'y',
'r' => 'r',
'f' => 'b',
'd' => 'w',
'l' => 'o',
'b' => 'g');
$fc = face_cube($cube, $dim);
// Translate face defs into colour defs
for($i = 0; $i < strlen($fc); $i++){
$col .= $FACE_COL[$fc[$i]];
}
return $col;
}
// Print a cube to screen for debugging
function printcube($cube, $dim){
$fc = letter_cube($cube, $dim);
println("<img src=\"visualcube.php?fmt=gif&fd=$fc\">");
}
// Applys an alg to the given cube
function apply_alg($alg, $cube){
global $CUBIE_MOVES;
$i = 0;
$len = strlen($alg);
while($i < $len){
$move = move_id(substr($alg, $i, 1));
if($move >= 0){
$pow = move_pow(substr($alg, $i+1, 1));
if($pow > 1) $i++;
// Make the move
$cube = prod($cube, $CUBIE_MOVES[$move], $pow);
}
$i++;
}
return $cube;
}
// Formats an inputed alg to remove dissallowed characters and standardise notation
function format_alg($moves){
// Remove characters not allowed in an alg
$r = preg_replace('/[^UDLRFBudlrfbMESxyzw\'`23]/', '', $moves);
$r = preg_replace('/[3`]/', "'", $r); // Replace 3 or ` with a '
$r = preg_replace('/2\'|\'2/', "2", $r); // Replace 2' or '2 with a 2
// Fix wide notation
if(preg_match('/w/', $r)){
$r = preg_replace('/Uw/', 'u', $r);
$r = preg_replace('/Rw/', 'r', $r);
$r = preg_replace('/Fw/', 'f', $r);
$r = preg_replace('/Dw/', 'd', $r);
$r = preg_replace('/Lw/', 'l', $r);
$r = preg_replace('/Bw/', 'b', $r);
// now remove any extra w's
$r = preg_replace('/w/', '', $r);
}
// Merge multiple moves/rotations of same face
//println( "init moves=|$moves|");
return compress_alg($r);
//println("compressed moves=|$moves|");
}
// Removes all initial and final rotations from a cube
function trim_rotations($alg, $is_ll){
//echo "isll?$is_ll";
// Remove AUFs if its an LL alg
if($is_ll) $alg = remove_auf($alg);
// Strip all initial rotations
$alg = preg_replace('/^([xyz][2\']?)+/', '', $alg);
// Strip all final rotations
$alg = preg_replace('/([xyz][2\']?)+$/', '', $alg);
//echo "moves=|$moves|";
return $alg;
}
// Removes AUFs and replaces them with y rotations
function remove_auf($alg){
$n = strlen($alg);
for($i = 0; $i < $n; $i++){
$c = substr($alg, $i, 1);
if($c == 'U') $alg[$i] = 'y';
else if(preg_match('/[^yU2\'\s]/', $c)) // anything other than y and U turns are no longer aufs
break;
}
for($i = $n - 1; $i > -1; $i--){
$c = substr($alg, $i, 1);
if($c == 'U') $alg[$i] = 'y';
else if(preg_match('/[^yU2\'\s]/', $c)) // anything other than y and U turns are no longer aufs
break;
}
return compress_alg($alg);
}
// Inserts spaces in an alg for display
function expand_alg($alg){
$n = strlen($alg);
$i = 1;
$exp = substr($alg, 0, 1);
while($i < $n){
$c = substr($alg, $i, 1);
if(move_id($c) != -1) $exp .= " ";
$exp .= $c;
$i++;
}
return $exp;
}
// Merges unnecessery repeated moves of the same face
function compress_alg($alg){
global $ALG_POW;
$merge_done = true;
while($merge_done && strlen($alg) > 1){
$n = strlen($alg);
$i = 0;
$merge_done = false;
while($i < $n){
$move = $alg[$i];
if(move_id($move) != -1){
$pow = 1;
if($i < $n -1) $pow = move_pow($alg[$i + 1]);
if($pow > 1) $i++;
// If moves the same, then simply add up powers
if($lmove == $move){
$lpow += $pow;
$merge_done = true;
}
// Otherwise, last move can be added to alg
else{
$lpow = $lpow % 4;
if($lpow > 0) $malg .= $lmove . $ALG_POW[$lpow-1];
$lpow = $pow;
$lmove = $move;
}
}
$i++;
}
// Add final move
$lpow = $lpow % 4;
if($lpow > 0) $malg .= $lmove . $ALG_POW[$lpow-1];
$alg = $malg;
$malg = null;
$lmove = null;
$lpow = null;
}
return $alg;
}
// Inverts an NxN cube algorithm
function invert_alg($alg){
global $ALG_POW;
$inv = "";
$pow = 1;
$pre = '';
$i = strlen($alg) - 1;
while($i >= 0){
$c = substr($alg, $i, 1);
$mv = fcs_move_id($c);
if($mv != -1){
// Retrive layer depth
if($i > 0){
$pre = substr($alg, $i-1, 1);
if(!is_numeric($pre) || ($i > 1
&& fcs_move_id(substr($alg, $i-2, 1)) != -1))
$pre = '';
else $i--;
}
// Invert and add the move
$inv .= $pre . $c . $ALG_POW[3 - $pow] . ' ';
$pow = 1; $pre = '';
}
else $pow = move_pow(substr($alg, $i, 1));
$i--;
}
return $inv;
}
// Returns an array of algorithm statistics
// including, STM, HTM, QTM and GEN
function alg_stats($alg){
$n = strlen($alg);
$i = 0;
$gen = Array(0, 0, 0, 0, 0, 0, 0, 0, 0);
while($i < $n){
$move = move_id(substr($alg, $i, 1));
if($move != -1){
$pow = 1;
if($i < $n -1) $pow = move_pow(substr($alg, $i + 1, 1));
// If move not a rotation
if($move <= 14){
$stm++;
$htm++;
$qtm_ = 1;
// If its a slice move
if($move >= 12 && $move <=14){
$htm++;
$qtm_ = 2;
}
if($pow == 2) $qtm_ *= 2;
$qtm += $qtm_;
$gen[$move >= 6 ? $move - 6 : $move] = 1;
}
}
$i++;
}
$gn = 0;
foreach($gen as $g) $gn += $g;
return Array($stm, $htm, $qtm, $gn);
}
// Encode orientation
function encode_o($data, $mod){
$o = 0;
for($i = 0; $i < count($data); $i++){
$o = $o * $mod + $data[$i];
}
return $o;
}
// Encode permutation
function encode_p($data){
$p = 0;
$n = count($data);
for($i = 0; $i < $n - 1; $i++){
$p = $p * ($n - $i + 1);
for($j = $i + 1; $j < $n; $j++){
if($data[$i] > $data[$j])
$p += 1;
}
}
return $p;
}
// Returns whether the cubes match
// Entries of -1 are counted as matching
function cube_match($cube1, $cube2){
for($i = 0; $i < count($cube1); $i++){
if(is_array($cube1[$i])){
if(!cube_match($cube1[$i], $cube2[$i])) return false;
}else if(!(
$cube1[$i] == $cube2[$i]
|| $cube1[$i] == -1
|| $cube2[$i] == -1))
return false;
}
return true;
}
// Permutes and orients cube1 by cube2 n times
function prod($cube1, $cube2, $n){
for($i = 0; $i < $n; $i++){
// Centres
$tmp = Array();
for($m = 0; $m < 6; $m++){
// Permute center
$tmp[0][$m] = $cube1[0][$cube2[0][$m]];
}
// Corners
for($c = 0; $c < 8; $c++){
// Permute corner
$tmp[1][$c] = $cube1[1][$cube2[1][$c]];
// Orient corner
$tmp[2][$c] = ($cube1[2][$cube2[1][$c]] + $cube2[2][$c]) % 3;
}
// Edges
for($e = 0; $e < 12; $e++){
// Permute edge
$tmp[3][$e] = $cube1[3][$cube2[3][$e]];
// Orient edge
$tmp[4][$e] = ($cube1[4][$cube2[3][$e]] + $cube2[4][$e]) % 2;
}
$cube1 = $tmp;
}
return $cube1;
}
// Returns the power of a move with given suffix
function move_pow($char){
switch($char){
case "2" : return 2;
case "'" : return 3;
case "3" : return 3;
}
return 1;
}
// Maps move names to a move id
function move_id($move){
switch($move){
case 'U': return 0;
case 'R': return 1;
case 'F': return 2;
case 'D': return 3;
case 'L': return 4;
case 'B': return 5;
case 'u': return 6;
case 'r': return 7;
case 'f': return 8;
case 'd': return 9;
case 'l': return 10;
case 'b': return 11;
case 'E': return 12;
case 'M': return 13;
case 'S': return 14;
case 'y': return 15;
case 'x': return 16;
case 'z': return 17;
}
return -1;
}
// -----------------[ NxNxN Face Cube ]---------------
// Permutes an NxNxN face definition according to the given alg
function fcs_doperm($fcs, $alg, $dim){
$nf = $dim * $dim;
$mt = Array();
// Generate basic move tables
// Twist generic face
$fc_twist = Array();
for($row = 0; $row < $dim; $row++){
for($col = 0; $col < $dim; $col++){
$fc_twist[$row * $dim + $col] = ($dim - $col - 1) * $dim + $row;
}
}
// Inverse twist
$fc_twist2 = Array();
for($row = 0; $row < $dim; $row++){
for($col = 0; $col < $dim; $col++){
$fc_twist2[$row * $dim + $col] = $col * $dim + $dim - $row - 1;
}
}
// Face order for slice turns
$sl_fo = Array(
Array(6, 5, 1, 6, 2, 4), // x
Array(2, 6, 3, 5, 6, 0), // y
Array(4, 0, 6, 1, 3, 6), // z
Array(6, 2, 4, 6, 5, 1), // x'
Array(5, 6, 0, 2, 6, 3), // y'
Array(1, 3, 6, 4, 0, 6), // z'
);
// Sticker order for slice turns
$sl_so = Array( // 1=+col+row, 2=-col+row, 3=+col-row, 4=-col-row,
// 5=+row+col, 6=-row+col, 7=+row-col, 8=-row-col, 0=null
Array(0, 1, 1, 0, 1, 1), // x
Array(8, 0, 8, 8, 0, 5), // y
Array(4, 7, 0, 1, 6, 0), // z
);
// Twist individual slices
$sl_twist = Array();
for($lr = 0; $lr < 6; $lr++){
$sl_twist[$lr] = Array();
for($sl = 0; $sl < $dim; $sl++){
$sl_twist[$lr][$sl] = Array();
for($fc = 0; $fc < 6; $fc++){
if($sl_so[$lr%3][$fc] == 0) continue;
for($i = 0; $i < $dim; $i++){
$sl_twist[$lr][$sl][$fc*$nf + fcs_pos($sl, $i, $sl_so[$lr%3][$fc], $dim)]
= $sl_fo[$lr][$fc]*$nf + fcs_pos($sl, $i, $sl_so[$lr%3][$sl_fo[$lr][$fc]], $dim);
}
}
}
}
// Initialise move tables
$fc_moves = Array();
for($i = 0; $i < $dim * 6; $i++){
for($j = 0; $j < $nf * 6; $j++){
$fc_moves[$i][$j] = $j;
}
}
// Create move tables composed of simple units
// Rotations
for($i = 0; $i < 3; $i++){
// Add all slice moves for axis
for($j = 0; $j < $dim; $j++)
fcs_union($fc_moves[$i], $sl_twist[$i][$j], 0);
// Add twist moves for each end
fcs_union($fc_moves[$i], $fc_twist, $i*$dim*$dim);
fcs_union($fc_moves[$i], $fc_twist2, ($i+3)*$dim*$dim);
}
// Centre-slice moves
if($dim % 2 > 0){
fcs_union($fc_moves[3], $sl_twist[3][floor($dim/2)], 0); // E
fcs_union($fc_moves[4], $sl_twist[4][floor($dim/2)], 0); // M
fcs_union($fc_moves[5], $sl_twist[2][floor($dim/2)], 0); // S
}
// Normal Moves
for($ax = 0; $ax < 3; $ax++){
for($dp = 0; $dp < $dim - 1; $dp++){
// Primary axis end
// Add twist move
fcs_union($fc_moves[6 + $ax*($dim-1) + $dp], $fc_twist, $ax*$dim*$dim);
for($sl = 0; $sl <= $dp; $sl++) // Add slice moves up to depth $dp
fcs_union($fc_moves[6 + $ax*($dim-1) + $dp], $sl_twist[$ax][$sl], 0);
// Secondary axis end
// Add twist move
fcs_union($fc_moves[6 + (3+$ax)*($dim-1) + $dp], $fc_twist, (3+$ax)*$dim*$dim);
for($sl = 0; $sl <= $dp; $sl++) // Add slice moves up to depth $dp
fcs_union($fc_moves[6 + (3+$ax)*($dim-1) + $dp], $sl_twist[3+$ax][$dim - $sl - 1], 0);
}
}
// Carry out moves
$moves = fcs_parse_alg($alg, $dim);
$fcs_ = Array();
if(!is_array($fcs)) $fcs = str_split($fcs);
foreach($moves as $mv){
fcs_permute($fcs, $fcs_, $fc_moves[$mv]);
$tmp = $fcs;
$fcs = $fcs_;
$fcs_ = $tmp;
}
return $fcs;
}
function fcs_pos($r, $c, $o, $d){
$n = $d*$d;
switch($o){
case 1: return $d * $r + $c;
case 2: return $d * ($r + 1) - 1 - $c;
case 3: return $n - $d * ($r + 1) + $c;
case 4: return $n - $d * $r - 1 - $c;
case 5: return $d * $c + $r;
case 6: return $d * ($c + 1) - 1 - $r;
case 7: return $n - $d * ($c + 1) + $r;
case 8: return $n - $d * $c - 1 - $r;
}
}
// Translations defined in $t2 are applied to $t1
function fcs_union(&$t1, &$t2, $offset){
foreach($t2 as $k => $v){
$t1[$k + $offset] = $v + $offset;
}
}
// Permutes given array, storing output in second array
function fcs_permute(&$in, &$out, $perm){
//print_r($perm);
for($i = 0; $i < count($in); $i++)
$out[$i] = $in[$perm[$i]];
//print_r($out);
return $out;
}
// Parses an algorithm string into a move-id sequence
function fcs_parse_alg($alg, $dim){
$moves = Array();
$i = 0;
$j = 0;
$pre = 0;
$len = strlen($alg);
while($i < $len){
$c = substr($alg, $i, 1);
$mv = fcs_move_id($c);
if(is_numeric($c)){
$pre = $c;
}
else if($mv >= 0){
$pow = $i < strlen($alg) - 1 ? move_pow(substr($alg, $i+1, 1)) : 1;
if($pow > 1) $i++;
// Add the move
$pre = $pre < 1 ? 1 : ($pre > $dim - 1 ? $dim - 1 : $pre);
if($mv >= 12){ $mv -= 6; $pre = $pre < 2 ? 2 : $pre; }
for($k = 0; $k < $pow; $k++)
$moves[$j++] = $mv < 6 ? $mv : 6 + ($mv - 6) * ($dim - 1) + ($pre - 1);
$pre = 1;
}
else $pre = 1;
$i++;
}
// echo "|" . $alg . "|";
// print_r($moves);
return $moves;
}
// Maps move names to a move id
function fcs_move_id($move){
switch($move){
case 'y': return 0;
case 'x': return 1;
case 'z': return 2;
case 'E': return 3;
case 'M': return 4;
case 'S': return 5;
case 'U': return 6;
case 'R': return 7;
case 'F': return 8;
case 'D': return 9;
case 'L': return 10;
case 'B': return 11;
case 'u': return 12;
case 'r': return 13;
case 'f': return 14;
case 'd': return 15;
case 'l': return 16;
case 'b': return 17;
}
return -1;
}
// Formats an alg for bigcubes
function fcs_format_alg($alg){
// Fix URL encoded characters (urldecode doesn't seem to remove them)
$r = preg_replace('/%27/', "'", $alg);
$r = preg_replace('/%20/', " ", $r);
// Remove characters not allowed in an alg
$r = preg_replace('/[^UDLRFBudlrfbMESxyzw\'`234567890 ]/', '', $r);
$r = preg_replace('/[`]/', "'", $r); // Replace ` with a '
$r = preg_replace('/2\'|\'2/', "2", $r); // Replace 2' or '2 with a 2
// Fix wide notation
if(preg_match('/[w]/', $r)){
$r = preg_replace('/Uw/', 'u', $r);
$r = preg_replace('/Rw/', 'r', $r);
$r = preg_replace('/Fw/', 'f', $r);
$r = preg_replace('/Dw/', 'd', $r);
$r = preg_replace('/Lw/', 'l', $r);
$r = preg_replace('/Bw/', 'b', $r);
// now remove any extra w's
$r = preg_replace('/w/', '', $r);
}
return $r;
}
// ------------------[ Basic Functions ]--------------
// Copy an array
function array_copy($ary){
if(!is_array($ary)) return $ary;
$out = Array(count($ary));
foreach($ary as $k => $v){
$out[$k] = array_copy($v);
}
return $out;
}
?>
================================================
FILE: db_schema.sql
================================================
/** Caches generated visual cubes.
Stores the parameters used to generate the image,
the latest referrer to request the image,
and the request frequencey */
CREATE TABLE vcache(
hash CHAR(32) NOT NULL,
fmt CHAR(4) NOT NULL,
req VARCHAR(255) NOT NULL,
rfr VARCHAR(255) NOT NULL,
rcount INT UNSIGNED NOT NULL,
img MEDIUMBLOB,
PRIMARY KEY (hash));
/** View contents with: */
SELECT hash, fmt, req, rfr, rcount, OCTET_LENGTH(img) FROM vcache;
================================================
FILE: screen.css
================================================
body{
margin:0;
text-align:center;
font-size:10pt;
font-family:Verdana, Geneva, Arial, Helvetica, sans-serif;
}
h1{
color:#888;
text-decoration:none;
font-family:Arial, Helvetica, sans-serif;
font-size:1.8em;
font-weight:bold;
}
h2{
margin-top:6em;
font-size:1.2em;
font-weight:bold;
}
h3{
margin-top:2em;
font-size:1.0em;
font-weight:bold;
}
em{
font-style:normal;
font-weight:bold;
}
img{
border:0;
float:right;
}
.imgarea{
text-align:center;
}
.imgarea img{
float:none;
}
.imglist img{
float:right;
}
.biglist li{
margin-bottom:15px;
}
.it{
font-style:italic;
}
.capimg2{
float:left;
width:220px;
text-align:center;
font-size:0.8em;
}
.capimg2 img{
float:none;
}
.capimg3{
float:left;
width:150px;
text-align:center;
font-size:0.8em;
}
.capimg3 img{
float:none;
}
.imglist li{
clear:both;
}
#container{
width:800px;
min-height:350px;
margin:10px auto 0 auto;
background-image:url('bg.png');
background-repeat:no-repeat;
}
#header{
width:450px;
margin:0 auto;
text-align:left;
}
#header a{
}
#header img{
float:right;
border:none;
}
#nav_box{
text-align:left;
float:right;
margin-right:20px;
margin-top:20px;
border:1px solid #888888;
background:#888888;
font-weight:bold;
color:#FFFFFF;
}
#nav_box ul{
list-style:none;
padding:5px;
margin:0px;
background:#F8F8F8;
}
#nav_box li{
color:#666666;
font-weight:normal;
margin:1px 0;
}
#content{
width:450px;
margin:20px auto;
text-align:left;
font-size:1em;
}
#content .backlink{
margin-top:10px;
}
#footer{
width:450px;
margin:0 auto;
font-size:0.8em;
color:#AAA;
}
.spaced_box{
margin-top:50px;
}
.term_list{
list-style:none;
padding-left:20px;
}
.term_list li{
clear:both;
padding-top:10px;
}
.term_list em{
display:block;
float:left;
}
.term_list span{
display:block;
font-weight:normal;
width:300px;
float:right;
}
.form{
margin-top:20px;
text-align:center;
}
.form_content{
width:350px;
margin:0 auto;
padding:5px 10px;
background:transparent;
border:0px solid #CCC;
}
.form_record{
clear:both;
}
.form_record .label{
text-align:left;
width:130px;
float:left;
margin:7px 0;
}
.form_record .data{
text-align:left;
float:right;
margin:7px 0;
}
.form_record .data input,select,textarea{
width:200px;
}
.form_record .data textarea{
height:4em;
}
.form_textbox{
clear:both;
}
.form_textbox textarea{
width:100%;
height:8em;
}
.form_submit{
clear:both;
text-align:right;
}
================================================
FILE: visualcube.php
================================================
<?php
/*
File: visualcube.php
Date: 02 Apr 2010
Author(s): Conrad Rider (www.crider.co.uk)
Contributors: Shotaro Makisumi <smakisumi@gmail.com>, Jaume Casado Ruiz <minterior@gmail.com>
Description: Main script to generate cube images
This file is part of VisualCube.
VisualCube is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
VisualCube is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
Copyright (C) 2010 Conrad Rider
TODO:
* Automatic Permutation Arrows
* Other puzzles
CHANGES:
(Version 0.5.5 to 0.5.6)
* Modified options to attempt to fix rendering issues in ImageMagick v6.9.x
(Version 0.5.4 to 0.5.5)
* Changed to using style attribute to fix transparrancy issues
(Version 0.5.3 to 0.5.4)
* Added configurable DB host
* Added configurable path to ImageMagick convert binary
(Version 0.5.2 to 0.5.3)
* Fixed links on API page
* Changed default format to SVG, avoiding ImageMagick failures
* Addressed PHP warnings and fixed typos in the code
(Version 0.5.1 to 0.5.2)
* Separate configuration file
* Separate API definition file - easier to provide custom API page
(Version 0.3.0 to 0.4.0)
* Algs applicable to NxNxN cubes
* Wider range of stage masks, with the ability to rotate them
* Style variables configurable via cookies
*/
// Import configuration values
require 'visualcube_config.php';
global
$DB_HOST,
$DB_NAME,
$DB_USERNAME,
$DB_PASSWORD,
$MAX_PZL_DIM,
$ENABLE_COOKIES,
$ENABLE_CACHE,
$CACHE_IMG_SIZE_LIMIT,
$DEFAULTS;
// VisualCube version
$VERSION = "0.5.5";
// Causes cube svg to be outputted as XML for inspection
$DEBUG = false;
// Do not display errors
// if (!$DEBUG) error_reporting(0);
// ----------------------[ API Page ]-----------------------
// If no format specified, display API page
if(!array_key_exists('fmt', $_REQUEST)){
include 'visualcube_api.php';
// Otherwise render a cube
}else{
// Check cache for image and return if it exists in cache
if($ENABLE_CACHE){
// Connect to db
$mysql_con = mysqli_connect($DB_HOST, $DB_USERNAME, $DB_PASSWORD, $DB_NAME) or die("Connect Error: " . mysqli_connect_error());
$hash = md5($_SERVER['QUERY_STRING']);
$imgdata = get_arrays($mysql_con, "SELECT fmt, req, rcount, img FROM vcache WHERE hash='$hash'");
// Verify query strings are equal (deals with unlikely, but possible hash collisions)
if($imgdata && count($imgdata) > 0 && $imgdata[0]['req'] == $_SERVER['QUERY_STRING']){
display_img($imgdata[0]['img'], $imgdata[0]['fmt']);
// Increment access count
mysqli_query($mysql_con, "UPDATE vcache SET rcount=rcount+1 WHERE hash='$hash'");
// Disconnect from db
mysqli_close();
return;
}
}
// Otherwise generate image
// -----------------[ Constants ]-----------------
// Faces
$U = 0; $R = 1; $F = 2; $D = 3; $L = 4; $B = 5; $N = 6; $O = 7; $T = 8;
// Colour constants
$BLACK = '000000';
$DGREY = '404040';
$GREY = '808080';
$SILVER = 'BFBFBF';
$WHITE = 'FFFFFF';
$YELLOW = 'FEFE00';
$RED = 'EE0000';//'FE0000';
$ORANGE = 'FFA100';//'FE8600';
$BLUE = '0000F2';
$GREEN = '00D800';//'00F300';
$PURPLE = 'A83DD9';
$PINK = 'F33D7B';
// Other colour schemes
// Array('FFFF00', 'FF0000', '0000FF', 'FFFFFF', 'FF7F00', '00FF00'); // Basic
// Array('EFEF00', 'C80000', '0000B6', 'F7F7F7', 'FFA100', '00B648'); // Cubestation
// Array('EFFF01', 'FF0000', '1600FF', 'FEFFFC', 'FF8000', '047F01'); // cube.rider
// Array('FEFE00', 'FE0000', '0000F2', 'FEFEFE', 'FE8600', '00F300'); // alg.garron
// Name colour mapping
$NAME_COL = Array(
'black' => $BLACK,
'dgrey' => $DGREY,
'grey' => $GREY,
'silver' => $SILVER,
'white' => $WHITE,
'yellow' => $YELLOW,
'red' => $RED,
'orange' => $ORANGE,
'blue' => $BLUE,
'green' => $GREEN,
'purple' => $PURPLE,
'pink' => $PINK);
// Abbreviation colour mapping
$ABBR_COL = Array(
'n' => $BLACK,
'd' => $DGREY,
'l' => $GREY,
's' => $SILVER,
'w' => $WHITE,
'y' => $YELLOW,
'r' => $RED,
'o' => $ORANGE,
'b' => $BLUE,
'g' => $GREEN,
'm' => $PURPLE,
'p' => $PINK,
't' => 't'); // Transparent
// Default colour scheme
$DEF_SCHEME = Array ($YELLOW, $RED, $BLUE, $WHITE, $ORANGE, $GREEN, $DGREY, $GREY, 't');
// $DEF_SCHEME = Array ($WHITE, $RED, $GREEN, $BLUE, $ORANGE, $YELLOW, $GREY, $SILVER, 't'); // Japanese scheme
// Corresponding mappings from colour code to face id
$DEF_SCHCODE = Array('y', 'r', 'b', 'w', 'o', 'g',);
//$DEF_SCHCODE = Array('w', 'r', 'g', 'b', 'o', 'y',); // Japanese scheme
// -----------------------[ User Parameters ]--------------------
// Retrieve format from user, default to first in list otherwise
$LEGAL_FMT = Array ('gif', 'png', 'svg', 'jpg', 'jpe', 'jpeg', 'tiff', 'ico');
$fmt = $LEGAL_FMT[0];
if(array_key_exists('fmt', $_REQUEST) || array_key_exists('fmt', $DEFAULTS)){
$fmt = array_key_exists('fmt', $_REQUEST) ? $_REQUEST['fmt'] : $DEFAULTS['fmt'];
if(!in_array($fmt, $LEGAL_FMT))
$fmt = $LEGAL_FMT[0];
else{
if($fmt == 'jpeg' || $fmt == 'jpe') $fmt = 'jpg';
}
}
// Default rotation sequence
$rtn = Array(Array(1, 45), Array(0, -34));
// Get rotation from request (or cookie)
if(array_key_exists('r', $_REQUEST) || array_key_exists('r', $DEFAULTS)
|| ($ENABLE_COOKIES && isset($_COOKIE['vc_r']) && $_COOKIE['vc_r'] != '')){
$_r = array_key_exists('r', $_REQUEST) ? $_REQUEST['r'] :
($ENABLE_COOKIES && isset($_COOKIE['vc_r']) && $_COOKIE['vc_r'] != '' ?
$_COOKIE['vc_r'] : $DEFAULTS['r']);
preg_match_all('/([xyz])(\-?[0-9][0-9]?[0-9]?)/', $_r, $matches);
for($i = 0; $i < count($matches[0]); $i++){
switch($matches[1][$i]){
case 'x' : $rtn_[$i][0] = 0; break;
case 'y' : $rtn_[$i][0] = 1; break;
case 'z' : $rtn_[$i][0] = 2; break;
default : break;
}
$rtn_[$i][1] = $matches[2][$i];
}
if($rtn_) $rtn = $rtn_;
}
// Retrieve cube Dimension
$dim = $DEFAULTS['pzl'];
if(array_key_exists('pzl', $_REQUEST) && is_numeric($_REQUEST['pzl'])
&& $_REQUEST['pzl'] > 0 && $_REQUEST['pzl'] <= $MAX_PZL_DIM)
$dim = $_REQUEST['pzl'];
// Default scheme
$scheme = $DEF_SCHEME;
// Default mapping from colour code to face id
$schcode = $DEF_SCHCODE;
// Retrieve colour scheme from request (or cookie)
if(array_key_exists('sch', $_REQUEST) || array_key_exists('sch', $DEFAULTS)
|| ($ENABLE_COOKIES && isset($_COOKIE['vc_sch']) && $_COOKIE['vc_sch'] != '')){
// Retrieve from cookie or 'sch' variable
$sd = array_key_exists('sch', $_REQUEST) ? $_REQUEST['sch'] :
($ENABLE_COOKIES && isset($_COOKIE['vc_sch']) && $_COOKIE['vc_sch'] != '' ?
$_COOKIE['vc_sch'] : $DEFAULTS['sch']);
if(preg_match('/^[ndlswyrogbpmt]{6}$/', $sd)){
for($i = 0; $i < 6; $i++){
$scheme[$i] = $ABBR_COL[$sd[$i]];
$schcode[$i] = $sd[$i];
}
}
else{
$cols = preg_split('/,/', $sd);
if(count($cols) == 6){
$cok = true;
for($i = 0; $i < 6; $i++){
$scheme[$i] = parse_col($cols[$i]);
if(!$cols[$i]) $cok = false;
}
if(!$cok) $scheme = $DEF_SCHEME;
}
}
}
// Retrieve size from user
$size = $DEFAULTS['size']; // default
if(array_key_exists('size', $_REQUEST) && is_numeric($_REQUEST['size'])){
$size = $_REQUEST['size'];
if($size < 0) $size = 0;
if($size > 1024) $size = 1024;
}
// Retrieve dist variable - projection distance (how close the eye is to the cube)
$dist = $DEFAULTS['dist']; // default dist parameter
if(array_key_exists('dist', $_REQUEST) || ($ENABLE_COOKIES && isset($_COOKIE['vc_dist']))){
$dist_ = array_key_exists('dist', $_REQUEST) ? $_REQUEST['dist'] : $_COOKIE['vc_dist'];
if(is_numeric($dist_)) $dist = $dist_ < 1 ? 1 : ($dist_ > 100 ? 100 : $dist_);
}
// Retrieve view variable
$view = $DEFAULTS['view'];
if(array_key_exists('view', $_REQUEST)){
$view = $_REQUEST['view'];
}
// Retrieve background colour from request (or cookies)
$bg = parse_col($DEFAULTS['bg']);
if(!$bg) $bg = 'FFFFFF';
if(array_key_exists('bg', $_REQUEST) || ($ENABLE_COOKIES && isset($_COOKIE['vc_bg']))){
$bg_ = array_key_exists('bg', $_REQUEST) ? $_REQUEST['bg'] : $_COOKIE['vc_bg'];
if($bg_ == "t") $bg = null;
else{
$bg_ = parse_col($bg_);
if($bg_) $bg = $bg_;
}
}
// Retrieve cube colour from request (or cookies)
$cc = $view == 'trans' ? $SILVER : parse_col($DEFAULTS['cc']);
if(array_key_exists('cc', $_REQUEST) || ($ENABLE_COOKIES && isset($_COOKIE['vc_cc']))){
$cc_ = array_key_exists('cc', $_REQUEST) ? $_REQUEST['cc'] : $_COOKIE['vc_cc'];
$cc_ = parse_col($cc_);
if($cc_) $cc = $cc_;
}
$cc = !$cc ? $BLACK : $cc;
// Retrieve cube opacity from request (or cookies)
$co = $view == 'trans' ? 50 : $DEFAULTS['co'];
if(array_key_exists('co', $_REQUEST) || ($ENABLE_COOKIES && isset($_COOKIE['vc_co']))){
$co_ = array_key_exists('co', $_REQUEST) ? $_REQUEST['co'] : $_COOKIE['vc_co'];
if(preg_match('/^[0-9][0-9]?$/', $co_)) $co = $co_;
}
$co = !is_numeric($co) || $co < 0 || $co > 100 ? 100 : $co;
// Retrieve face opacity from request (or cookies)
$fo = $DEFAULTS['fo'];
if(!is_numeric($fo) || $fo < 0 || $fo > 100)
$fo = 100;
if(array_key_exists('fo', $_REQUEST) || ($ENABLE_COOKIES && isset($_COOKIE['vc_fo']))){
$fo_ = array_key_exists('fo', $_REQUEST) ? $_REQUEST['fo'] : $_COOKIE['vc_fo'];
if(preg_match('/^[0-9][0-9]?$/', $fo_)) $fo = $fo_;
}
// Create default face defs
for($fc = 0; $fc < 6; $fc++){ for($i = 0; $i < $dim * $dim; $i++)
$facelets[$fc * $dim * $dim + $i] = $fc;
}
// Retrieve colour def
// This overrides face def and makes the $scheme variable redundant (ie, gets reset to default)
$using_cols = false;
$uf = array_key_exists('fc', $_REQUEST) ? $_REQUEST['fc'] : (!array_key_exists('fd', $_REQUEST) ? $DEFAULTS['fc'] : '');
if(preg_match('/^[ndlswyrobgmpt]+$/', $uf)){
$using_cols = true;
$scheme = $DEF_SCHEME;
$nf = strlen($uf);
for($fc = 0; $fc < 6; $fc++){ for($i = 0; $i < $dim * $dim; $i++){
// Add user defined face
if($fc * $dim *$dim + $i < $nf)
$facelets[$fc * $dim * $dim + $i] = $uf[$fc * $dim *$dim + $i];
// Otherwise use scheme code
else
$facelets[$fc * $dim * $dim + $i] = $schcode[$fc];
}}
}
// Retrieve facelet def
if(!$uf){ $uf = array_key_exists('fd', $_REQUEST) ? $_REQUEST['fd'] : $DEFAULTS['fd'];
if(preg_match('/^[udlrfbnot]+$/', $uf)){
// Map from face names to numeric face ID
$fd_map = Array('u' => $U, 'r' => $R, 'f' => $F, 'd' => $D, 'l' => $L, 'b' => $B, 'n' => $N, 'o' => $O, 't' => $T);
$nf = strlen($uf);
for($fc = 0; $fc < 6; $fc++){ for($i = 0; $i < $dim * $dim; $i++){
// Add user defined face
if($fc * $dim *$dim + $i < $nf)
$facelets[$fc * $dim * $dim + $i] = $fd_map[$uf[$fc * $dim *$dim + $i]];
// Otherwise default to a blank/transparent face
else $facelets[$fc * $dim *$dim + $i] = $view == 'trans' ? $T : $N;
}}
}}
// Retrieve stage variable
if(array_key_exists('stage', $_REQUEST) || array_key_exists('stage', $DEFAULTS)){
$stage = array_key_exists('stage', $_REQUEST) ? $_REQUEST['stage'] : $DEFAULTS['stage'];
// Extract rotation sequence if present
$p = strrpos($stage, '-');
$st_rtn = '';
if($p > 0){
$st_rtn = urldecode(substr($stage, $p+1));
$stage = substr($stage, 0, $p);
}
// Stage Definitions
$mask = '';
if($dim == 3){
switch($stage){
case 'fl' :
$mask = "000000000000000111000000111111111111000000111000000111";
break;
case 'f2l' :
$mask = "000000000000111111000111111111111111000111111000111111";
break;
case 'll' :
$mask = "111111111111000000111000000000000000111000000111000000";
break;
case 'cll' :
$mask = "101010101101000000101000000000000000101000000101000000";
break;
case 'ell' :
$mask = "010111010010000000010000000000000000010000000010000000";
break;
case 'oll' :
$mask = "111111111000000000000000000000000000000000000000000000";
break;
case 'ocll' :
$mask = "101010101000000000000000000000000000000000000000000000";
break;
case 'oell' :
$mask = "010111010000000000000000000000000000000000000000000000";
break;
case 'coll' :
$mask = "111111111101000000101000000000000000101000000101000000";
break;
case 'ocell' :
$mask = "111111111010000000010000000000000000010000000010000000";
break;
case 'wv' :
$mask = "111111111000111111000111111111111111000111111000111111";
break;
case 'vh' :
$mask = "010111010000111111000111111111111111000111111000111111";
break;
case 'els' :
$mask = "010111010000111011000111110110111111000111111000111111";
break;
case 'cls' :
$mask = "111111111000111111000111111111111111000111111000111111";
break;
case 'cmll' :
$mask = "101000101101111111101101101101101101101111111101101101";
break;
case 'cross' :
$mask = "000000000000010010000010010010111010000010010000010010";
break;
case 'f2l_3' :
$mask = "000000000000110110000011011011111010000010010000010010";
break;
case 'f2l_2' :
$mask = "000000000000011011000010010010111111000110110000111111";
break;
case 'f2l_sm' :
$mask = "000000000000110110000011011011111110000110110000011011";
break;
case 'f2l_1' :
$mask = "000000000000011011000110110110111111000111111000111111";
break;
case 'f2b' :
$mask = "000000000000111111000101101101101101000111111000101101";
break;
case 'line' :
$mask = "000000000000000000000010010010010010000000000000010010";
break;
case '2x2x2' :
$mask = "000000000000110110000011011011011000000000000000000000";
break;
case '2x2x3' :
$mask = "000000000000110110000111111111111000000011011000000000";
break;
}
}else if($dim == 2){
switch($stage){
case 'fl' :
$mask = "000000110011111100110011";
break;
case 'll' :
$mask = "111111001100000011001100";
break;
case 'oll' :
$mask = "111100000000111100000000";
break;
}
}
// Apply alg to mask if defined
if($mask && $st_rtn != ''){
require_once "cube_lib.php";
$mask = fcs_doperm($mask, fcs_format_alg($st_rtn), $dim);
}
// Apply mask to face def
if($mask){
for($i = 0; $i < $dim * $dim * 6; $i++){
$facelets[$i] = $mask[$i] == 0 ?
($view == 'trans' ? ($using_cols ? 't' : $T) :
($using_cols ? 'l' : $N)) : $facelets[$i];
}
}
}
// Retrieve alg def
if(array_key_exists('alg', $_REQUEST) || array_key_exists('case', $_REQUEST)
|| array_key_exists('alg', $DEFAULTS) || array_key_exists('case', $DEFAULTS)){
require_once "cube_lib.php";
if(array_key_exists('alg', $_REQUEST)) $alg = $_REQUEST['alg']; else $alg = $DEFAULTS['alg'];
if(array_key_exists('case', $_REQUEST)) $case = $_REQUEST['case']; else $case = $DEFAULTS['case'];
$alg = fcs_format_alg(urldecode($alg));
$case = invert_alg(fcs_format_alg(urldecode($case)));
// $facelets = facelet_cube(case_cube($alg), $dim, $facelets); // old 3x3 alg system
$facelets = fcs_doperm($facelets, $case . ' ' . $alg, $dim); // new NxN facelet permute
}
// Retrieve arrow defn's
if(array_key_exists('arw', $_REQUEST)){
$astr = preg_split('/,/', $_REQUEST['arw']);
$i = 0;
foreach($astr as $a){
$a_ = parse_arrow($a, $dim);
if($a_) $arrows[$i++] = $a_;
}
}
// Retrieve default arrow colour
$ac = $GREY;
if(array_key_exists('ac', $_REQUEST)){
$ac_ = parse_col($_REQUEST['ac']);
if($ac_ && $ac_ != 't') $ac = $ac_;
}
// ---------------[ 3D Cube Generator properties ]---------------
// Outline width
$OUTLINE_WIDTH = 0.94;
// Stroke width
$sw = 0;
// Viewport
$ox = -0.9;
$oy = -0.9;
$vw = 1.8;
$vh = 1.8;
// ------------------[ 3D Cube Generator ]-----------------------
// Set up cube for OLL view if specified
if($view == 'plan'){
$rtn = Array(Array(0, -90));
}
// All cube face points
$p = Array();
// Translation vector to centre the cube
$t = Array(-$dim/2, -$dim/2, -$dim/2);
// Translation vector to move the cube away from viewer
$zpos = Array(0, 0, $dist);
// Rotation vectors to track visibility of each face
$rv = Array(Array(0, -1, 0), Array(1, 0, 0), Array(0, 0, -1), Array(0, 1, 0), Array(-1, 0, 0), Array(0, 0, 1));
for($fc = 0; $fc < 6; $fc++){
for($i = 0; $i <= $dim; $i++){
for($j = 0; $j <= $dim; $j++){
switch($fc){
case $U : $p[$fc][$i][$j] = Array( $i, 0, $dim - $j); break;
case $R : $p[$fc][$i][$j] = Array( $dim, $j, $i); break;
case $F : $p[$fc][$i][$j] = Array( $i, $j, 0); break;
case $D : $p[$fc][$i][$j] = Array( $i, $dim, $j); break;
case $L : $p[$fc][$i][$j] = Array( 0, $j, $dim - $i); break;
case $B : $p[$fc][$i][$j] = Array($dim - $i, $j, $dim); break;
}
// Now scale and tranform point to ensure size/pos independent of dim
$p[$fc][$i][$j] = translate($p[$fc][$i][$j], $t);
$p[$fc][$i][$j] = scale($p[$fc][$i][$j], 1 / $dim);
// Rotate cube as per perameter settings
foreach($rtn as $rn){
$p[$fc][$i][$j] = rotate($p[$fc][$i][$j], $rn[0], M_PI * $rn[1]/180);
}
// Move cube away from viewer
$p[$fc][$i][$j] = translate($p[$fc][$i][$j], $zpos);
// Finally project the 3D points onto 2D
$p[$fc][$i][$j] = project($p[$fc][$i][$j], $zpos[2]);
}
}
// Rotate rotation vectors
foreach($rtn as $rn){
$rv[$fc] = rotate($rv[$fc], $rn[0], M_PI * $rn[1]/180);
}
}
// Sort render order (crappy bubble sort)
$ro = Array(0, 1, 2, 3, 4, 5);
for($i = 0; $i < 5; $i++){ for($j = 0; $j < 5; $j++){
if($rv[$ro[$j]][2] < $rv[$ro[$j+1]][2]){
$t = $ro[$j]; $ro[$j] = $ro[$j+1]; $ro[$j+1] = $t; }
}}
// Cube diagram SVG XML
$cube = "<?xml version='1.0' standalone='no'?>
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN'
'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>
<svg version='1.1' xmlns='http://www.w3.org/2000/svg'
width='$size' height='$size'
viewBox='$ox $oy $vw $vh'>\n";
// Draw background
if($bg) $cube .= "\t<rect fill='#$bg' x='$ox' y='$oy' width='$vw' height='$vh'/>\n";
// Transparancy background rendering
if($co < 100){
// Create polygon for each background facelet (transparency only)
$cube .= "\t<g style='opacity:".($fo/100).";stroke-opacity:0.5;stroke-width:$sw;stroke-linejoin:round'>\n";
for($ri = 0; $ri < 3; $ri++){
$cube .= facelet_svg($ro[$ri]);
}
$cube .= "\t</g>\n";
// Create outline for each background face (transparency only)
$cube .= "\t<g style='stroke-width:0.1;stroke-linejoin:round;opacity:".($co/100)."'>\n";
for($ri = 0; $ri < 3; $ri++)
$cube .= outline_svg($ro[$ri]);
$cube .= "\t</g>\n";
}
// Create outline for each visible face
$cube .= "\t<g style='stroke-width:0.1;stroke-linejoin:round;opacity:".($co/100)."'>\n";
for($ri = 3; $ri < 6; $ri++){
if(face_visible($ro[$ri], $rv) || $co < 100)
$cube .= outline_svg($ro[$ri]);
}
$cube .= "\t</g>\n";
// Create polygon for each visible facelet
$cube .= "\t<g style='opacity:".($fo/100).";stroke-opacity:0.5;stroke-width:$sw;stroke-linejoin:round'>\n";
for($ri = 3; $ri < 6; $ri++){
if(face_visible($ro[$ri], $rv) || $co < 100)
$cube .= facelet_svg($ro[$ri]);
}
$cube .= "\t</g>\n";
// Create OLL view guides
if($view == 'plan'){
$cube .= "\t<g style='opacity:".($fo/100).";stroke-opacity:1;stroke-width:0.02;stroke-linejoin:round'>\n";
$toRender = Array($F, $L, $B, $R);
foreach($toRender as $fc)
$cube .= oll_svg($fc);
$cube .= "\t</g>\n";
}
// Draw Arrows
if(isset($arrows)){
$awidth = 0.12 / $dim;
$cube .= "\t<g style='opacity:1;stroke-opacity:1;stroke-width:$awidth;stroke-linecap:round'>\n";
foreach($arrows as $i => $a){
$cube .= gen_arrow($i, $a[0], $a[1], $a[2], $a[4], array_key_exists(3, $a)?$a[3]:$ac);
}
$cube .= "\t</g>\n";
}
$cube .= "</svg>\n";
// Display cube
if($DEBUG) echo $cube;
else{
$img = $fmt != 'svg' ? convert($cube, $fmt, $size) : $cube;
display_img($img, $fmt);
// Cache image if enabled
if($ENABLE_CACHE && !array_key_exists("nocache", $_REQUEST) && strlen($img) < $CACHE_IMG_SIZE_LIMIT){
$req = mysqli_real_escape_string($mysql_con, $_SERVER['QUERY_STRING']);
$rfr = mysqli_real_escape_string($mysql_con, $_SERVER['HTTP_REFERER']);
$hash = md5($req);
$img = mysqli_real_escape_string($mysql_con, $img);
mysqli_query($mysql_con, "INSERT INTO vcache(hash, fmt, req, rfr, rcount, img) ".
"VALUES ('$hash', '$fmt', '$req', '$rfr', 1, '$img')");
// Disconnect from db
mysqli_close();
}
}
}
// -----------------[ User input functions ]----------------------
// Parse colour value
function parse_col($col){
global $NAME_COL, $ABBR_COL;
// As an abbriviation
if(preg_match('/^[ndlswyrogbpmt]$/', $col))
return $ABBR_COL[$col];
// As a name
if(array_key_exists($col, $NAME_COL))
return $NAME_COL[$col];
// As 12-bit colour
if(preg_match('/^[0-9a-fA-F]{3}$/', $col))
return $col[0].$col[0].$col[1].$col[1].$col[2].$col[2];
// As 24-bit colour
if(preg_match('/^[0-9a-fA-F]{6}$/', $col))
return $col;
// Otherwise fail
return null;
}
// Parse arrow definition
function parse_arrow($str, $dim){
$parts = preg_split('/-/', $str);
$fcodes = array('U' => 0, 'R' => 1, 'F' => 2, 'D' => 3, 'L' => 4, 'B' => 5);
if(count($parts) == 0) return null;
if(!preg_match_all('/([URFDLB])([0-9]+)/', $parts[0], $split) || count($split) < 2) return null;
$arrow = array();
$arrow[4] = 1;
for($i = 0; $i < 3; $i++){
if($i == 2 && count($split[1]) < 3){
$arrow[2] = null;
break;
}
else $arrow[2][3] = 2;
$arrow[$i][0] = $fcodes[$split[1][$i]];
$fn = $split[2][$i]; $fn = $fn >= $dim * $dim ? $dim * $dim - 1 : $fn;
$arrow[$i][1] = $fn % $dim;
$arrow[$i][2] = floor($fn / $dim);
}
// Parse remainder
for($i = 1; $i < count($parts); $i++){
if(preg_match('/^i[0-9]+$/', $parts[$i]) && $arrow[2]){
$arrow[2][3] = substr($parts[$i],1) / 5;
$arrow[2][3] = $arrow[2][3] > 10 ? 10 : $arrow[2][3]; // Var range = 0 to 50, default 10
}
else if(preg_match('/^s[0-9]+$/', $parts[$i])){
$arrow[4] = substr($parts[$i],1) / 10;
$arrow[4] = $arrow[4] > 2 ? 2 : $arrow[4]; // Var range = 0 to 20, default 10
}
else{
$ac_ = parse_col($parts[$i]);
if($ac_) $arrow[3] = $ac_;
}
}
return $arrow;
}
// Insert space in default fd/fc variables
function insert_space($in, $dim){
$out = '';
$dim *= $dim;
for($i = 0; $i < 6; $i++){
$out .= substr($in, $dim * $i, $dim) . ' ';
}
return $out;
}
// -------------------[ 3D Geometry Functions ]--------------------
// Move point by translation vector
function translate($p, $t){
$p[0] += $t[0];
$p[1] += $t[1];
$p[2] += $t[2];
return $p;
}
function scale($p, $f){
$p[0] *= $f;
$p[1] *= $f;
$p[2] *= $f;
return $p;
}
// Scale point relative to position vector
function trans_scale($p, $v, $f){
// Translate each facelet to cf
$iv = Array(-$v[0], -$v[1], -$v[2]);
return translate(scale(translate($p, $iv), $f), $v);
}
function rotate($p, $ax, $an){
$np = Array($p[0], $p[1], $p[2]);
switch($ax){
case 0 :
$np[2] = $p[2] * cos($an) - $p[1] * sin($an);
$np[1] = $p[2] * sin($an) + $p[1] * cos($an);
break;
case 1 :
$np[0] = $p[0] * cos($an) + $p[2] * sin($an);
$np[2] = - $p[0] * sin($an) + $p[2] * cos($an);
break;
case 2 :
$np[0] = $p[0] * cos($an) - $p[1] * sin($an);
$np[1] = $p[0] * sin($an) + $p[1] * cos($an);
break;
}
return $np;
}
// Project 3D points onto a 2D plane
function project($p, $d){
return Array(
$p[0] * $d / $p[2],
$p[1] * $d / $p[2],
$p[2] // Maintain z coordinate to allow use of rendering tricks
);
}
// Returns whether a face is visible
function face_visible($face, $rv){
return $rv[$face][2] < -0.105;
}
// ---------------------------[ Rendering Functions ]----------------------------
// Returns svg for a cube outline
function outline_svg($fc){
global $p, $dim, $cc, $OUTLINE_WIDTH;
return "\t\t<polygon fill='#$cc' stroke='#$cc' points='".
$p[$fc][ 0][ 0][0]*$OUTLINE_WIDTH.','.$p[$fc][ 0][ 0][1]*$OUTLINE_WIDTH.' '.
$p[$fc][$dim][ 0][0]*$OUTLINE_WIDTH.','.$p[$fc][$dim][ 0][1]*$OUTLINE_WIDTH.' '.
$p[$fc][$dim][$dim][0]*$OUTLINE_WIDTH.','.$p[$fc][$dim][$dim][1]*$OUTLINE_WIDTH.' '.
$p[$fc][ 0][$dim][0]*$OUTLINE_WIDTH.','.$p[$fc][ 0][$dim][1]*$OUTLINE_WIDTH."'/>\n";
}
// Returns svg for a faces facelets
function facelet_svg($fc){
global $p, $dim;
$svg = '';
for($i = 0; $i < $dim; $i++){
for($j = 0; $j < $dim; $j++){
// Find centre point of facelet
$cf = Array(($p[$fc][$j ][$i ][0] + $p[$fc][$j+1][$i+1][0])/2,
($p[$fc][$j ][$i ][1] + $p[$fc][$j+1][$i+1][1])/2, 0);
// Scale points in towards centre
$p1 = trans_scale($p[$fc][$j ][$i ], $cf, 0.85);
$p2 = trans_scale($p[$fc][$j+1][$i ], $cf, 0.85);
$p3 = trans_scale($p[$fc][$j+1][$i+1], $cf, 0.85);
$p4 = trans_scale($p[$fc][$j ][$i+1], $cf, 0.85);
// Generate facelet polygon
$svg .= gen_facelet($p1, $p2, $p3, $p4, $fc * $dim * $dim + $i * $dim + $j);
}
}
return $svg;
}
// Renders the top rim of the R U L and B faces out from side of cube
function oll_svg($fc){
global $p, $dim, $rv;
$svg = '';
// Translation vector, to move faces out
$tv1 = scale($rv[$fc], 0.00);
$tv2 = scale($rv[$fc], 0.20);
$i = 0;
for($j = 0; $j < $dim; $j++){
// Find centre point of facelet
$cf = Array(($p[$fc][$j ][$i ][0] + $p[$fc][$j+1][$i+1][0])/2,
($p[$fc][$j ][$i ][1] + $p[$fc][$j+1][$i+1][1])/2, 0);
// Scale points in towards centre and skew
$p1 = translate(trans_scale($p[$fc][$j ][$i ], $cf, 0.94), $tv1);
$p2 = translate(trans_scale($p[$fc][$j+1][$i ], $cf, 0.94), $tv1);
$p3 = translate(trans_scale($p[$fc][$j+1][$i+1], $cf, 0.94), $tv2);
$p4 = translate(trans_scale($p[$fc][$j ][$i+1], $cf, 0.94), $tv2);
// Generate facelet polygon
$svg .= gen_facelet($p1, $p2, $p3, $p4, $fc * $dim * $dim + $i * $dim + $j);
}
return $svg;
}
/** Generates a polygon SVG tag for cube facelets */
function gen_facelet($p1, $p2, $p3, $p4, $seq){
global $ABBR_COL, $facelets, $scheme, $using_cols, $cc, $T;
$fcol = $using_cols ? ($facelets[$seq] == 't' ? 't' : $ABBR_COL[$facelets[$seq]])
: ($facelets[$seq] == $T ? 't' : $scheme[$facelets[$seq]]);
return "\t\t<polygon fill='#".
($fcol == 't' ? '000000' : $fcol)."' stroke='#$cc' ".
($fcol == 't' ? "opacity='0' " : ' ' )."points='".
$p1[0].','.$p1[1].' '.
$p2[0].','.$p2[1].' '.
$p3[0].','.$p3[1].' '.
$p4[0].','.$p4[1]."'/>\n";
}
// Generates svg for an arrow pointing from sticker s1 to s2
function gen_arrow($id, $s1, $s2, $sv, $sc, $col){
global $p, $dim;
if($col == 't') return;
// Find centre point of each facelet
$p1 = Array(($p[$s1[0]][$s1[1]][$s1[2]][0] + $p[$s1[0]][$s1[1]+1][$s1[2]+1][0])/2,
($p[$s1[0]][$s1[1]][$s1[2]][1] + $p[$s1[0]][$s1[1]+1][$s1[2]+1][1])/2, 0);
$p2 = Array(($p[$s2[0]][$s2[1]][$s2[2]][0] + $p[$s2[0]][$s2[1]+1][$s2[2]+1][0])/2,
($p[$s2[0]][$s2[1]][$s2[2]][1] + $p[$s2[0]][$s2[1]+1][$s2[2]+1][1])/2, 0);
// Find midpoint between p1 and p2
$cp = Array(($p1[0] + $p2[0])/2, ($p1[1] + $p2[1])/2, 0);
// Shorten arrows towards midpoint according to config
$p1 = trans_scale($p1, $cp, $sc);
$p2 = trans_scale($p2, $cp, $sc);
if($sv){
$pv = Array(($p[$sv[0]][$sv[1]][$sv[2]][0] + $p[$sv[0]][$sv[1]+1][$sv[2]+1][0])/2,
($p[$sv[0]][$sv[1]][$sv[2]][1] + $p[$sv[0]][$sv[1]+1][$sv[2]+1][1])/2, 0);
// Project via point double dist from centre point
$pv = trans_scale($pv, $cp, $sv[3]);
}
// Calculate arrow rotation
$p_ = $sv ? $pv : $p1;
$rt = $p_[1] > $p2[1] ? 270 : 90;
if($p2[0]-$p_[0] != 0){
$rt = rad2deg(atan(($p2[1]-($p_[1]))/($p2[0]-$p_[0])));
$rt = ($p_[0] > $p2[0]) ? $rt + 180 : $rt;
}
return ' <path d="M '.$p1[0].','.$p1[1].' '.(isset($pv)?'Q '.$pv[0].','.$pv[1]:'L').' '.$p2[0].','.$p2[1].'"
style="fill:none;stroke:#'.$col.';stroke-opacity:1" />
<path transform=" translate('.$p2[0].','.$p2[1].') scale('.(0.033 / $dim).') rotate('.$rt.')"
d="M 5.77,0.0 L -2.88,5.0 L -2.88,-5.0 L 5.77,0.0 z"
style="fill:#'.$col.';stroke-width:0;stroke-linejoin:round"/>'."\n";
}
/** Converts svg into given format */
function convert($svg, $fmt, $size) {
global $CONVERT;
$opts = gen_image_opts($fmt, $size, "svg:-", "$fmt:-");
$descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"));
$convert = proc_open("$CONVERT $opts", $descriptorspec, $pipes);
fwrite($pipes[0], $svg);
fclose($pipes[0]);
$img = null;
while(!feof($pipes[1])) {
$img .= fread($pipes[1], 1024);
}
fclose($pipes[1]);
proc_close($convert);
return $img;
}
/** Alternative version using files rather than pipes,
not desired because of collision possibilities.. */
function convert_file($svg, $fmt, $size) {
global $CONVERT;
$svgfile = fopen("/tmp/visualcube.svg", 'w');
fwrite($svgfile, $svg);
fclose($svgfile);
$opts = gen_image_opts($fmt, $size, '/tmp/visualcube.svg', "/tmp/visualcube.$fmt");
$rsvg = exec("$CONVERT $opts");
$imgfile = fopen("/tmp/visualcube.$fmt", 'r');
$img = null;
while($imgfile and !feof($imgfile)) {
$img .= fread($imgfile, 1024);
}
fclose($imgfile);
return $img;
}
/** Generate ImageMagick options depending on format */
function gen_image_opts($fmt, $size, $infile, $outfile){
$inopts = ' -density 600 -resize '.$size.'x'.$size;
$outopts = ' -channel RGBA -alpha set';
// $opts .= '+label "Generated by VisualCube"';
// $opts .= ' -comment "Generated by VisualCube"';
// $opts .= ' -caption "Generated by VisualCube"';
// $opts = "-gaussian 1";
switch($fmt){
case 'png' : $inopts .= " -background none"; $outopts .= " -quality 100 -define png:format=png32";
break;
case 'gif' : $inopts .= " -background none";
break;
case 'ico' : $inopts .= " -background none";
break;
case 'jpg' : $outopts .= " -quality 90";
break;
}
return "$inopts $infile $outopts $outfile";
}
/** Sends image to browser */
function display_img($img, $fmt){
$mime = $fmt;
switch($fmt){
case 'jpe' :
case 'jpg' : $mime = 'jpeg'; break;
case 'svg' : $mime = 'svg+xml'; break;
case 'ico' : $mime = 'vnd.microsoft.icon'; break;
}
header("Content-type: image/$mime");
// header("Content-Length: " . filesize($img) ."; ");
echo $img;
}
// -----------------------------[ DB Access Functions ]--------------------------
// Return result of sql query as array
function get_arrays($mysql_con, $query){
$result = mysqli_query($mysql_con, $query);
$count = mysqli_num_rows($result);
if($count <= 0) return null;
$ary = Array($count);
$i = 0;
while($record = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$ary[$i] = $record;
$i++;
}
return $ary;
}
?>
================================================
FILE: visualcube_api.php
================================================
<?php
// Import globals
global
$VERSION,
$MAX_PZL_DIM,
$ENABLE_COOKIES,
$DEFAULTS;
// XML definition
$HTML_DEF = '<?xml version="1.0" encoding="iso-8859-1"?>'."\n".
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"'."\n".
' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'."\n";
$CUBE_CRIDER="http://cube.crider.co.uk/";
// Start page render
echo $HTML_DEF;
?>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>VisualCube (v<?php echo $VERSION; ?>)</title>
<meta name="description" content="Rubiks cube visualiser"/>
<meta name="keywords" content="visualcube, visual cube, imagecube, image cube, cube vis, viscube, visual rubiks, imgcube, cube image, cube gif, cub png, cube jpeg"/>
<meta name="resource-type" content="document"/>
<meta name="language" content="English"/>
<meta name="rating" content="general"/>
<meta name="robots" content="all"/>
<meta name="expires" content="never"/>
<meta name="revisit-after" content="14 days"/>
<meta name="distribution" content="global"/>
<meta name="author" content="Conrad Rider"/>
<meta name="copyright" content="Copyright © 2009-2010 Conrad Rider"/>
<meta http-equiv="Content-Type" content="text/html; iso-8859-1"/>
<script type="text/javascript">
//<![CDATA[
function setCookie(cname, value){
var days = 365;
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
document.cookie = cname + "=" + value + expires + "; path=/";
}
//]]>
</script>
<style media="screen" type="text/css">
@import url("screen.css");
table{
border-spacing:0px;
border-top:1px solid silver;
border-left:1px solid silver;
border-right:0;
border-bottom:1px solid silver;
background-color:#FAFAFA;
}
th{
background-color:#DDDDDD;
border-right:1px solid silver;
text-align:center;
}
h2{
margin-top:10px;
}
td{
vertical-align:top;
border-top:1px solid grey;
border-right: 1px solid silver;
padding:10px;
}
em{
font-style:normal;
font-weight:bold;
}
#examples img{
border:0;
float:none;
}
#content_v{
margin:10px 50px;
text-align:left;
}
#header_v{
margin:10px 50px;
text-align:left;
}
#header_v img{
float:right;
border:none;
}
#cookie_list{
width:250px;
}
#cookie_list li{
margin-bottom:20px;
}
#cookie_list input{
float:right;
width:60px;
}
</style>
</head>
<body>
<div id="nav_box">
cube.crider.co.uk
<ul>
<li><a href="<?php echo $CUBE_CRIDER; ?>">ZZ Tutorial</a></li>
<li><a href="<?php echo $CUBE_CRIDER; ?>beginner.php">Beginner Tutorial</a></li>
<li><a href="http://www.ctimer.co.uk">cTimer</a></li>
<li><em>VisualCube</em></li>
<li><a href="<?php echo $CUBE_CRIDER; ?>algtrans.html">Algorithm Translator</a></li>
<li><a href="<?php echo $CUBE_CRIDER; ?>coracle.html">Coracle Lookahead Drill</a></li>
<li><a href="<?php echo $CUBE_CRIDER; ?>scrambler.html">Random State Scrambler</a></li>
<li><a href="http://www.crider.co.uk">Author's Homepage</a></li>
</ul>
</div>
<div id="header_v">
<a href="http://validator.w3.org/check?uri=referer" title="Valid XHTML 1.0 Strict">
<img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Strict" width="88" height="31" style="margin-right:200px"/>
</a>
<h1>VisualCube</h1>
Generate custom Rubik's cube visualisations from your browser address bar.
<br/><br/>
</div>
<div id="content_v">
<h2>Instructions</h2>
Simply point your browser to visualcube.php to create a cube image.<br/>
A range of parameters can be set to customise the cube visualisation.<br/>
Click the link below for an example:<br/><br/>
<a href="visualcube.php?fmt=<?php echo $DEFAULTS['fmt']; ?>&size=150&pzl=2&alg=R2F2R2">cube.crider.co.uk/visualcube.php?fmt=<?php echo $DEFAULTS['fmt']; ?>&size=150&pzl=2&alg=R2F2R2</a>
<br/><br/><br/>
<h2>Examples</h2>
The following images were generated by VisualCube.
<br/><br/>
<div id="examples">
<a href="visualcube.php?fmt=<?php echo $DEFAULTS['fmt']; ?>&size=200&alg=S2M2E2">
<img src="visualcube_0.gif" alt="Example 0"/></a>
<a href="visualcube.php?fmt=<?php echo $DEFAULTS['fmt']; ?>&size=200&view=plan&case=RUR'U'R'U2RUR'UR2U2R'y2&arw=U1U5,U5U1,U3U7,U7U3">
<img src="visualcube_1.gif" alt="Example 1"/></a>
<a href="visualcube.php?fmt=<?php echo $DEFAULTS['fmt']; ?>&size=200&co=30&co=12&fo=50">
<img src="visualcube_2.gif" alt="Example 2"/></a>
<a href="visualcube.php?fmt=<?php echo $DEFAULTS['fmt']; ?>&size=200&r=y45x34&cc=n&fo=100&co=35&fd=tototototttttttttttttofotfttdtodotdtttttttttttttobotbt">
<img src="visualcube_3.gif" alt="Example3"/></a>
<a href="visualcube.php?fmt=<?php echo $DEFAULTS['fmt']; ?>&size=200&pzl=7&cc=grey&r=z-15x-105&sch=yyyyyy&fc=ynyyynynnnynnnyyyyyyyyynnnyynyynyynnnyyynnynnnnny">
<img src="visualcube_4.gif" alt="Example4"/></a>
</div>
Click each cube to see how it was generated..
<br/><br/><br/>
<h2>Features</h2>
<ul>
<li>Fully 3D cube visualisation</li>
<li>Cube dimensions from 1x1x1 to NxNxN</li>
<li>Algorithm support</li>
<li>Complete orientation control</li>
<li>Multiple image formats</li>
<li>Custom image size</li>
<li>Cube and facelet transparency</li>
<li>Custom colour schemes</li>
<li>Custom background colour</li>
<li>Image caching for speedy access</li>
<li>Cookie configurable variables</li>
</ul>
<br/>
<h2>To Do</h2>
<div>
The following features/bug fixes are planned for the future (ordered by priority).
<ul>
<li>More special views added to the 'view' variable (permutation arrows for example)</li>
<li>Visualisation of other puzzles inc square-1, megaminx and pyraminx</li>
</ul>
<br/><br/>
</div>
<h2>Source Code</h2>
<div> The source code for this script is available under the GNU Lesser General Public License at
<a href="https://github.com/Cride5/visualcube">github.com/Cride5/visualcube</a>.</div>
<br/><br/>
<h2>Parameters</h2>
<table>
<tr><th>Variable</th><th>Description</th><th>Value Range</th><th>Default</th><th>Comment</th></tr>
<tr><td><em>.</em></td><td>script extension</td><td> .png | .gif | .jpg | .svg | .tiff | .ico </td><td>.<?php echo $DEFAULTS['fmt']; ?></td>
<td>The extension used in the script url dictates the format of the image generated. For example:
visiting <a href="visualcube.jpg">/visualcube.jpg</a>
will create a jpeg image.</td></tr>
<tr><td><em>fmt</em></td><td>Image Format</td><td> png | gif | jpg | svg | tiff | ico </td><td><?php echo $DEFAULTS['fmt']; ?></td>
<td>Used as an alternative to using an image extension as above.</td></tr>
<tr><td><em>pzl</em></td><td>Puzzle Type</td><td>1 to <?php echo $MAX_PZL_DIM; ?></td><td><?php echo $DEFAULTS['pzl']; ?></td>
<td>Values from N=(1 to <?php echo $MAX_PZL_DIM; ?>) represent an NxNxN cube. Currently only regular cubes are modelled</td></tr>
<tr><td><em>size</em></td><td>Size of generated image</td><td>0 to 1024</td><td><?php echo $DEFAULTS['size']; ?></td><td>
Images produced are square, so size specifies both width and height of the final image in pixels.</td></tr>
<tr><td><em>view</em></td><td>Special View</td><td>plan|trans</td><td><?php echo $DEFAULTS['view']; ?> </td>
<td>The view parameter allows special views to facilitate interpretation of different case aspects.
<br/><em>plan</em> rotates cube to expose U face, while showing the sides of the top layer<br/>
<em>trans</em> sets the cube base colour to transparent, and hides any masked or undefined faces</td></tr>
<tr><td><em>stage</em></td><td>Stage Mask</td><td> ( fl | f2l | ll | cll | ell | oll | ocll | oell | coll | ocell | wv |
vh | els | cls | cmll | cross | f2l_3 | f2l_2 | f2l_sm | f2l_1 | f2b | line | 2x2x2 | 2x2x3 )-?[xyz2']*
</td><td><?php echo $DEFAULTS['stage']; ?> </td>
<td>Sets parts of the cube to be masked from being coloured. The stage identifier is optionally followed by a rotation algorithm. For example: <em>stage=cross-x2</em> would rotate the cross mask so that the cross appears on the U-layer rather than the D-layer</td></tr>
<tr><td><em>r</em></td><td>Rotation Sequence</td><td>([xyz]-?[0-9][0-9]?[0-9]?)+</td><td><?php echo $DEFAULTS['r']; ?></td>
<td>Each entry in the sequence is an axis (x, y or z), followed by the
number of degrees to rotate in a clockwise direction. Negative values are permitted.
Any number of rotations is possible.</td></tr>
<tr><th colspan="5">State Definitions</th></tr>
<tr><td><em>alg</em></td><td>Algorithm to apply</td><td>[UDLRFBudlrfbMESxyz'2 ]*</td><td><?php echo $DEFAULTS['alg']; ?> </td>
<td>The system applies the algorithm to the cube and displays the resulting state.<br/><br/>
<em>NOTE:</em> Currently unavailable for 4x4 cubes or above</td></tr>
<tr><td><em>case</em></td><td>Algorithm to solve case</td><td>[UDLRFBudlrfbMESxyz'2 ]*</td><td><?php echo $DEFAULTS['case']; ?> </td>
<td>The system displays the cube state which is solved by applying the algorithm
(algorithm inverse).<br/><br/>
<em>NOTE:</em> Currently unavailable for 4x4 cubes or above</td></tr>
<tr><td><em>fd</em></td><td>Facelet Definition</td><td>[udlrfbnot]*</td>
<td><?php echo $DEFAULTS['fd'] != '' ? insert_space($DEFAULTS['fd'], $DEFAULTS['pzl']) :
'uuuuuuuuu rrrrrrrrr fffffffff ddddddddd lllllllll bbbbbbbbb'; ?></td>
<td>Defines the cube state in terms of facelet positions.
u stands for a 'U' facelet (and likewise with rfdlb).
Defining a cube state using this method means the cube will be coloured
according to the scheme defined by the <em>sch</em> variable.
Three special characters are used to indicate the following:<br/>
<em>n</em>: This is a blank face (coloured grey)<br/>
<em>o</em>: This is an 'oriented' face (coloured silver)<br/>
<em>t</em>: This is a transparent face, and will not appear on the cube
</td></tr>
<tr><td><em>fc</em></td><td>Facelet Colours</td><td>[ndlswyrobgmpt]*</td>
<td><?php echo $DEFAULTS['fc'] != '' ? insert_space($DEFAULTS['fc'], $DEFAULTS['pzl']) :
'yyyyyyyyy rrrrrrrrr bbbbbbbbb wwwwwwwww ooooooooo ggggggggg'; ?></td>
<td>Defines the cube state in terms of facelet colours,
as an alternative to using fd. fc
takes precedence over fd if both are defined.<br/><br/>
See the 'sch' variable below for an explanation of the colour codes.
</td></tr>
<tr><th colspan="5">Cube Style</th></tr>
<tr><td><em>sch</em></td><td>Colour Scheme</td>
<td>[ndlswyrobgmp]*6 <br/><br/>OR<br/><br/>
Comma separated list containing 6x one of:<br/>
black | dgrey | grey | silver | white | yellow | red | orange | blue
| green | purple | pink | [0-9a-fA-F]*3 | [0-9a-fA-F]*6
</td><td><?php echo $DEFAULTS['sch']; ?></td>
<td>The order of the colours specified represent the faces in this order:<br/><br/>
U R F D L B
<br/><br/>The letters used in shorthand notation map to the generic
face colours as follows: n=black (noir), d=dark grey, l=light grey,
s=silver (lighter grey), w=white, y=yellow, r=red, o=orange, b=blue, g=green,
m=purple (magenta), p=pink, t=transparent<br/><br/>
Where longhand notation is used, 3 or 6-digit hex codes can be used to specify
the exact colour. for example C80000 would be a dark red colour.
</td></tr>
<tr><td><em>bg</em></td><td>Background Colour of image</td><td>[ndlswyrobgmpt] <br/><br/>OR<br/><br/>
black | dgrey | grey | silver | white | yellow | red | orange | blue
| green | purple | pink | [0-9a-fA-F]*3 | [0-9a-fA-F]*6
</td>
<td><?php echo $DEFAULTS['bg']; ?></td><td>The value <em>t</em> represents transparent, and is only valid for png and gif images.</td></tr>
<tr><td><em>cc</em></td><td>Cube Colour</td><td>see above</td><td><?php echo $DEFAULTS['cc']; ?></td><td>This is the cube's base colour.</td></tr>
<tr><td><em>co</em></td><td>Cube Opacity</td><td>0 to 99</td><td><?php echo $DEFAULTS['co']; ?></td>
<td>Setting this value causes the base cube to be transparent.
It means facelets at the back of the cube will also be rendered.
A value of 0 gives complete transparency.</td></tr>
<tr><td><em>fo</em></td><td>Facelet Opacity</td><td>0 to 99</td><td><?php echo $DEFAULTS['fo']; ?></td>
<td>Setting this value causes the facelets to be rendered with transparency.</td></tr>
<tr><td><em>dist</em></td><td>Projection Distance</td><td>1 to 100</td><td><?php echo $DEFAULTS['dist']; ?></td>
<td>Controls the distance of the cube from the perspective of the viewer.</td></tr>
<tr><th colspan="5">Added Features</th></tr>
<tr><td><em>arw</em></td><td>Arrow Definition</td>
<td>Comma separated list in the form:<br/><br/>
<a_from><a_to>(<a_via>)?(-i[0-9+])?(-s[0-9+])?(-<colour>)?<br/><br/>
Where <a_x> is: [URFDLB][0-9]+<br/><br/>
And: <colour> is as defined in the 'sch' variable.</td>
<td>-i10-s10</td>
<td>Defines a list of arrows to be drawn on the cube.<br/><br/>
Each arrow is defined with a minimum of two sticker identifiers to indicate
where it should be drawn from and to. The optional third sticker identifier
indicates which sticker it should pass through if a curved arrow is to be drawn.
Arrows may be scaled so that they fall short, or past the centre of each facelet
by specifying the <em>s</em> (scale) parameter after a dash.
Where curved arrows are drawn the degree to which the arrow deviates from a straight
path can be specified via the <em>i</em> (influence) parameter.
Arrows may also optionally be assigned individual colours, by using a -
followed by a colour code.
<br/><br/>Example: arw=U0U2,U2U8,U8U0,R6R2R0-s8-i5-yellow
<br/><br/>
The above example draws 4 arrows. The first three use default colour and scale
and point to stickers on the U-face. The fourth arrow
points from sticker #6 to sticker #2 on the R-face, and is curved
so that it passes through sticker #0. The arrow is slightly shortened to 8/10
of its full length, and the influence of the pass through sticker in generating
the curve is set to 5/10.
</td></tr>
<tr><td><em>ac</em></td><td>Default Arrow Colour</td><td>[ndlswyrobgmp] <br/><br/>OR<br/><br/>
black | dgrey | grey | silver | white | yellow | red | orange | blue
| green | purple | pink | [0-9a-fA-F]*3 | [0-9a-fA-F]*6
</td>
<td>grey</td><td>Arrows will be this colour by default, unless overridden by a
colour specified for each arrow in the arw variable.</td></tr>
</table>
<br/><br/><?php if($ENABLE_COOKIES){ ?>
<h2>Cookie Configuration</h2>
The desired values for cookie configurable variables can be set below. <br/>
Refer to the table above for acceptable values.
<ul id="cookie_list">
<li><input type="text" value="<?php if(array_key_exists('vc_r', $_COOKIE)) echo $_COOKIE['vc_r']?>"
onkeyup="setCookie('vc_r', this.value)"/>Rotation Sequence (r):</li>
<li><input type="text" value="<?php if(array_key_exists('vc_sch', $_COOKIE)) echo $_COOKIE['vc_sch']?>"
onkeyup="setCookie('vc_sch', this.value)"/>Colour Scheme (sch):</li>
<li><input type="text" value="<?php if(array_key_exists('vc_bg', $_COOKIE)) echo $_COOKIE['vc_bg']?>"
onkeyup="setCookie('vc_bg', this.value)"/>Background Colour (bg):</li>
<li><input type="text" value="<?php if(array_key_exists('vc_cc', $_COOKIE)) echo $_COOKIE['vc_cc']?>"
onkeyup="setCookie('vc_cc', this.value)"/>Cube Colour (cc):</li>
<li><input type="text" value="<?php if(array_key_exists('vc_co', $_COOKIE)) echo $_COOKIE['vc_co']?>"
onkeyup="setCookie('vc_co', this.value)"/>Cube Opacity (co):</li>
<li><input type="text" value="<?php if(array_key_exists('vc_fo', $_COOKIE)) echo $_COOKIE['vc_fo']?>"
onkeyup="setCookie('vc_fo', this.value)"/>Facelet Opacity (fo):</li>
<li><input type="text" value="<?php if(array_key_exists('vc_dist', $_COOKIE)) echo $_COOKIE['vc_dist']?>"
onkeyup="setCookie('vc_dist', this.value)"/>Projection Distance (dist):</li>
</ul><?php } ?>
</div>
<div id="footer">
Copyright © 2010 <a href="http://www.crider.co.uk">Conrad Rider</a>.
<br/>Cube images generated by VisualCube are free to copy and distribute
</div>
</body>
</html>
================================================
FILE: visualcube_config.php
================================================
<?php
// Maximum cube dimension to render (pzl)
$MAX_PZL_DIM = 10;
// Whether to allow cookie config of style variables (r, sch, bg, cc, co, fo, dist)
$ENABLE_COOKIES = true;
// Default rendering values
$DEFAULTS = Array(
'fmt' => 'svg',
'pzl' => '3',
'size' => '128',
'view' => '',
'stage' => '',
'r' => 'y45x-34',
'alg' => '',
'case' => '',
'fd' => '',
'fc' => '',
'sch' => 'yrbwog',
'bg' => 'white',
'cc' => 'black',
'co' => '100',
'fo' => '100',
'dist' => '5',
);
// Location of ImageMagick's 'convert' binary.
// NOTE: if the $PATH variable is set up correctly using just 'convert' is sufficient
$CONVERT="convert";
// -------------[ Cache related configuration ]---------------
// Whether image caching is enabled. NOTE: if enabled a cron
// job will need to be set up to prune the database
$ENABLE_CACHE = false;
// Database Configuration (for image caching)
$DB_HOST="localhost";
$DB_NAME="DATABASE_NAME";
$DB_USERNAME="DATABASE_USERNAME";
$DB_PASSWORD="DATABASE_PASSWORD";
// Maximum size of image to be cached
$CACHE_IMG_SIZE_LIMIT = 10000; // 10Kb
================================================
FILE: visualcube_dbprune.sh
================================================
#!/bin/sh
# Script to prune virtualcube image cache, to be run weekly
# Prune database by removing all entries which have been accessed less than 1 times
mysql -u DB_USER --safe-updates=0 --password="DB_PASS" DB_NAME -e "DELETE FROM vcache WHERE rcount < 1"
# Reset all existing entrys to 0
mysql -u DB_USER --safe-updates=0 --password="DB_PASS" DB_NAME -e "UPDATE vcache SET rcount=0"
# Query to display db contents
#mysql -u DB_USER --password="DB_PASS" DB_NAME -e "SELECT hash, fmt, req, rfr, rcount, OCTET_LENGTH(img) FROM vcache"
# This crontab line will run it at 4 am every Monday
#00 4 * * Mon /path/to/visualcube_dbprune.sh "Prune visualcube image cache"
# To install crontab on multi-user system place the line in a file and then run:
# crontab <filename>
gitextract_hbkv5873/ ├── .gitignore ├── COPYING ├── COPYING.LESSER ├── Dockerfile ├── README.md ├── cube_lib.php ├── db_schema.sql ├── screen.css ├── visualcube.php ├── visualcube_api.php ├── visualcube_config.php └── visualcube_dbprune.sh
SYMBOL INDEX (58 symbols across 3 files)
FILE: cube_lib.php
function gen_state (line 267) | function gen_state($moves, $puzzle, $group_id, $is_ll){
function orient_alg (line 321) | function orient_alg($alg, $ref, $puzzle, $group_id){
function els_FR (line 437) | function els_FR($cube){
function is_member (line 447) | function is_member($cube, $group_id){
function is_member_auf (line 467) | function is_member_auf($cube, $group_id){
function is_member_strict (line 482) | function is_member_strict($cube, $group_id){
function cube_state (line 509) | function cube_state($cube, $group_id){
function case_cube (line 562) | function case_cube($alg){
function case_cubes (line 571) | function case_cubes($alg, $prerot){
function case_cubes2 (line 582) | function case_cubes2($alg, $postrot){
function upright (line 592) | function upright($cube){
function face_cube (line 614) | function face_cube($cube, $dim){
function facelet_cube (line 627) | function facelet_cube($cube, $d, $fi){
function letter_cube (line 722) | function letter_cube($cube, $dim){
function col_cube (line 732) | function col_cube($cube, $dim){
function printcube (line 750) | function printcube($cube, $dim){
function apply_alg (line 756) | function apply_alg($alg, $cube){
function format_alg (line 773) | function format_alg($moves){
function trim_rotations (line 795) | function trim_rotations($alg, $is_ll){
function remove_auf (line 808) | function remove_auf($alg){
function expand_alg (line 825) | function expand_alg($alg){
function compress_alg (line 838) | function compress_alg($alg){
function invert_alg (line 878) | function invert_alg($alg){
function alg_stats (line 908) | function alg_stats($alg){
function encode_o (line 940) | function encode_o($data, $mod){
function encode_p (line 949) | function encode_p($data){
function cube_match (line 964) | function cube_match($cube1, $cube2){
function prod (line 979) | function prod($cube1, $cube2, $n){
function move_pow (line 1007) | function move_pow($char){
function move_id (line 1017) | function move_id($move){
function fcs_doperm (line 1046) | function fcs_doperm($fcs, $alg, $dim){
function fcs_pos (line 1151) | function fcs_pos($r, $c, $o, $d){
function fcs_union (line 1165) | function fcs_union(&$t1, &$t2, $offset){
function fcs_permute (line 1171) | function fcs_permute(&$in, &$out, $perm){
function fcs_parse_alg (line 1179) | function fcs_parse_alg($alg, $dim){
function fcs_move_id (line 1211) | function fcs_move_id($move){
function fcs_format_alg (line 1235) | function fcs_format_alg($alg){
function array_copy (line 1259) | function array_copy($ary){
FILE: db_schema.sql
type vcache (line 5) | CREATE TABLE vcache(
FILE: visualcube.php
function parse_col (line 646) | function parse_col($col){
function parse_arrow (line 665) | function parse_arrow($str, $dim){
function insert_space (line 702) | function insert_space($in, $dim){
function translate (line 715) | function translate($p, $t){
function scale (line 722) | function scale($p, $f){
function trans_scale (line 730) | function trans_scale($p, $v, $f){
function rotate (line 736) | function rotate($p, $ax, $an){
function project (line 756) | function project($p, $d){
function face_visible (line 765) | function face_visible($face, $rv){
function outline_svg (line 775) | function outline_svg($fc){
function facelet_svg (line 785) | function facelet_svg($fc){
function oll_svg (line 806) | function oll_svg($fc){
function gen_facelet (line 830) | function gen_facelet($p1, $p2, $p3, $p4, $seq){
function gen_arrow (line 844) | function gen_arrow($id, $s1, $s2, $sv, $sc, $col){
function convert (line 878) | function convert($svg, $fmt, $size) {
function convert_file (line 896) | function convert_file($svg, $fmt, $size) {
function gen_image_opts (line 913) | function gen_image_opts($fmt, $size, $infile, $outfile){
function display_img (line 935) | function display_img($img, $fmt){
function get_arrays (line 955) | function get_arrays($mysql_con, $query){
Condensed preview — 12 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (156K chars).
[
{
"path": ".gitignore",
"chars": 29,
"preview": "*~\n.dropbox\nnbproject\nlocal\n\n"
},
{
"path": "COPYING",
"chars": 35147,
"preview": " GNU GENERAL PUBLIC LICENSE\n Version 3, 29 June 2007\n\n Copyright (C) 2007 Free "
},
{
"path": "COPYING.LESSER",
"chars": 7637,
"preview": "\t\t GNU LESSER GENERAL PUBLIC LICENSE\n Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software"
},
{
"path": "Dockerfile",
"chars": 93,
"preview": "from php:7.4-apache\n\nRUN apt update\nRUN apt install --yes imagemagick\n\nCOPY . /var/www/html/\n"
},
{
"path": "README.md",
"chars": 1766,
"preview": "# VisualCube\nGenerate custom Rubik's cube visualisations from your browser address bar. \n\n### Installation Instructions\n"
},
{
"path": "cube_lib.php",
"chars": 45246,
"preview": "<?php\n/*\n\tFile: cube_lib.php\n\tDate: 02 Apr 2010\n\tAuthor(s): Conrad Rider (www.crider.co.uk)\n\tDescription: Php library fo"
},
{
"path": "db_schema.sql",
"chars": 449,
"preview": "/** Caches generated visual cubes.\nStores the parameters used to generate the image,\nthe latest referrer to request the "
},
{
"path": "screen.css",
"chars": 2432,
"preview": "body{\n\tmargin:0;\n\ttext-align:center;\n\tfont-size:10pt;\n\tfont-family:Verdana, Geneva, Arial, Helvetica, sans-serif;\n}\n\nh1{"
},
{
"path": "visualcube.php",
"chars": 31781,
"preview": "<?php\n/*\n\tFile: visualcube.php\n\tDate: 02 Apr 2010\n\tAuthor(s): Conrad Rider (www.crider.co.uk)\n\tContributors: Shotaro Mak"
},
{
"path": "visualcube_api.php",
"chars": 17047,
"preview": "<?php\n\n\t// Import globals\n\tglobal\n\t\t$VERSION,\n\t\t$MAX_PZL_DIM,\n\t\t$ENABLE_COOKIES,\n\t\t$DEFAULTS;\n\n\t// XML definition\n\t$HTML"
},
{
"path": "visualcube_config.php",
"chars": 1156,
"preview": "<?php\n\n\n\t// Maximum cube dimension to render (pzl)\n\t$MAX_PZL_DIM = 10;\n\n\t// Whether to allow cookie config of style vari"
},
{
"path": "visualcube_dbprune.sh",
"chars": 773,
"preview": "#!/bin/sh\n\n# Script to prune virtualcube image cache, to be run weekly\n\n# Prune database by removing all entries which h"
}
]
About this extraction
This page contains the full source code of the Cride5/visualcube GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 12 files (140.2 KB), approximately 48.4k tokens, and a symbol index with 58 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.