Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
//=======================================================================
3
// File:	JPGRAPH_LED.PHP
4
// Description:	Module to generate Dotted LED-like digits
5
// Created: 	2006-11-26
6
// Ver:		$Id: jpgraph_led.php 854 2007-03-18 20:03:18Z ljp $
7
//
8
// Copyright 2006 (c) Aditus Consulting. All rights reserved.
9
//========================================================================
10
 
11
// Constants for color schema
12
DEFINE('LEDC_RED',0);
13
DEFINE('LEDC_GREEN',1);
14
DEFINE('LEDC_BLUE',2);
15
DEFINE('LEDC_YELLOW',3);
16
DEFINE('LEDC_GRAY',4);
17
 
18
//========================================================================
19
// CLASS DigitalLED74
20
// Description:
21
// Construct a number as an image that looks like LED numbers in a
22
// 7x4 digital matrix
23
//========================================================================
24
class DigitalLED74 {
25
    var $iLED_X = 4, $iLED_Y=7;
26
 
27
    var $iLEDSpec = array( 0 => array(6,9,9,9,9,9,6),
28
			   1 => array(2,6,10,2,2,2,2),
29
			   2 => array(6,9,1,2,4,8,15),
30
			   3 => array(6,9,1,6,1,9,6),
31
			   4 => array(1,3,5,9,15,1,1),
32
			   5 => array(15,8,8,14,1,9,6),
33
			   6 => array(6,8,8,14,9,9,6),
34
			   7 => array(15,1,1,2,4,4,4),
35
			   8 => array(6,9,9,6,9,9,6),
36
			   9 => array(6,9,9,7,1,1,6),
37
			   '.' => array(0,0,0,0,0,3,3),
38
			   ' ' => array(0,0,0,0,0,0,0),
39
			   '#' => array(0,9,15,9,15,9,0),
40
			   'A' => array(6,9,9,15,9,9,9),
41
			   'B' => array(14,9,9,14,9,9,14),
42
			   'C' => array(6,9,8,8,8,9,6),
43
			   'D' => array(14,9,9,9,9,9,14),
44
			   'E' => array(15,8,8,14,8,8,15),
45
			   'F' => array(15,8,8,14,8,8,8),
46
			   'G' => array(6,9,8,8,11,9,6),
47
			   'H' => array(9,9,9,15,9,9,9),
48
			   'I' => array(14,4,4,4,4,4,14),
49
			   'J' => array(15,1,1,1,1,9,6),
50
			   'K' => array(8,9,10,12,12,10,9),
51
			   'L' => array(8,8,8,8,8,8,15)	),
52
 
53
	$iColorSchema = array(0 => array('red','darkred:0.9','red:0.3'),
54
			      1 => array('green','darkgreen','green:0.3'),
55
			      2 => array('lightblue:0.9','darkblue:0.85','darkblue:0.7'),
56
			      3 => array('yellow','yellow:0.4','yellow:0.3'),
57
			      4 => array('gray:1.4','darkgray:0.85','darkgray:0.7')),
58
 
59
	$iSuperSampling = 3, $iMarg = 1, $iRad = 4 ;
60
 
61
    function DigitalLED74($aRadius=2,$aMargin=0.6) {
62
	$this->iRad = $aRadius;
63
	$this->iMarg = $aMargin;
64
    }
65
 
66
    function SetSupersampling($aSuperSampling=2) {
67
	$this->iSuperSampling = $aSuperSampling;
68
    }
69
 
70
    function _GetLED($aLedIdx,$aColor=0) {
71
 
72
	if( $aColor < 0 || $aColor > 4 )
73
	    $aColor = 0 ;
74
 
75
	$width=  $this->iLED_X*$this->iRad*2 +  ($this->iLED_X+1)*$this->iMarg + $this->iRad ;
76
	$height= $this->iLED_Y*$this->iRad*2 +  ($this->iLED_Y+1)*$this->iMarg + $this->iRad * 2;
77
 
78
	// Adjust radious for supersampling
79
	$rad = $this->iRad * $this->iSuperSampling;
80
 
81
	// Margin in between "Led" dots
82
	$marg = $this->iMarg * $this->iSuperSampling;
83
 
84
	$swidth = $width*$this->iSuperSampling;
85
	$sheight = $height*$this->iSuperSampling;
86
 
87
	$simg = new RotImage($swidth,$sheight,0,DEFAULT_GFORMAT,false);
88
	$simg->SetColor($this->iColorSchema[$aColor][2]);
89
	$simg->FilledRectangle(0,0,$swidth-1,$sheight-1);
90
 
91
 
92
	$d = $this->iLEDSpec[$aLedIdx];
93
 
94
	for( $r = 0 ; $r < 7; ++$r ) {
95
 
96
	    $dr = $d[$r];
97
 
98
	    for($c=0; $c < 4; ++$c ) {
99
 
100
		if( ($dr & pow(2,3-$c)) !== 0 ) {
101
		    $color = $this->iColorSchema[$aColor][0];
102
		}
103
		else {
104
		    $color = $this->iColorSchema[$aColor][1];
105
		}
106
 
107
		$x = 2*$rad*$c+$rad + ($c+1)*$marg + $rad ;
108
		$y = 2*$rad*$r+$rad + ($r+1)*$marg + $rad ;
109
 
110
		$simg->SetColor($color);
111
		$simg->FilledCircle($x,$y,$rad);
112
 
113
	    }
114
	}
115
 
116
	$img =  new Image($width,$height,DEFAULT_GFORMAT,false);
117
	$img->Copy($simg->img,0,0,0,0,$width,$height,$swidth,$sheight);
118
	$simg->Destroy();
119
	unset($simg);
120
	return $img;
121
    }
122
 
123
    function Stroke($aValStr,$aColor=0) {
124
	$n=strlen($aValStr);
125
	for( $i=0 ; $i < $n; ++$i ) {
126
	    $d = substr($aValStr,$i,1);
127
	    if( ctype_digit($d) )
128
		$d = (int)$d;
129
	    else {
130
		$d = strtoupper($d);
131
		if( $d != '#' && $d != '.' && ($d < 'A' || $d > 'L') )
132
		    $d = ' ';
133
	    }
134
	    $digit_img[$i] = $this->_GetLED($d,$aColor);
135
	}
136
 
137
	$w = imagesx($digit_img[0]->img);
138
	$h = imagesy($digit_img[0]->img);
139
 
140
	$number_img = new Image($w*$n,$h,DEFAULT_GFORMAT,false);
141
 
142
	for($i=0; $i < $n; ++$i ) {
143
	    $number_img->Copy($digit_img[$i]->img,$i*$w,0,0,0,$w,$h,$w,$h);
144
	}
145
 
146
	$number_img->Headers();
147
	$number_img->Stream();
148
 
149
    }
150
}
151
 
152
 
153
?>