Quick Search for:  in language:    
code,produces,does,place,four,pixels,evenly,d
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
PHP Stats

 Code: 113,010. lines
 Jobs: 41. postings

 How to support the site

 
Sponsored by:

 
You are in:
 
Login





Latest Code Ticker for PHP.
Simplest Web-Counter
By Kamran Riaz on 1/18


Easy Webcomic System
By Kyle Temkin on 1/17


Click here to see a screenshot of this code!AutoIndex PHP Script (Directory Indexer)
By J J H on 1/17

(Screen Shot)

DB Selector
By Martyn Merrett on 1/17


MapQuest Link Generator
By Steve Schoenfeld on 1/15


Click here to see a screenshot of this code!A Simple FTP Solution
By Marcelo Valle Franco on 1/15

(Screen Shot)

Web Blog / Content Updater
By Matthew Sparrow on 1/14


Current Users Online v1
By Robert Peterson on 1/13


Click here to see a screenshot of this code!Blobsy : MSN Messenger Bot
By JawishHameed on 1/12

(Screen Shot)

Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!

Affiliate Sites



 
 
   

Squiggles

Print
Email
 
VB icon
Submitted on: 6/20/2002 10:31:28 AM
By: Chas Pardee 
Level: Beginner
User Rating: By 1 Users
Compatibility:PHP 4.0

Users have accessed this code 957 times.
 
(About the author)
 
     This code produces a png. What it does is place four pixels evenly dispersed acorss the picture and they then move in a random direction. No color can go on top of any other color but can back track on top of themselves.

 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!

    //**************************************
    //     
    // for :Squiggles
    //**************************************
    //     
    If you use my code I ask that you leave the section crediting it to me in. Otherwise you may use it whereever you please, as long as it is not being redistributed.
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

    //**************************************
    //     
    // Name: Squiggles
    // Description:This code produces a png.
    //     What it does is place four pixels evenly
    //     dispersed acorss the picture and they th
    //     en move in a random direction. No color 
    //     can go on top of any other color but can
    //     back track on top of themselves.
    // By: Chas Pardee
    //
    // Inputs:The first two lines of code ca
    //     n be edited so that the code is ran more
    //     or less times and so that the size of th
    //     e picture varies. You'll find out soon t
    //     hough that it is easy for the script to 
    //     time out.
    //
    // Returns:A file called pic.png is crea
    //     ted in the same folder as the page is sa
    //     ved. Because the image wraps around it i
    //     s also tilable and could be used as a ba
    //     ckground image. With a little modificati
    //     on of the colors a very nice background 
    //     that is different every time the pages i
    //     s loaded could be produced.
    //
    // Assumes:I nterestingly enough I had t
    //     o make a can to microtime() because rand
    //     just wasn't random. Try playing with it.
    //     If you just use rand(1,4) to generate th
    //     e random numbers and if the screen is bi
    //     g enough that the different colors won't
    //     hit each other, the same shapes are prod
    //     uced every time, and they're symmetrical
    //     . Now first I tried using rand(1,5) and 
    //     just running until it produced a number 
    //     other than 5. This results in four ident
    //     ical nonsymmetrical shapes. It really ma
    //     kes you realize that they are pseudorand
    //     om numbers. Anyways, it's a fun script t
    //     o play around with. I hope you enjoy it.
    //     
    //
    // Side Effects:Creates pic.png
    //
    //This code is copyrighted and has    // limited warranties.Please see http://
    //     www.Planet-Source-Code.com/vb/scripts/Sh
    //     owCode.asp?txtCodeId=662&lngWId;=8    //for details.    //**************************************
    //     
    
    <html>
    <head>
    <title></title>
    <?php
    /*squiggle picture producing section*/
    /* Code by Chas */
    /* http://userpages.wittenberg.edu/s04.cpardee */
    // max size of the picture
    $max = 300;
    // number of times to itirate
    // or the number of times the pixel move
    //     s
    $times = 30000;
    // function made to check if a pixel can
    //     
    // move to a given spot 
    function testfor($pic, $xstart, $ystart, $col1, $col2)
    {
    return(imagecolorat($pic, $xstart, $ystart) == $col1 ||imagecolorat($pic, $xstart, $ystart) == $col2);
    }
    // creates the image
    $pic=imagecreate($max,$max);
    // allocates the colors used
    // $col1 is the background
    $col1=imagecolorallocate($pic,0,0,0);
    $col2=imagecolorallocate($pic,0,255,0);
    $col3=imagecolorallocate($pic,0,0,255);
    $col4=imagecolorallocate($pic,255,255,255);
    $col5=imagecolorallocate($pic,255,0,0);
    // put colors and starting cooridnates i
    //     n arrays
    $col = Array($col2, $col3, $col4, $col5);
    $x = Array($max/3, 2*$max/3, $max/3, 2*$max/3);
    $y = Array($max/3, 2*$max/3, 2*$max/3, $max/3);
    // for loop simply loops through the
    // code the correct number of times
    for($i = 0; $i < $times; $i++)
    foreach($col as $key=>$value)
    {
    // chooses a random value between 1 and 
    //     4
    // I was a little paranoid here because
    // for a while I was getting symmetrical
    //     images
    // and at other tiems all 4 colors were 
    //     follow
    // the same pathes with idfferent starti
    //     ng positions 
    $a = (rand()*microtime())%5+1;
    while($a ==5)
    $a = (rand()*microtime())%5+1;
    // switch statement chooses the coorespo
    //     nding direction
    switch($a)
    {
    case 1:
    	 	// test to make sure the pixel is not already
    		// colored with another color
    if(testfor($pic, $x[$key]+1, $y[$key], $col1, $value))
    // move
    			 $x[$key]++;
    break;
    case 2:
    // test to make sure the pixel is not al
    //     ready
    		// colored with another color
    if(testfor($pic, $x[$key]-1, $y[$key], $col1, $value))
    //move
    			 $x[$key]--;
    break;
    case 3:
    // test to make sure the pixel is not al
    //     ready
    		// colored with another color
    if(testfor($pic, $x[$key], $y[$key]+1, $col1, $value))
    // move
    			 $y[$key]++;
    break;
    case 4:
    // test to make sure the pixel is not al
    //     ready
    		// colored with another color
    if(testfor($pic, $x[$key], $y[$key]-1, $col1, $value))
    // move
    			 $y[$key]--;
    break;
    		}
    		// if the pixel moves off of one side this
    		// section makes it wrap around
    		if($x[$key] > $max)
    		$x[$key] = 0;
    		if($y[$key] > $max)
    		$y[$key] = 0;
    		if($x[$key] < 0)
    		$x[$key] = $max;
    		if($y[$key] < 0)
    		$y[$key] = $max;
    // color the appropriate pixel
    imagesetpixel($pic, $x[$key], $y[$key], $value);
    }
    // creates the picture
    imagepng($pic,"pic.png");
    // free the memory storing the pic
    imagedestroy($pic);
    /*end squiggle picture section*/
    ?>
    </head>
    <body>
    <img src="pic.png" border=0>
    </body>
    </html>


Other 2 submission(s) by this author

 

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
8/16/2002 8:16:02 AM:Grant Cummings
I'm only getting parallel horizontal 
lines?!?!  the top one goes red - green 
- red while the bottom one goes 
blue-white-blue
Hmmmmmmmmmmmmmmmm
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
12/9/2002 12:14:59 PM:Chas Pardee
Sorry I didn't respond for so long. I 
reran the code just to double check it 
and it's still wokring fine for me. The 
only tihng I can think to tell you is 
maybe to try and change the way it 
selects the direction to move. I was 
using rand() and microtime(), but you 
can use any given random number 
generator in that spot.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | PHP Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.