DHTML
  Home arrow DHTML arrow Page 3 - An Object-Based Approach to Building Noisy...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DHTML

An Object-Based Approach to Building Noisy Images
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2007-05-15

    Table of Contents:
  • An Object-Based Approach to Building Noisy Images
  • Creating noisy images with a procedural approach
  • Building a noisy image with an object-based approach
  • Listing the complete source code of the noisy image script

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    An Object-Based Approach to Building Noisy Images - Building a noisy image with an object-based approach


    (Page 3 of 4 )

    In consonance with the concepts that I deployed in the previous section, my purpose here is to demonstrate how a simple noisy image can be created by using a PHP class instead of using a procedural function. Therefore, below I included the definition of a brand new PHP class, called "RandomGenerator." As its name implies, it is tasked with generating the four-digit random values contained within the corresponding noisy image.

    Please take some time to examine this class, shown below: 

    class RandomGenerator{
       var $length;
       var $chars="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
       function RandomGenerator($length=4){
         if(!is_int($length)||$length<1||$length>strlen($this-
    >chars)){
           trigger_error('Invalid length for random
    string',E_USER_ERROR);
         }
         $this->length=$length;
       }
       function getRandomValue(){
         $rndstr='';$maxvalue=strlen($this->chars)-1;
         for($i=0;$i<$this->length;$i++){
           $rndstr.=substr($this->chars,rand(0,$maxvalue),1);
         }
         return $rndstr;
       }
    }

    As you can see,  regardless of the simple definition of the previous class, its functionality is quite remarkable. In plain terms, the class in question is comprised of two basic methods (including the corresponding constructor, logically), and its main purpose is to return to client code the random strings required to create the pertinent noisy image.

    I have to admit that the prior "RandomGenerator" class is a simple wrapper for the procedural function that was defined in the first article of the series. However, if you feel inclined to work with object-based web applications, this class should be very appropriate to your programming needs.

    So far, so good. At this point I hopefully demonstrated in a friendly fashion how to use a basic PHP class to generate the random strings required to make the noisy images work properly.

    So, what's the next step concerning the implementation of the noisy images? Well, since I wish you to see how this brand new class can be neatly linked to the same PHP file that was defined in the preceding article of the series, in the section to come I'm going to list the complete source code of this file, logically including the "RandomGenerator" class.

    To read the next chapter of this article, please click on the link below and keep reading.

    More DHTML Articles
    More By Alejandro Gervasio


       · If you found interesting the first article of the series, then this one will be...
     

    DHTML ARTICLES

    - Text-Justify, Volume, and Other Style Sheet ...
    - Ruby-Position, Size, and Other Style Sheet P...
    - Padding, Pages, and More Style Sheet Propert...
    - Marks, Orphans, and More Style Sheet Propert...
    - Layouts, Margins, and Other Style Sheet Prop...
    - Floats, Fonts, and Other Style Sheet Propert...
    - Color, Filters, and Other Style Sheet Proper...
    - Borders and More with Style Sheets
    - Learning Style Sheet Properties
    - Style Sheet Property Reference
    - Completing a Noisy Image Application
    - An Object-Based Approach to Building Noisy I...
    - A Basic Method for Building Noisy Images
    - Adding More Features to Sliders with the Scr...
    - Using Sliders with the Scriptaculous Framewo...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek