Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: allocating/deallocating colors with GD module.

by moritz (Cardinal)
on Jun 24, 2013 at 17:16 UTC ( #1040458=note: print w/replies, xml ) Need Help??

in reply to allocating/deallocating colors with GD module.

From the little information you have given us, I'd guess that the arithmetic expressions in the arguments to colorAllocate return values outside the range 0..255.

But please provide a runnable, minimal example that demonstrates how stuff doesn't work.

Replies are listed 'Best First'.
Re^2: allocating/deallocating colors with GD module.
by Anonymous Monk on Jun 24, 2013 at 17:48 UTC

    I'm making a julia fractal, i've added the code:

    use GD; use Math::Complex; $img = new GD::Image(400,400); $black = $img->colorAllocate(0,0,0); $bl = $img->colorAllocate(0,0,50); $blue = $img->colorAllocate(0,0,50); $c = cplx(-0.70,-0.38); for($x=-200;$x<=200;$x++){ for($y=-200;$y<=200;$y++){ $z = cplx($x/100,$y/100); $teller = 0; che(); } } binmode STDOUT; print $img->png; sub che(){ $zz = $z**2 + $c; if(abs($zz)>2){ if($teller<=3){ $img->setPixel(200+$x,200+$y,$blue);} else{ $img->colorDeallocate($bl); $bl = $img->colorAllocate(0,0,25*$teller); $img->setPixel(200+$x,200+$y,$bl);} } elsif(abs($zz<2)){ if($teller<8){ $teller++; $z = $zz; che(); } } }

    So after 3 iterations i want the blue component($bl) to be 25 * $teller, so a maximum of 200. But on the picture the blue becomes brighter(must be 100) only once. As if it deallocated once(it was 50 to start with, as you can see at the beginning) and not every time that part of code is executed. So my question is: can you deallocate a color and then allocate it again like in my program. And is this really necessary, because like i said in my original question sometimes you can simply allocate it with different rgb-components without deallocating it first. Thank you.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1040458]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2017-06-24 20:03 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (562 votes). Check out past polls.