Lost Password?


  #1 (permalink)  
Old 12-02-2006, 07:17 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,433
Last Blog:
Google Web Toolkit
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default Code:PHP Random Functions

As I mentioned in another post, im working on a little something as an alternative to the generic captcha which looks something like this

PHP Code:
<?php
function RandomStringGenerator($length){
global 
$string;
    
$pattern "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
if(empty(
$length)){
    
$length "10";
    }
for(
$i=0$i<$length$i++){
    
$string .= $pattern{rand(0,61)};
    }

return 
$string;
}

function 
CaptchaGenerator(){
global 
$string;
RandomStringGenerator();
header("Content-type: image/png");
$im = @imagecreate(10050)
   or die(
"Cannot Initialize new GD image stream");
$background_color imagecolorallocate($im255255255);
$text_color imagecolorallocate($im000);
imagestring($im1055,  $string$text_color);
imagepng($im);
imagedestroy($im);
}

CaptchaGenerator();
?>

an alternative might be like what color is this shape? or how many sides does this shape have? So I created another random function that creates a random shape a random color at a random size

PHP Code:
<?php

function RandomColorGenerator(){
global 
$red$green$blue$color;
    
$color = array(rand(50,255), rand(50,255), rand(50,255)); //generates random RGB color;
    
$red $color[1]; //red value;
    
$green $color[2]; //green value;
    
$blue $color[3]; //blue value;
}

function 
ShapeGenerator($vertices$radius) {
global 
$points;
$points = array();
$degrees 360/$vertices//calculates the degrees per angle;


for ($i=0$i<$vertices$i++) {
    
$cos cos(deg2rad($degrees*$i)); //generates x points;
    
$sin sin(deg2rad($degrees*$i)); //generates y points;
    
$cosTranslated round($cos*$radius)+$radius//translates x points;
    
$sinTranslated round($sin*$radius)+$radius//transpates y points;
    
$points[] = $cosTranslated//Adds the x and y values to the array;
    
$points[] .= $sinTranslated//Adds the x and y values to the array;
    
}
}
   
function 
RandomShape($sides,$radius) {
global 
$points$red$green$blue;
RandomColorGenerator();
ShapeGenerator($sides$radius);
    
$vertices count($points)/2;
    
$image imagecreatetruecolor(400400); //creates drawing canvass
    
$bg imagecolorallocate($image000); //sets the background color
    
$color imagecolorallocate($image$red$green$blue); //sets the polygon color
    
imagefilledpolygon($image$points$vertices$color); //draws the polygon
    
header("Content-type: image/png");
    
imagepng($image);
}

RandomShape(rand(3,10), rand(25,200)); //DO IT!!!!!
//@credits: onion2k - ShapeGenerator
?>
Im actually pretty satisfied how this came out, concidering its one of the few scripts I've made using polymorphic functions.

Last edited by John; 08-22-2007 at 06:50 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 12-03-2006, 10:50 AM
Jordan's Avatar   
Jordan Jordan is offline
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Posts: 9,203
Last Blog:
Ext JS or Ext GWT
Rep Power: 20
Jordan is just really niceJordan is just really niceJordan is just really niceJordan is just really nice
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan
Default

Thank you, very nice code!
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog
The CodeCall Wiki is now fully integrated with vBulletin users! Check it out and add some new pages!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 12-03-2006, 11:04 AM
TcM's Avatar   
TcM TcM is offline
Code Warrior
 
Join Date: Aug 2006
Location: In a technologic world :p
Posts: 8,332
Rep Power: 68
TcM is a glorious beacon of lightTcM is a glorious beacon of lightTcM is a glorious beacon of lightTcM is a glorious beacon of lightTcM is a glorious beacon of light
Default

Nice Tutorial ;0 good code
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Generating Random Numbers with PHP Paradine PHP Tutorials 4 08-27-2007 08:09 PM
Return random numbers without duplicates Paradine PHP Tutorials 0 08-26-2007 03:07 PM
How do I program a random generator? eddiewillers General Programming 4 07-24-2007 03:26 PM
Get and Set Functions Chan C# Programming 3 08-25-2006 12:44 PM
I need to generate a random number in PHP dirkfirst PHP Forum 7 07-05-2006 10:58 PM


All times are GMT -5. The time now is 07:16 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 97%

Ads