|
|
|
|
Like this code?
Show the author your appreciation.
|
|
| |
Diffusion-Limited Aggregation creates great looking fractals, I made a fast(but not the fastest) Diffusion-Limited Aggregation simulator. You define how many molecules will be released and the size of the board. A more accurate Brownian motion system will make the image look better, but it is going to be a lot slower.
Made by Chao Xu
http://webDevLogs.com
| <?php
<?php
set_time_limit(0);
//This line was added to avoide the huge amount of notices this script creates
error_reporting(E_ALL ^ E_NOTICE );
//Very fast Diffusion-Limited Aggregation
$s = 100;
$step = 700;
$area = 2;//smaller = faster, larger = more accurate(random)
$image = imagecreate($s,$s);
imagecolorallocate($image,255,255,255);
$color = imagecolorallocate($image,0,0,0);
$s2 = $s/2;
$grid[$s2][$s2] = 1;
imagesetpixel($image,$s2,$s2,$color);
while($i<$step){
//calculate releasing area
$n = max($max_x - $min_x, $max_y - $min_y) + $area;
$s2mn = $s2-$n;
$s2an = $s2+$n;
//release a molecule
do{
$x = rand($s2mn,$s2an);
$y = rand($s2mn,$s2an);
}while($grid[$x][$y]);
//move the molecule randomly
while(!($grid[$x-1][$y-1]+$grid[$x-1][$y]+$grid[$x-1][$y+1]+
$grid[$x][$y-1]+$grid[$x][$y+1]+$grid[$x+1][$y-1]+
$grid[$x+1][$y]+$grid[$x+1][$y+1])){
$x += rand(-1,1);
$y += rand(-1,1);
if($x<$s2mn||$x>$s2an||$y<$s2mn||$y>$s2an){
continue 2;
}
}
$grid[$x][$y] = 1;
if($max_x<$x){
$max_x = $x;
}elseif($min_x>$x){
$min_x = $x;
}
if($max_y<$y){
$max_y = $y;
}elseif($min_y>$y){
$min_y = $y;
}
imagesetpixel($image,$x,$y,$color);
++$i;
}
header("Content-type: image/png");
imagepng($image);
?> | | |
|
| Library of math functions to expand the functionality of PHP3. Version 1.2.1 fixes a major problem with the gcd function.
Categories : Algorithms, PHP, Math. | | | Prime Spiral is a image plotted with all the primes in a number spiral.
Categories : Algorithms, Graphics, GD image library, Math. | | | Show the steps for converting a number from a given base to base 10. Shows the steps involved in converting a number from a given base to base 10. Categories : PHP, Math., Algorithms | | | Prime number finder (Sieve of Erastothenes) Categories : PHP, Algorithms, Math. | | | 3dLib - a class for drawing in 3D space. Supported functions: Line, SetPixel, Polygon, FilledPolygon, etc. 3dChart() function has been added for one-call drawing of 3d charts. Support of mostly used 3d-transformations. Categories : Graphics, Math., PHP Classes, PHP, Charts and Graphs | | | How to judge if an integer is odd or is even in Php3? Categories : Math., PHP, Algorithms | | | Simple class that uses GD to draw pie charts. After the class definition there's some sample code to demonstrate how you use the class.
Categories : Graphics, PHP, PHP Classes, GD image library, Charts and Graphs | | | abs -- Absolute value Categories : PHP, PHP Functions, Math. | | | Find the day of the week for any given year/month/day. Categories : PHP, Date Time, Data Validation, Algorithms, Beginner Guides | | | Shows the current time as a PNG-image. This script does not use the GD
library. You can use it as a benchmark (because it's slow), or as a quick
reference for implementing a simple PNG-file generator. Categories : Graphics, Zlib, Calendar, PHP, Date Time | | | Dollar Serial Number Validator Categories : PHP, Security, Algorithms | | | Calculate Body Mass Index Categories : PHP, Algorithms, Regexps | | | A very simple and efficient split bar the B-Z bar , for mysql and php ...
Tired of obfuscated code try this one ...
Categories : PHP, Databases, MySQL, Algorithms | | | Paginating the mySQL data Categories : PHP, Algorithms, Databases, MySQL, HTML and PHP | | | A couple of functions that convert an IP address into its color code and not-color-code. Useful when viewing an apache log with a mysql result grouped by IP Categories : PHP, Graphics, Databases | |
|
|
|