@ 2024-05-11T06:17:11Z <?php
$spriteSpan=24;
$tileSpan=8;
$sheetSpan=64;
include_once($_SERVER["DOCUMENT_ROOT"]."/Classes/prettyClass.php");
$pretty = new prettyClass();
// Instantiate the mirrorsClass object
$zeroSpan=0;
$tileSpan=8;
$doubleSpan=16;
$spriteSpan=24;
$sheetSpan=64;
$blankpixel="0000007f";
$mirrors = new mirrorsClass();
$mirrors->initiate();
class mirrorsClass
{
public function __construct()
{
global $zeroSpan, $tileSpan, $doubleSpan, $spriteSpan, $sheetSpan, $blankpixel;
$zeroSpan=0;
$tileSpan=8;
$doubleSpan=16;
$spriteSpan=24;
$sheetSpan=64;
$blankpixel="0000007f";
}
public function initiate()
{
global $zeroSpan, $tileSpan, $doubleSpan, $spriteSpan, $sheetSpan, $blankpixel;
$Combo=[];
// Load the sprite sheet from a contiguous PNG file
$sheet = imagecreatefrompng ($_SERVER["DOCUMENT_ROOT"]."/Sprites/roe5/sheets/roe5-sheet.png");
// Load the sprite sheet metadata from a JSON file
$sheetjson = json_decode(file_get_contents($_SERVER["DOCUMENT_ROOT"]."/Sprites/roe5/sheets/roe5-sheet.json"),true, 512, JSON_THROW_ON_ERROR);
$p = array_keys($sheetjson["pre_"]);
$s = array_keys($sheetjson["suf_"]);
$parts = []; // Initialize $parts as an empty array
$seq2=[];
// $D="";
for($pindex = $zeroSpan; $pindex < count( $p ); $pindex++)
{
for($sindex = $zeroSpan; $sindex < count( $s ); $sindex++)
{
// echo $p[$pindex].",".$s[$sindex]."<br>\r\n";
$pre = $p[$pindex];
$suf = $s[$sindex];
for($celly=$zeroSpan;$celly<$spriteSpan;$celly+=$tileSpan)
{
for($cellx=$zeroSpan;$cellx<$spriteSpan;$cellx+=$tileSpan)
{
$seq["$cellx,$celly"]="";
for($py=$zeroSpan;$py<$tileSpan;$py++)
{
for($px=$zeroSpan;$px<$tileSpan;$px++)
{
$colorIndex = imagecolorat($sheet, $pindex*$spriteSpan+$cellx+$px, $sindex*$spriteSpan+$celly+$py);
// Get the RGBA values of the color
$rgba = imagecolorsforindex($sheet, $colorIndex);
$h = ""
.str_pad(dechex($rgba['red']), 2, '0', STR_PAD_LEFT)
.str_pad(dechex($rgba['green']), 2, '0', STR_PAD_LEFT)
.str_pad(dechex($rgba['blue']), 2, '0', STR_PAD_LEFT)
.str_pad(dechex($rgba['alpha']), 2, '0', STR_PAD_LEFT);
$seq["$cellx,$celly"].=$h;
}
}
}
}
$seq2["$pre$suf"]=$seq;
}
}
// Free up memory
imagedestroy($sheet);
unset($sheetjson);
foreach($seq2 as $k1 => $seqA)
{
if($seqA==
array(
"$zeroSpan,$zeroSpan"=>str_repeat("$blankpixel",$tileSpan),
"$tileSpan,$zeroSpan"=>str_repeat("$blankpixel",$tileSpan),
"$doubleSpan,$zeroSpan"=>str_repeat("$blankpixel",$tileSpan),
"$zeroSpan,$tileSpan"=>str_repeat("$blankpixel",$tileSpan),
"$tileSpan,$tileSpan"=>str_repeat("$blankpixel",$tileSpan),
"$doubleSpan,$tileSpan"=>str_repeat("$blankpixel",$tileSpan),
"$zeroSpan,$doubleSpan"=>str_repeat("$blankpixel",$tileSpan),
"$tileSpan,$doubleSpan"=>str_repeat("$blankpixel",$tileSpan),
"$doubleSpan,$doubleSpan"=>str_repeat("$blankpixel",$tileSpan)
))
{continue 1;}
foreach($seqA as $A => $partA)
{
if($partA == str_repeat("$blankpixel",$tileSpan))
{continue 1;}
$this->manip(array("exact"),$partA,$Combo);
}
$Combo = array_unique($Combo);
$Combo = array_values($Combo);
foreach($seqA as $A => $partA)
{
if($partA == str_repeat("$blankpixel",$tileSpan))
{continue 1;}
$this->prune(array("flip_x","flip_y","flip_xy"),$partA,$Combo);
}
}
$this->sheetRender($Combo);
// Free memory
imagedestroy($sheet);
unset($sheetjson);
}
// Exact carbon copy
public function exact($A, &$Combo)
{
global $zeroSpan, $tileSpan, $doubleSpan, $spriteSpan, $sheetSpan, $blankpixel;
$Combo[] = $A;
}
// Horizontal flip
public function flip_x($A, &$Combo)
{
global $zeroSpan, $tileSpan, $doubleSpan, $spriteSpan, $sheetSpan, $blankpixel;
$Combo[] = implode("", array_reverse(array_map(fn ($file) => $file, str_split($A, $tileSpan))));
}
// Vertical flip
public function flip_y($A, &$Combo)
{
global $zeroSpan, $tileSpan, $doubleSpan, $spriteSpan, $sheetSpan, $blankpixel;
$Combo[] = implode("", array_reverse(str_split($A, $tileSpan * $tileSpan)));
}
// Diagonal flip
public function flip_xy($A, &$Combo)
{
global $zeroSpan, $tileSpan, $doubleSpan, $spriteSpan, $sheetSpan, $blankpixel;
$Combo[] = implode("", array_reverse(str_split($A, $tileSpan)));
}
// 90 degrees counter-clockwise rotation
public function rotate_90_counter_clockwise($A, &$Combo)
{
global $zeroSpan, $tileSpan, $doubleSpan, $spriteSpan, $sheetSpan, $blankpixel;
// Split the input string into rows and convert each row to an array of characters
$rows = array_map('str_split', str_split($A, $tileSpan*$tileSpan));
// Transpose the matrix
$transposed = array_map(null, ...$rows);
// Reverse the rows to get the counter-clockwise rotation
$rotated = array_map('array_reverse', $transposed);
// Combine the rows back into a single string
$result = implode('', array_map('implode', $rotated));
// Add the rotated result to the Combo array
$Combo[] = $result;
}
// 90 degrees clockwise rotation
public function rotate_90_clockwise($A, &$Combo)
{
global $zeroSpan, $tileSpan, $doubleSpan, $spriteSpan, $sheetSpan, $blankpixel;
// Split the input string into rows and convert each row to an array of characters
$rows = array_map('str_split', str_split($A, $tileSpan*$tileSpan));
// Transpose the matrix
$transposed = array_map(null, ...array_reverse($rows));
// Combine the rows back into a single string
$result = implode('', array_map('implode', $transposed));
// Add the rotated result to the Combo array
$Combo[] = $result;
}
// 270 degrees clockwise rotation
public function rotate_270_clockwise($A, &$Combo)
{
global $zeroSpan, $tileSpan, $doubleSpan, $spriteSpan, $sheetSpan, $blankpixel;
$this->rotate_90_counter_clockwise($A, $Combo);
}
// 270 degrees counter-clockwise rotation
public function rotate_270_counter_clockwise($A, &$Combo)
{
global $zeroSpan, $tileSpan, $doubleSpan, $spriteSpan, $sheetSpan, $blankpixel;
$this->rotate_90_clockwise($A, $Combo);
}
// 180 degrees rotation
public function rotate_180($A, &$Combo)
{
global $zeroSpan, $tileSpan, $doubleSpan, $spriteSpan, $sheetSpan, $blankpixel;
$this->flip_xy($A, $Combo);
}
// Render completed sprite sheet to PNG output
public function sheetRender($Combo)
{
global $zeroSpan, $tileSpan, $doubleSpan, $spriteSpan, $sheetSpan, $blankpixel;
$xcount=$sheetSpan;
$ycount=ceil(count($Combo)/$xcount);
$w=$xcount*$tileSpan;
$h=$ycount*$tileSpan;
// Load the sprite sheet from a contiguous PNG file
$partsSheet = imagecreatetruecolor ($w,$h);
// Allocate a color with alpha transparency
$transparent_color = imagecolorallocatealpha($partsSheet, 0, 0, 0, 127);
// Set background color to transparent
imagefill($partsSheet, $zeroSpan, $zeroSpan, $transparent_color);
// Enable alpha blending for the image
imagealphablending($partsSheet, true);
// Preserve transparency
imagesavealpha($partsSheet, true);
for($index=$zeroSpan;$index<count($Combo);$index++)
{
$x = floor($index % $sheetSpan)*$tileSpan;
$y = floor($index / $sheetSpan)*$tileSpan;
for($py=$zeroSpan;$py<$tileSpan;$py++)
{
for($px=$zeroSpan;$px<$tileSpan;$px++)
{
$row = str_split($Combo[$index], $tileSpan*$tileSpan)[$py];
$column = str_split($row, $tileSpan)[$px];
$colors = str_split($column, 2);
$color["alpha"]=hexdec($colors[3]);
$color["alpha"]=127*$color["alpha"]/255;
if($color["alpha"]==0)
{
$color["red"]=hexdec($colors[0]);
$color["green"]=hexdec($colors[1]);
$color["blue"]=hexdec($colors[2]);
// Allocate some color
$pixelColor = imagecolorallocatealpha($partsSheet, $color["red"],$color["green"],$color["blue"],$color["alpha"]);
// Draw pixels at specific coordinates
imagesetpixel($partsSheet, $x+$px, $y+$py, $pixelColor);
}
}
}
}
// Output the image
header('Content-type: image/png');
imagepng($partsSheet);
// Free up memory
imagedestroy($partsSheet);
}
// Manipulate tiles using inline translations
public function manip($functions,$partA,&$Combo)
{
foreach($functions as $function)
{call_user_func_array(array($this, $function),array($partA,&$Combo));}
$Combo=array_unique($Combo);
$Combo=array_values($Combo);
}
// Prune tiles of which share geometric/planar redundancy
public function prune($functions,$partA,&$Combo)
{
$counts=array_count_values($Combo);
foreach($functions as $function)
{
$Combo_2=[];
call_user_func_array(array($this, $function),array($partA,&$Combo_2));
foreach ($Combo_2 as $combo){
if(array_search($combo, $Combo)!==false && isset($counts[$combo]))
{unset($Combo[array_search($combo, $Combo)]);}
}$Combo = array_values($Combo);
}
}
/* Submitted by Rockwood 2024 05/10 23:14
// Prune tiles that exhibit geometric redundancy without consideration for number balance
function prune($functions, $partA, &$Combo)
{
// Count occurrences of each tile
$counts = array_count_values($Combo);
// Iterate through each pruning function
foreach ($functions as $function) {
$prunedTiles = [];
// Apply the pruning function to the current tile
call_user_func_array(array($this, $function), array($partA, &$prunedTiles));
// Iterate through the pruned tiles
foreach ($prunedTiles as $tile) {
// Check if the tile exists in the Combo and if its count is greater than 1
if (array_search($tile, $Combo) !== false && $counts[$tile] > 1) {
// Remove the tile from the Combo
unset($Combo[array_search($tile, $Combo)]);
}
}
// Re-index the Combo array
$Combo = array_values($Combo);
}
}
*/
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.1.0 - 8.1.28 , 8.2.0 - 8.2.19 , 8.3.0 - 8.3.7 Warning: include_once(): open_basedir restriction in effect. File(/Classes/prettyClass.php) is not within the allowed path(s): (/tmp:/in:/etc) in /in/D7nMh on line 7
Warning: include_once(/Classes/prettyClass.php): Failed to open stream: Operation not permitted in /in/D7nMh on line 7
Warning: include_once(): Failed opening '/Classes/prettyClass.php' for inclusion (include_path='.:') in /in/D7nMh on line 7
Fatal error: Uncaught Error: Class "prettyClass" not found in /in/D7nMh:8
Stack trace:
#0 {main}
thrown in /in/D7nMh on line 8
Process exited with code 255 . preferences:dark mode live preview
53.22 ms | 402 KiB | 62 Q