Functions
WebDev/*nix assorted functions & hacks
Search
find all
Array
-
Bash
-
Classes
-
Config
-
DateTime
-
Debug
-
dotjs
-
File
-
foooo
-
Git
-
HTML
-
Images
-
Javascript
-
Linux
-
Math
-
Misc
-
MySQL
-
OS X
-
Reading
-
Redis
-
Shell scripts
-
snippets
-
SQL
-
Strings
-
TextMate
-
Web
-
\(^o^)/ Fun!
-
_Misc hacks
-
_Pages
\(^o^)/ Fun!
* Readme
Alphanumeric images to ascii
Conway's Game of Life as TextMate command
Langton's Ant
Quine
Sierpiński Carpet
Sierpiński Triangle
Towers of Hanoi
8
found
auth
Name:
Category: \(^o^)/ Fun!
Body:
/* Sierpiński Carpet. The fun thing of a lot of fractals: - you can generate them by repeating a small number of steps X times, to quote Wikipedia: "The construction of the Sierpiński carpet begins with a square. The square is cut into 9 congruent subsquares in a 3-by-3 grid, and the central subsquare is removed. The same procedure is then applied recursively to the remaining 8 subsquares, ad infinitum". - you can ALSO generate them by plotting points seemingly random, like in the code below: [1] put a point anywhere within the square. [2] Choose 1 of 8 points on the sides at random, draw a (invisible) line to it from your current point, and plot the next point at two-thirds of that line. [3] Repeat step 2. - finally, you can probably also create them by running an iterative function on each point of the grid, this is how the Mandelbrot images are made. */ header("Content-type: image/png"); $w = 500; $h = 500; $im = imagecreatetruecolor($w, $h); $white = imagecolorallocate($im, 250, 250, 250); $black = imagecolorallocate($im, 0, 0, 0); imagefill($im, 1, 1, $white); $x = $y = round($w/2); $crs = array(1=>array(0,0), 2=>array(round($w/2),0), 3=>array($w,0), 4=>array(0,round($h/2)), 5=>array($w,round($h/2)), 6=>array(0,$h), 7=>array(round($w/2),$h), 8=>array($w,$h)); for($i=0;$i < 240000;$i++) { $c = rand(1, 8); $x = round(((2*$crs[$c][0])+$x)/3); $y = round(((2*$crs[$c][1])+$y)/3); imagesetpixel($im, $x, $y, $black); } imagepng($im); imagedestroy($im);
Footer