?
Solved

Converting PHP to Coldfusion

Posted on 2008-11-17
5
Medium Priority
?
332 Views
Last Modified: 2012-08-13
Hello,
I have a file which creates output for a swf to read.  The dynamic aspect is in PHP and I need to convert to Coldfusion.
<gauge>
 
 
	<!-- large gauge -->
	<circle x='145' y='130' radius='110' fill_color='555555' fill_alpha='100' line_thickness='6' line_color='333333' line_alpha='90' />
	<circle x='145' y='130' radius='100' start='240' end='480' fill_color='99bbff' fill_alpha='90' line_thickness='4' line_alpha='20' />
	<circle x='145' y='130' radius='94' start='50' end='115' fill_color='FF4400' fill_alpha='100' />
	<circle x='145' y='130' radius='80' start='240' end='480' fill_color='99bbff' fill_alpha='80' />
	<circle x='145' y='130' radius='40' fill_color='333333' fill_alpha='100' line_alpha='0' />
	<circle x='145' y='130' radius='90' start='130' end='230' fill_color='333333' fill_alpha='100' line_alpha='0' />
	
	<?php
	//these are PHP functions that generate the XML to to draw radial ticks and numbers
	//any script language can be used to generate the XML code like this
	RadialTicks( 145, 130, 80, 15, 250, 387, 6, 8, "000000" );
	RadialTicks( 145, 130, 80, 15, 263, 400, 6, 4, "000000" );
	RadialTicks( 145, 130, 80, 15, 55, 110, 3, 4, "99bbff" );
	RadialNumbers( 145, 130, 80, 0, 8, 245, 465, 9, 14, "444444" );
	?>
	
	<rotate x='145' y='130' start='0' span='50' step='3' shake_frequency='100' shake_span='2' shadow_alpha='15'>
		<rect x='143' y='40' width='4' height='100' fill_color='ffffff' fill_alpha='90' line_alpha='0' />
	</rotate>
	
	<circle x='145' y='130' radius='30' fill_color='111111' fill_alpha='100' line_thickness='5' line_alpha='50' />
	<text x='95' y='180' width='100' size='14' color='ffffff' alpha='70' align='center'>x1000 r/min</text>
	
	
	
	
	<!-- background elements -->
	<text x='-10' y='250' width='500' size='24' color='000000' alpha='20' align='left'>||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||</text>
	<text x='400' y='0' width='300' size='49' color='ffffff' alpha='15' align='left' rotation='90'>dashboard</text>
	
	
	
	<?php
	//====================================
	//PHP function that generates the XML code to draw radial ticks
	function RadialTicks ( $x_center, $y_center, $radius,  $length, $start_angle, $end_angle, $ticks_count, $thickness, $color ){
		
		for ( $i=$start_angle; $i<=$end_angle; $i+=($end_angle-$start_angle)/($ticks_count-1) ){
			echo "	
<line x1='".round($x_center+sin(deg2rad($i))*$radius)."' y1='".round($y_center-cos(deg2rad($i))*$radius)."' x2='".round($x_center+sin(deg2rad($i))*($radius+$length))."' y2='".round($y_center-cos(deg2rad($i))*($radius+$length))."' thickness='".$thickness."' color='".$color."' />";
		
		}
	}
	//====================================
	//PHP function that generates the XML code to draw radial numbers
	function RadialNumbers ( $x_center, $y_center, $radius,  $start_number, $end_number, $start_angle, $end_angle, $ticks_count, $font_size, $color ){
		
		$number=$start_number;
		
		for( $i=$start_angle; $i<=$end_angle; $i+=($end_angle-$start_angle)/($ticks_count-1) ){
			echo "
	<text x='".round($x_center+sin(deg2rad($i))*$radius)."' y='".round($y_center-cos(deg2rad($i))*$radius)."' width='200' size='".$font_size."' color='".$color."' align='left' rotation='".$i."'>".$number."</text>";
			$number += ($end_number-$start_number)/($ticks_count-1);
		
		}
	}
	//====================================
	?>
	
	
</gauge>

Open in new window

0
Comment
Question by:CalDev
  • 3
5 Comments
 
LVL 16

Accepted Solution

by:
duncancumming earned 2000 total points
ID: 22978463
Coldfusion doesn't have a built-in degrees to radians function, but someone else has already written one ( http://www.cflib.org/udf/DegToRad )

This code is completely untested, but should give you the general idea.  Normally you wouldn't use WriteOutput like this, but for simplicity I have done so to mimic as close as possible the original PHP.
<cfscript>
/**
* Converts degrees to radians.
*
* @param degrees      Angle (in degrees) you want converted to radians.
* @return Returns a simple value
* @author Rob Brooks-Bilson (rbils@amkor.com)
* @version 1.0, July 18, 2001
*/
function deg2rad(degrees)
{
Return (degrees*(Pi()/180));
}
	//Coldfusion function that generates the XML code to draw radial ticks
	function RadialTicks ( x_center, y_center, radius, length, start_angle, end_angle, ticks_count, thickness, color ){
		var i = 0; 
		for ( i=arguments.start_angle; i LTE arguments.end_angle; i = i + (arguments.end_angle-arguments.start_angle)/(arguments.ticks_count-1) ){
			WriteOutput("  
<line x1='#round(arguments.x_center+sin(deg2rad(i))*arguments.radius)#' y1='#round(arguments.y_center-cos(deg2rad(i))*arguments.radius)#' x2='#round(arguments.x_center+sin(deg2rad(i))*(arguments.radius+arguments.length))#' y2='#round(arguments.y_center-cos(deg2rad(i))*(arguments.radius+arguments.length))#' thickness='#arguments.thickness#' color='arguments.color#' />");
		
		}
	}
	
	//Coldfusion function that generates the XML code to draw radial numbers
	function RadialNumbers ( x_center, y_center, radius,  start_number, end_number, start_angle, end_angle, ticks_count, font_size, color ){
		
		var number = arguments.start_number;
		var i = 0; 
		
		for( i= arguments.start_angle; i  LTE end_angle; i = i + (arguments.end_angle-arguments.start_angle)/(arguments.ticks_count-1) ){
			WriteOutput("
	<text x='#round(arguments.x_center+sin(deg2rad(i))*arguments.radius)#' y='#round(arguments.y_center-cos(deg2rad(i))*arguments.radius)#' width='200' size='#arguments.font_size#' color='#arguments.color#' align='left' rotation='#i#'>#number#</text>");
			number = number + (arguments.end_number-arguments.start_number)/(arguments.ticks_count-1);
		
		}
	}
	</cfscript>

Open in new window

0
 
LVL 7

Expert Comment

by:black0ps
ID: 22978680
You are missing a pound sign on line 18 in front of arguments.
0
 
LVL 16

Expert Comment

by:duncancumming
ID: 22978714
So I have.  Correct line is:
<line x1='#round(arguments.x_center+sin(deg2rad(i))*arguments.radius)#' y1='#round(arguments.y_center-cos(deg2rad(i))*arguments.radius)#' x2='#round(arguments.x_center+sin(deg2rad(i))*(arguments.radius+arguments.length))#' y2='#round(arguments.y_center-cos(deg2rad(i))*(arguments.radius+arguments.length))#' thickness='#arguments.thickness#' color='#arguments.color#' />");

I'd missed the opening # in front of arguments.color
0
 
LVL 16

Expert Comment

by:duncancumming
ID: 22978732
I also missed out how you would call these functions:

<!---
        these are Coldfusion functions that generate the XML to to draw radial ticks and numbers
        any script language can be used to generate the XML code like this --->
<cfoutput>
        #RadialTicks( 145, 130, 80, 15, 250, 387, 6, 8, "000000" )#
        #RadialTicks( 145, 130, 80, 15, 263, 400, 6, 4, "000000" )#
        #RadialTicks( 145, 130, 80, 15, 55, 110, 3, 4, "99bbff" )#
        #RadialNumbers( 145, 130, 80, 0, 8, 245, 465, 9, 14, "444444" )#
</cfoutput>
0
 

Author Closing Comment

by:CalDev
ID: 31517538
perfect, got me pointed in the correct direction, thanks.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question