750) $size=750; if($size<10) $size=10; if(!$n) $n=3; if($n>25) $n=25; if($n<1) $n=1; if(!$scale) $scale=3; if($scale>4) $scale=4; if($scale<1) $scale=1; if(!$thickness) $thickness=1; if($thickness>3) $thickness=3; if($thickness<1) $thickness=1; if(!$stickers){ for($i = 1; $i<=$n*$n;$i++){ $stickers .= "y"; } for($i = 1; $i<=$n*$n;$i++){ $stickers .= "r"; } for($i = 1; $i<=$n*$n;$i++){ $stickers .= "g"; } } $scalepx=$size*$scale/220; $im = imagecreate($size*$scale,$size*$scale); imageantialias ($im,true); imagesetthickness($im,$thickness); // Define coordinates of the 6 'key'-points that define the cube shape cube: //Default orientation of the cube, based on ImageRevenge: if(!$orient){ $x1=89; $y1=18; $x2=200; $y2=31; $x3=14; $y3=59; $x4=138; $y4=77; $x5=29; $y5=185; $x6=147; $y6=211; $x7=206; $y7=151; } //Alternative orientation of the cube, based on ImageCube: if($orient=="1"){ $x1=78; $y1=16; $x2=183; $y2=28; $x3=15; $y3=62; $x4=134; $y4=78; $x5=31; $y5=168; $x6=141; $y6=194; $x7=185; $y7=133; } // Allocate colors: $back = imagecolorallocate($im, 255, 255, 255); $col_poly = imagecolorallocate($im, 0, 0, 0); $red = imagecolorallocate($im, 200, 0, 0); $orange = imagecolorallocate($im, 255, 161, 0); $blue = imagecolorallocate($im, 0, 0, 182); $green = imagecolorallocate($im, 0, 182, 72); $white = imagecolorallocate($im,247,247,247); $yellow = imagecolorallocate($im, 239, 239, 0); $grey = imagecolorallocate($im, 200, 200, 200); $colors=array("r"=>$red, "o"=>$orange, "b"=>$blue, "g"=>$green, "w"=>$white, "y"=>$yellow, "x"=>$grey); // Draw cube silhouette: imagepolygon($im, array ( $x2*$scalepx, $y2*$scalepx, $x1*$scalepx, $y1*$scalepx, $x3*$scalepx, $y3*$scalepx, $x5*$scalepx, $y5*$scalepx, $x6*$scalepx, $y6*$scalepx, $x7*$scalepx, $y7*$scalepx ), 6, $col_poly); //finishing the basic 1x1 cube shape, by drawing 3 more lines... imageline($im,$x4*$scalepx,$y4*$scalepx,$x3*$scalepx,$y3*$scalepx,$col_poly); imageline($im,$x4*$scalepx,$y4*$scalepx,$x2*$scalepx,$y2*$scalepx,$col_poly); imageline($im,$x4*$scalepx,$y4*$scalepx,$x6*$scalepx,$y6*$scalepx,$col_poly); //Making the grid on all 3 faces. For one grid, the makelines function is used 2 times, as //that function draws lines in only 1 direction: makelines($im, $n, $col_poly, $scalepx, $x1, $y1, $x2, $y2, $x3,$y3, $x4, $y4); makelines($im, $n, $col_poly, $scalepx, $x1, $y1, $x3, $y3, $x2,$y2, $x4, $y4); makelines($im, $n, $col_poly, $scalepx, $x3, $y3, $x4, $y4, $x5,$y5, $x6, $y6); makelines($im, $n, $col_poly, $scalepx, $x3, $y3, $x5, $y5, $x4,$y4, $x6, $y6); makelines($im, $n, $col_poly, $scalepx, $x4, $y4, $x2, $y2, $x6,$y6, $x7, $y7); makelines($im, $n, $col_poly, $scalepx, $x4, $y4, $x6, $y6, $x2,$y2, $x7, $y7); //Extracting the stickers of U, F and R faces: $stickers_U=substr($stickers,0,($n)*($n)); $stickers_F=substr($stickers,$n*$n,($n)*($n)); $stickers_R=substr($stickers,$n*$n*2,($n)*($n)); //Calculate coordinates and fill up the U, F and R faces respectively: calculate_coordinates($datax,$datay,$n, $x1,$y1,$x2,$y2,$x3,$y3,$x4,$y4); fill_up($im, $n, $scalepx, $datax, $datay, $colors, $stickers_U); calculate_coordinates($datax,$datay,$n, $x3,$y3,$x4,$y4,$x5,$y5,$x6,$y6); fill_up($im, $n, $scalepx, $datax, $datay, $colors, $stickers_F); calculate_coordinates($datax,$datay,$n, $x4,$y4,$x2,$y2,$x6,$y6,$x7,$y7); fill_up($im, $n, $scalepx, $datax, $datay, $colors, $stickers_R); // Resample image and make background transparent: $interm=ImageCreateTrueColor($size,$size); imagecopyresampled($interm,$im,0,0,0,0,$size,$size,$size*$scale,$size*$scale); $output=ImageCreate($size,$size); imagecopyresized($output,$interm,0,0,0,0,$size,$size,$size,$size); $back = imagecolorallocate($output,221,221,221); imagecolortransparent($output,$back); imagefill($output,0,0,$back); // Send image to client: header("Content-type: image/png"); imagepng($output); imagedestroy($im); imagedestroy($output); ?>