Go to Post "The compressor is half the temperature of a toasted Subway sandwich." - Ashley Hartley [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 24-01-2004, 18:38
echos's Avatar
echos echos is offline
Jack of all trades
#1125
Team Role: Programmer
 
Join Date: Dec 2003
Location: San Diego, CA
Posts: 61
echos will become famous soon enough
Send a message via ICQ to echos Send a message via AIM to echos Send a message via MSN to echos Send a message via Yahoo to echos
Random code snipets

I've been working on some perty usless code that are more for fun than anything else, but oh well.

Feel free to post some of your own.

Here they are...

Find Pi
Code:
 unsigned double float pi;
  
 void main(void)
 	{
 	pi = 1;
 
 	for(count = 0, top = 2, bottem = 1; count < 10000; count++)
 		{
 		pi *= top/bottem;
 		bottem += 2;
 
 		pi *= top/bottem;
 		top += 2;
 		}
  
 	printf ("pi = %f", pi*2);
 	}
Random Signature
PHP Code:
<?php 
 
 header
("Content-type: image/png");
 
 
//read folder
 
$folder opendir(".");
 
 while (
$file readdir($folder))
 
 
$names[count($names)] = $file;
 
 
closedir($folder);
 
 
//sort file names in array
 
sort($names);
 
 
//remove any non-images from array
 
$tempvar 0;
 
 for (
$i 0$names[$i]; $i++)
     {
     
$ext=strtolower(substr($names[$i],-4));
 
 if (
$ext == ".png")
     {
     
$names1[$tempvar] = $names[$i]; $tempvar++;}
     }
 
 
//random
 
srand ((double) microtime() * 10000000);
 
$rand_keys array_rand ($names12);
 
 
//random image from array
 
$im imagecreatefrompng($names1[$rand_keys[0]]);
 
 
imagepng($im);
 
?>
Create a directory on your server and put this script there along with any png images. It will select one randomly and then output it to display image. This the exact code that I use for mine. (hit F5 a couple of times to watch it change)
__________________

Entity Hosting Staff
http://www.entityhosting.com/
  #2   Spotlight this post!  
Unread 25-01-2004, 18:25
Guest
 
Posts: n/a
Re: Random code snipets

Could you add these to the repository?

http://nrg.chaosnet.org/repository - You'll need to register
  #3   Spotlight this post!  
Unread 25-01-2004, 21:06
mtrawls's Avatar
mtrawls mtrawls is offline
I am JVN! (John von Neumann)
#0122 (NASA Knights)
Team Role: Programmer
 
Join Date: Mar 2003
Location: Hampton, VA
Posts: 295
mtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to behold
Send a message via AIM to mtrawls
Re: Random code snipets

Quote:
Originally Posted by SilverStar
Could you add these to the repository?

http://nrg.chaosnet.org/repository - You'll need to register

Err ... Could you not add these to the repository? Maybe I got the wrong idea, but I thought the repository was supposed to be a place to find *useful* and *robot-related* code (ideally to spark either inspiration or recognition ). These snippets are useless to any team looking for some code for their robot, and hence would only clutter up the repository -- thereby making it a less useful place, as it would be harder to find what you're looking for.

I mean, really, the poster did say:
Quote:
I've been working on some perty usless code that are more for fun than anything else, but oh well.
Also, I saw in another post that you asked for the beacon/tracker code to be uploaded to the repository. I believe that this would be a mistake, too. This code can be got in other places (it is on the FIRST website, afterall). Anyone going to the repository should already have access to that code, and hence, again, the unnecessary posting of it would only add clutter, and make the repository less useful.

I realize you are excited about getting a lot of useful code uploaded to the repository ... but more is not necessarily better. Especially if it is more uneccesary or useless code! Remember: quality, not quantity, is what counts ... especially when programming. Perhaps I mistook the purpose of the repository ... but it doesn't seem to me like there is a need for a repository of random, un-related and un-useful pieces of code.
  #4   Spotlight this post!  
Unread 26-01-2004, 01:42
Grommit Grommit is offline
Registered User
#0115 (Monta Vista Robotics)
 
Join Date: Oct 2002
Location: Cupertino
Posts: 47
Grommit will become famous soon enoughGrommit will become famous soon enough
Send a message via AIM to Grommit
Re: Random code snipets

That's a very poor formula for pi. It converges very, very, very slowly.

Try some of these links for some better formulas:
http://www.geocities.com/SiliconValley/Bay/9187/pi.htm
http://elephant.linux.net.cn/articles/pi.php?lang=en

Chudnovsky's algorithm would be a fine choice. You get 14 digits every iteration of the algorithm.
  #5   Spotlight this post!  
Unread 26-01-2004, 14:46
echos's Avatar
echos echos is offline
Jack of all trades
#1125
Team Role: Programmer
 
Join Date: Dec 2003
Location: San Diego, CA
Posts: 61
echos will become famous soon enough
Send a message via ICQ to echos Send a message via AIM to echos Send a message via MSN to echos Send a message via Yahoo to echos
Re: Random code snipets

New version of random image
PHP Code:
<?php
// Last Updated: Sunday, January 26, 2004 at 11:43:45 AM

// *****IPORTANT*****
// GIF support has been disabled due to complications
// of another nature.

/**************************************************/
/* Supported image types                          */
/**************************************************/
/* Input:                                         */
/* PNG                                            */
/* JPEG                                           */
/* WBMP                                           */
/* XBM                                            */
/* XPM                                            */
/*                                                */
/* Output:                                        */
/* PNG                                            */
/* JPEG                                           */
/* GIF (if supported, else defualts to PNG)       */
/**************************************************/

/**************************************************/
/* -Options                                       */
/**************************************************/
/* Image Output type                              */
/*                                                */
/* Desription:                                    */
/* Allows the ability to overide the type of      */
/* image output by the program.                   */
/*                                                */
/* Settings:                                      */
/* auto, png, jpeg, and gif (if supported)        */
/**************************************************/

$imageoutputtype "auto";

/**************************************************/
/* JPEG Quality                                   */
/*                                                */
/* Description:                                   */
/* Allows you to set the compression level of     */
/* JPEGs generated by the program.                */
/*                                                */
/* Settings:                                      */
/* defualt, [0-100] (0 worst and 100 best)        */
/**************************************************/

$jpegquality "defualt";

/**************************************************/
/* NO NEED TO CHANGE ANYTHING BELOW               */
/**************************************************/

//does a check to see if GD is installed and running
/*
if (!isset(imagetypes()))
    {
    die("This server does not have image support.");
    }
*/

if(!isset($imageoutputtype))
    {
    
$imageoutputtype "auto";
    }

if(!
$jpegquality >= && !$jpegquality <= 100)
    {
    
$jpegquality 100;
    }

//read folder
$folder opendir(".");

while (
$file readdir($folder))

$names[count($names)] = $file;

closedir($folder);

//sort file names in array
sort($names);

//remove any non-images from array
$tempvar 0;

for (
$i 0$names[$i]; $i++)
    {
    
$ext=strtolower(substr($names[$i],-4));

    if (
$ext == ".png" || $ext == ".jpg" || $ext == "jpeg" || $ext == "wbmp" || $ext == ".xbm" || $ext == ".xpm")
        {
        
$names1[$tempvar] = $names[$i];
        
$tempvar++;
        }
    }

//random
srand ((double) microtime() * 10000000);
$rand_keys array_rand ($names12);


//random image from array
$rimage $names1[$rand_keys[0]];


//image identification
$imagetype strtolower(substr($rimage,-4));


//image import
if($imagetype == ".png")
    {
    
$image imagecreatefrompng($rimage);

    if(
$imageoutputtype == "auto")
        {
        
$imageoutputtype "png";
        }
    }

  elseif(
$imagetype == ".jpg" || $imagetype == "jpeg")
    {
    
$image imagecreatefromjpeg($rimage);

    if(
$imageoutputtype == "auto")
        {
        
$imageoutputtype "jpeg";
        }
    }

  elseif(
$imagetype == ".gif")
    {
    
$image imagecreatefromgif($rimage);

    if(
$imageoutputtype == "auto")
        {
        
$imageoutputtype "gif";
        }
    }

  elseif(
$imagetype == "wbmp")
    {
    
$image imagecreatefromwbmp($rimage);

    if(
$imageoutputtype == "auto")
        {
        
$imageoutputtype "png";
        }
    }

  elseif(
$imagetpye == ".xbm")
    {
    
$image imagecreatefromxbm($rimage);

    if(
$imageoutputtype == "auto")
        {
        
$imageoutputtype "png";
        }
    }

  elseif(
$imagetype == ".xpm")
    {
    
$image imagecreatefromxpm($rimage);

    if(
$imageoutputtype == "auto")
        {
        
$imageoutputtype "png";
        }
    }


//image output
if($imageoutputtype == "gif")
    {
    if(
imagetypes() & IMG_GIF)
        {
        
header("Content-type: image/gif");
        
imagegif($image);
        }
      else
        {
        
header("Content-type: image/png");
        
imagepng($image);
        }
    }

  elseif(
$imageoutputtype == "jpeg" || $imageoutputtype == "jpg")
    {
    if(
imagetypes() & IMG_JPG)
        {
        
header("Content-type: image/jpeg");
        
imagejpeg($image''$jpegquality);
        }
      else
        {
        
header("Content-type: image/png");
        
imagepng($image);
        }
    }

  elseif(
$imageoutputtype == "png")
    {
    
header("Content-type: image/png");
    
imagepng($image);
    }

  else
    {
    
header("Content-type: image/png");
    
imagepng($image);
    }
?>
__________________

Entity Hosting Staff
http://www.entityhosting.com/
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
What is your most prefered programming language? Hailfire Programming 156 19-01-2005 21:42
InfraRed autonomous code ... mtrawls Programming 1 11-01-2004 00:25
Does your team use the Default code. Jeff McCune General Forum 2 09-01-2003 14:46
How random is random???? archiver 1999 0 23-06-2002 21:59
Patent source code? Kyle Fenton Chit-Chat 3 20-10-2001 17:53


All times are GMT -5. The time now is 09:35.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi