Re: [GD-DEVEL] Using GD with D
[email protected] (Alexander Brock)
| Newsgroups | php.gd.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi, >> dmd is the name of the command-line-compiler I use. >> DMD is the "Digital Mars D Compiler" >> implib is a command-line-tool which allows me to generate bgd.lib from >> bgd.dll > > Is it a special .lib or is it a standard lib one can use to compile > against gd with VisualC or mingw? If it is the same, you can try the > .lib available in the binary release. It's not the same, the .lib from the binary release isn't accepted by the D-linker. > I will try it, the D language sounds like good fun. It's a lot more fun than C/C++, I hate both for the array-handling. > Do you have the PHP sources? If you can use attachments, it will make > my life easier. It looks like the new lines are broken here: These are (or should be) Windows-linebreaks (\r\n), perhaps they were somehow converted to Unix-linebreaks (\n). Try to use Notepad2: http://www.flos-freeware.ch/notepad2.html I try to send the attachements again. Alexander
test.txt
(text/plain, 2.2 KB)
import std.stdio;
import std.math;
import std.conv;
import std.stream;
import gd.gd;
import gd.gd_io;
import gd.gdfx;
int main(char[][] args) {
if (args.length < 4) {
return 0;
}
holo t = new holo(toInt(args[1]), toInt(args[2]), toInt(args[3]));
return 0;
}
class holo {
float[][] image;
int width;
int height;
float lambda;
float wellenzahl;
float[][] raster;
public this(int width, int height, int lambda) {
this.width = width;
this.height = height;
this.getRaster();
this.lambda = cast(float)lambda*10E-5;
this.wellenzahl = 2*PI/this.lambda;
this.generate();
}
public void generate() {
float x1;
float y1;
float maxgegenstand;
float mingegenstand;
float bereich;
int grauwert;
gdImagePtr result;
_iobuf* output;
File file = new File;
bool firstrun = true;
this.image.length = this.width;
for (int x = 0; x < this.width; x++) {
x1 = x/this.width;
this.image[x].length = this.height;
for (int y = 0; y < this.height; y++) {
this.image[x][y] = 0;
foreach (float[] dot; this.raster) {
this.image[x][y] += cos(
this.wellenzahl
*
sqrt(
(x1-dot[0])*(x1-dot[0])
+ (y1-dot[1])*(y1-dot[1])
+ (dot[2]*dot[2])
)
);
}
if (firstrun) {
maxgegenstand = this.image[x][y];
mingegenstand = this.image[x][y];
}
else if(maxgegenstand < this.image[x][y]) {
maxgegenstand = this.image[x][y];
}
else if(mingegenstand > this.image[x][y]) {
mingegenstand = this.image[x][y];
}
}
}
result = gdImageCreateTrueColor(this.width, this.height);
bereich = maxgegenstand-mingegenstand;
for (int x = 0; x < this.width; x++) {
for (int y = 0; y < this.height; y++) {
this.image[x][y] = (this.image[x][y]-mingegenstand)/bereich*255;
grauwert = cast(int)this.image[x][y];
gdImageSetPixel(result, x, y, gdImageColorAllocate(result, grauwert, grauwert, grauwert));
}
}
output = fopen("rect.png", "wb");
writefln("1");
gdImagePng(result, output);
writefln("2");
fclose(output);
writefln("3");
}
public void getRaster() {
this.raster.length = 1;
this.raster[0].length = 3;
this.raster[0][0] = 5;
this.raster[0][1] = 5;
this.raster[0][2] = 20;
}
}
prog.txt
(text/plain, 2.5 KB)
<?php
$t = new holo();
class holo {
var $resolution = array('w' => 800, 'h' => 600);
var $lambda = 6.33E-5;
function __construct() {
$this->image = array();
$w = $this->resolution['w'];
$h = $this->resolution['h'];
$mittelwert = ($w+$h)/2;
$faktor = 0.1;
$this->object = array(
1 => math::mal(array(5, 6, 20), $faktor),
2 => math::mal(array(5, 7, 20), $faktor),
3 => math::mal(array(5, 8, 20), $faktor),
4 => math::mal(array(5, 9, 20), $faktor),
5 => math::mal(array(5, 10, 20), $faktor),
6 => math::mal(array(5, 1, 20), $faktor),
7 => math::mal(array(5, 2, 20), $faktor),
8 => math::mal(array(5, 3, 20), $faktor),
9 => math::mal(array(5, 4, 20), $faktor),
10 => math::mal(array(6, 5, 20), $faktor),
11 => math::mal(array(7, 5, 20), $faktor),
12 => math::mal(array(8, 5, 20), $faktor),
13 => math::mal(array(9, 5, 20), $faktor)
);
$this->wellenzahl = 2*pi()/$this->lambda;
$this->generate();
}
function generate() {
$w = $this->resolution['w'];
$h = $this->resolution['h'];
$start = microtime(true);
for ($x = 0; $x < $w; $x++) {
if ($x % 50 === 0 and $x >= 50) {
echo 'Rendering line '.$x.' of '.$w.' time left: '.round((microtime(true)-$start)/$x*($w-$x)).'sec'."\r\n";
}
$this->image[$x] = array();
$x1 = $x/$w;
for ($y = 0; $y < $h; $y++) {
$y1 = $y/$h;
$gegenstand = 0;
foreach ($this->object as $dot) {
$gegenstand += cos($this->wellenzahl*math::abstand(array($x1, $y1, 0), $dot));
}
if (!isset($maxgegenstand)) {
$maxgegenstand = $gegenstand;
}
else {
$maxgegenstand = max($gegenstand, $maxgegenstand);
}
if (!isset($mingegenstand)) {
$mingegenstand = $gegenstand;
}
else {
$mingegenstand = min($gegenstand, $mingegenstand);
}
$this->image[$x][$y] = $gegenstand;
}
}
$messbereich = $maxgegenstand-$mingegenstand;
$image = imagecreatetruecolor($w, $h);
foreach ($this->image as $x=>$line) {
foreach ($line as $y=>$val) {
$grau = ($val-$mingegenstand)/$messbereich*255;
imagesetpixel($image, $x, $y, imagecolorallocate($image, $grau, $grau, $grau));
}
}
imagepng($image, 'test.png');
}
}
class math {
function abstand($v1, $v2) {
$difference = 0;
foreach ($v1 as $key=>$val) {
$difference += ($v1[$key]-$v2[$key])*($v1[$key]-$v2[$key]);
}
return sqrt($difference);
}
function mal($v, $faktor) {
if (!is_array($v)) {
return $v*$faktor;
}
foreach ($v as $key=>$val) {
$v[$key] = $val*$faktor;
}
return $v;
}
}
?>