WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Diffusion-Limited Aggregation visualization
Categories : PHP, Graphics, Algorithms, Math. Click here to Update Your Picture
Chao Xu
Date : May 15th 2007
Grade : 5 of 5 (graded 1 times)
Viewed : 3498
File : No file for this code example.
Images : Image 1
Search : More code by Chao Xu
Action : Grade This Code Example
Tools : My Examples List

 
Like this code?
Show the author your appreciation.
Submit your own code examples 
 

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);
?>



Reverse a given number
Categories : PHP, Beginner Guides, Algorithms, 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
How to judge if an integer is odd or is even in Php3?
Categories : Math., PHP, Algorithms
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
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.
Prime number finder (Sieve of Erastothenes)
Categories : PHP, Algorithms, Math.
Latitude-Longitude to Miles
Categories : PHP, Utilities, Math.
Create Thumbnails - resize an image - jpeg, jpg, gif, png to the specifed width and height in proportion without loosing out on pixcel quality.
Categories : PHP, GD image library, Graphics
Math operations on big numbers
Categories : PHP, Math.
Simple way of scaling any image to fit either given width or height.
Categories : PHP, Graphics, Arrays
The Porter Word Stemming Algorithm in PHP Reduces words to their base stem for search engines and indexing
Categories : Algorithms, PHP, Strings
Mail-lib provides a simple interface to the sendmail program. Note: you must actually have sendmail on your machine (sorry windows NT users).
Categories : Algorithms, Email, PHP
A recursive function to traverse a multi-dimensional array where the dimensions are not known
Categories : Arrays, PHP, Algorithms
Kasskooye($path) tell you the complete size of a folder
Categories : PHP, Algorithms, Utilities, Filesystem
 Alix Axel wrote :1795
This is a nice function indeed the only drawback is the speed.