From 7eec7c46cd0273e72d834c15ac1cb81ae8aefc1c Mon Sep 17 00:00:00 2001 From: Conrad Rider Date: Sun, 12 Apr 2015 20:49:39 +0700 Subject: [PATCH] Seperated configuration and API page from main php script. --- visualcube.php | 474 +++++++----------------------------------- visualcube_api.php | 322 ++++++++++++++++++++++++++++ visualcube_config.php | 46 ++++ visualcube_dbprune.sh | 0 4 files changed, 438 insertions(+), 404 deletions(-) create mode 100644 visualcube_api.php create mode 100644 visualcube_config.php mode change 100644 => 100755 visualcube_dbprune.sh diff --git a/visualcube.php b/visualcube.php index c9a5e17..33f7150 100644 --- a/visualcube.php +++ b/visualcube.php @@ -27,376 +27,42 @@ * Automatic Permutation Arrows * Other puzzles - CHANGES: (Version 0.3.0 to 0.4.0) + CHANGES: + (Version 0.5.1 to 0.5.2) + * Seperate configuration file + * Seperate 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 + + */ - // -----------------[ Script Configuration ]----------------- + // Import configuration values + require 'visualcube_config.php'; - // Database Configuration (for image caching) - $DB_NAME="DATABASE_NAME"; - $DB_USERNAME="DATABASE_USERNAME"; - $DB_PASSWORD="DATABASE_PASSWORD"; - - // 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; + global + $DB_NAME, + $DB_USERNAME, + $DB_PASSWORD, + $MAX_PZL_DIM, + $ENABLE_COOKIES, + $ENABLE_CACHE, + $CACHE_IMG_SIZE_LIMIT, + $DEBUG, + $DEFAULTS; - // Whether image caching is enabled. NOTE: if enabled a cron - // job will need to be set up to prune the database - $ENABLE_CACHE = true; - - // Maximum size of image to be cached - $CACHE_IMG_SIZE_LIMIT = 10000; // 10Kb - - // Causes cube svg to be outputted as XML for inspection - $DEBUG = false; - // Do not display errors -// if (!$DEBUG) error_reporting(0); - // Default rendering values - $DEFAULTS = Array( - 'fmt' => 'gif', - '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', - ); - + // VisualCube version + $VERSION = "0.5.2"; // ----------------------[ API Page ]----------------------- // If no format specified, display API page if(!array_key_exists('fmt', $_REQUEST)){ - - // XML definition - $HTML_DEF = ''."\n". - ''."\n"; - - // Start page render - echo $HTML_DEF; -?> - - - VisualCube (v0.5.1) - - - - - - - - - - - - - - - - - -
- - Valid XHTML 1.0 Strict - -

VisualCube

- Generate custom Rubik's cube visualisations from your browser address bar. -

-
-
-

Instructions

- Simply point your browser to visualcube.png to create a cube image.
- A range of parameters can be set to customise the cube visualisation.
- Click the link below for an example:

-           - cube.crider.co.uk/visualcube.png?size=150&pzl=2&alg=R2F2R2 -


-

Examples

- The following images were generated by VisualCube. -

- - Click each cube to see how it was generated.. -


-

Features

- -
-

To Do

-
- The following features/bug fixes are planned for the future (ordered by priority). -
    -
  • More special views added to the 'view' variable (permutation arrows for example)
  • -
  • Visualisation of other puzzles inc square-1, megaminx and pyraminx
  • -
-

-
-

Source Code

-
The source code for this script is available under the GNU Lesser General Public License at - sourceforge.net/projects/vcube.
-

-

Parameters

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
VariableDescriptionValue RangeDefaultComment
.script extension .png | .gif | .jpg | .svg | .tiff | .ico .The extension used in the script url dictates the format of the image generated. For example: - visiting /visualcube.jpg - will create a jpeg image.
fmtImage Format png | gif | jpg | svg | tiff | ico Used as an alternative to using an image extension as above.
pzlPuzzle Type1 to Values from N=(1 to ) represent an NxNxN cube. Currently only regular cubes are modelled
sizeSize of generated image0 to 1024 - Images produced are square, so size specifies both width and height of the final image in pixels.
viewSpecial Viewplan|trans The view parameter allows special views to facilitate interpretation of different case aspects. -
plan rotates cube to expose U face, while showing the sides of the top layer
- trans sets the cube base colour to transparent, and hides any masked or undefined faces
stageStage Mask ( 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']* -  Sets parts of the cube to be masked from being coloured. The stage identifier is optionally followed by a rotation algorithm. For example: stage=cross-x2 would rotate the cross mask so that the cross appears on the U-layer rather than the D-layer
rRotation Sequence([xyz]-?[0-9][0-9]?[0-9]?)+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.
State Definitions
algAlgorithm to apply[UDLRFBudlrfbMESxyz'2 ]* The system applies the algorithm to the cube and displays the resulting state.

- NOTE: Currently unavailable for 4x4 cubes or above
caseAlgorithm to solve case[UDLRFBudlrfbMESxyz'2 ]* The system displays the cube state which is solved by applying the algorithm - (algorithm inverse).

- NOTE: Currently unavailable for 4x4 cubes or above
fdFacelet Definition[udlrfbnot]*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 sch variable. - Three special characters are used to indicate the following:
- n: This is a blank face (coloured grey)
- o: This is an 'oriented' face (coloured silver)
- t: This is a transparent face, and will not appear on the cube -
fcFacelet Colours[ndlswyrobgmpt]*Defines the cube state in terms of facelet colours, - as an alternative to using fd. fc - takes precedence over fd if both are defined.

- See the 'sch' variable below for an explanation of the colour codes. -
Cube Style
schColour Scheme[ndlswyrobgmp]*6

OR

- Comma separated list containing 6x one of:
- black | dgrey | grey | silver | white | yellow | red | orange | blue - | green | purple | pink | [0-9a-fA-F]*3 | [0-9a-fA-F]*6 -
The order of the colours specified represent the faces in this order:

- U R F D L B -

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

- 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. -
bgBackground Colour of image[ndlswyrobgmpt]

OR

- black | dgrey | grey | silver | white | yellow | red | orange | blue - | green | purple | pink | [0-9a-fA-F]*3 | [0-9a-fA-F]*6 -
The value t represents transparent, and is only valid for png and gif images.
ccCube Coloursee aboveThis is the cube's base colour.
coCube Opacity0 to 99Setting 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.
foFacelet Opacity0 to 99Setting this value causes the facelets to be rendered with transparency.
distProjection Distance1 to 100Controls the distance of the cube from the perspective of the viewer.
Added Features
arwArrow DefinitionComma separated list in the form:

- <a_from><a_to>(<a_via>)?(-i[0-9+])?(-s[0-9+])?(-<colour>)?

- Where <a_x> is: [URFDLB][0-9]+

- And: <colour> is as defined in the 'sch' variable.
-i10-s10Defines a list of arrows to be drawn on the cube.

- 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 s (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 i (influence) parameter. - Arrows may also optionally be assigned individual colours, by using a - - followed by a colour code. -

Example:   arw=U0U2,U2U8,U8U0,R6R2R0-s8-i5-yellow -

- 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. -
acDefault Arrow Colour[ndlswyrobgmp]

OR

- black | dgrey | grey | silver | white | yellow | red | orange | blue - | green | purple | pink | [0-9a-fA-F]*3 | [0-9a-fA-F]*6 -
greyArrows will be this colour by default, unless overridden by a - colour specified for each arrow in the arw variable.
-

-

Cookie Configuration

- The desired values for cookie configurable variables can be set below.
- Refer to the table above for acceptable values. - -
- - - - $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',); + // 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 @@ -697,48 +363,48 @@ function setCookie(cname, value){ 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"; + 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; - 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){ @@ -780,7 +446,7 @@ function setCookie(cname, value){ $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 + $facelets = fcs_doperm($facelets, $case . ' ' . $alg, $dim); // new NxN facelet permute } // Retrive arrow defn's diff --git a/visualcube_api.php b/visualcube_api.php new file mode 100644 index 0000000..a0de036 --- /dev/null +++ b/visualcube_api.php @@ -0,0 +1,322 @@ +'."\n". + ''."\n"; + + $CUBE_CRIDER="http://cube.crider.co.uk/"; + + // Start page render + echo $HTML_DEF; +?> + + + VisualCube (v<?php echo $VERSION; ?>) + + + + + + + + + + + + + + + + + +
+ + Valid XHTML 1.0 Strict + +

VisualCube

+ Generate custom Rubik's cube visualisations from your browser address bar. +

+
+
+

Instructions

+ Simply point your browser to visualcube.png to create a cube image.
+ A range of parameters can be set to customise the cube visualisation.
+ Click the link below for an example:

+           + cube.crider.co.uk/visualcube.png?size=150&pzl=2&alg=R2F2R2 +


+

Examples

+ The following images were generated by VisualCube. +

+ + Click each cube to see how it was generated.. +


+

Features

+ +
+

To Do

+
+ The following features/bug fixes are planned for the future (ordered by priority). +
    +
  • More special views added to the 'view' variable (permutation arrows for example)
  • +
  • Visualisation of other puzzles inc square-1, megaminx and pyraminx
  • +
+

+
+

Source Code

+
The source code for this script is available under the GNU Lesser General Public License at + github.com/Cride5/visualcube.
+

+

Parameters

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
VariableDescriptionValue RangeDefaultComment
.script extension .png | .gif | .jpg | .svg | .tiff | .ico .The extension used in the script url dictates the format of the image generated. For example: + visiting /visualcube.jpg + will create a jpeg image.
fmtImage Format png | gif | jpg | svg | tiff | ico Used as an alternative to using an image extension as above.
pzlPuzzle Type1 to Values from N=(1 to ) represent an NxNxN cube. Currently only regular cubes are modelled
sizeSize of generated image0 to 1024 + Images produced are square, so size specifies both width and height of the final image in pixels.
viewSpecial Viewplan|trans The view parameter allows special views to facilitate interpretation of different case aspects. +
plan rotates cube to expose U face, while showing the sides of the top layer
+ trans sets the cube base colour to transparent, and hides any masked or undefined faces
stageStage Mask ( 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']* +  Sets parts of the cube to be masked from being coloured. The stage identifier is optionally followed by a rotation algorithm. For example: stage=cross-x2 would rotate the cross mask so that the cross appears on the U-layer rather than the D-layer
rRotation Sequence([xyz]-?[0-9][0-9]?[0-9]?)+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.
State Definitions
algAlgorithm to apply[UDLRFBudlrfbMESxyz'2 ]* The system applies the algorithm to the cube and displays the resulting state.

+ NOTE: Currently unavailable for 4x4 cubes or above
caseAlgorithm to solve case[UDLRFBudlrfbMESxyz'2 ]* The system displays the cube state which is solved by applying the algorithm + (algorithm inverse).

+ NOTE: Currently unavailable for 4x4 cubes or above
fdFacelet Definition[udlrfbnot]*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 sch variable. + Three special characters are used to indicate the following:
+ n: This is a blank face (coloured grey)
+ o: This is an 'oriented' face (coloured silver)
+ t: This is a transparent face, and will not appear on the cube +
fcFacelet Colours[ndlswyrobgmpt]*Defines the cube state in terms of facelet colours, + as an alternative to using fd. fc + takes precedence over fd if both are defined.

+ See the 'sch' variable below for an explanation of the colour codes. +
Cube Style
schColour Scheme[ndlswyrobgmp]*6

OR

+ Comma separated list containing 6x one of:
+ black | dgrey | grey | silver | white | yellow | red | orange | blue + | green | purple | pink | [0-9a-fA-F]*3 | [0-9a-fA-F]*6 +
The order of the colours specified represent the faces in this order:

+ U R F D L B +

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

+ 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. +
bgBackground Colour of image[ndlswyrobgmpt]

OR

+ black | dgrey | grey | silver | white | yellow | red | orange | blue + | green | purple | pink | [0-9a-fA-F]*3 | [0-9a-fA-F]*6 +
The value t represents transparent, and is only valid for png and gif images.
ccCube Coloursee aboveThis is the cube's base colour.
coCube Opacity0 to 99Setting 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.
foFacelet Opacity0 to 99Setting this value causes the facelets to be rendered with transparency.
distProjection Distance1 to 100Controls the distance of the cube from the perspective of the viewer.
Added Features
arwArrow DefinitionComma separated list in the form:

+ <a_from><a_to>(<a_via>)?(-i[0-9+])?(-s[0-9+])?(-<colour>)?

+ Where <a_x> is: [URFDLB][0-9]+

+ And: <colour> is as defined in the 'sch' variable.
-i10-s10Defines a list of arrows to be drawn on the cube.

+ 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 s (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 i (influence) parameter. + Arrows may also optionally be assigned individual colours, by using a - + followed by a colour code. +

Example:   arw=U0U2,U2U8,U8U0,R6R2R0-s8-i5-yellow +

+ 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. +
acDefault Arrow Colour[ndlswyrobgmp]

OR

+ black | dgrey | grey | silver | white | yellow | red | orange | blue + | green | purple | pink | [0-9a-fA-F]*3 | [0-9a-fA-F]*6 +
greyArrows will be this colour by default, unless overridden by a + colour specified for each arrow in the arw variable.
+

+

Cookie Configuration

+ The desired values for cookie configurable variables can be set below.
+ Refer to the table above for acceptable values. + +
+ + + diff --git a/visualcube_config.php b/visualcube_config.php new file mode 100644 index 0000000..4de44a9 --- /dev/null +++ b/visualcube_config.php @@ -0,0 +1,46 @@ + 'gif', + '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', + ); + diff --git a/visualcube_dbprune.sh b/visualcube_dbprune.sh old mode 100644 new mode 100755