POV-Ray : Newsgroups : povray.newusers : Any help in colors and java convertions ? Server Time
23 Nov 2024 03:14:12 EST (-0500)
  Any help in colors and java convertions ? (Message 1 to 6 of 6)  
From: kurtz le pirate
Subject: Any help in colors and java convertions ?
Date: 28 Sep 2019 11:35:42
Message: <5d8f7dce$1@news.povray.org>
Hello,

I'm trying to make pictures of the mandelbrot set. I found several 
examples on the web but I have a problem to adapt the sources.

Signifiant part of Java code building colors table :

import java.awt.Color;
int max = 1000;
int[] colors = new int[max];
for (int i = 0; i<max; i++) {
   colors[i] = Color.HSBtoRGB(i/256f, 1, i/(i+8f));
   }

Displaying "colors" table give :
    0 : 0.000000 0.000000 0.000000
    1 : 0.109804 0.003922 0.000000
    2 : 0.200000 0.007843 0.000000
    3 : 0.274510 0.019608 0.000000
    4 : 0.333333 0.031373 0.000000
    5 : 0.384314 0.043137 0.000000
    6 : 0.427451 0.058824 0.000000
    7 : 0.466667 0.078431 0.000000
    8 : 0.501961 0.094118 0.000000
    ...
    ...


Trying to do in POVRay :
#include "colors.inc"
#declare Max = 1000;
#declare ColorsArray = array[Max];
#declare i=0;
#while(i<Max)
   #declare ColorsArray[i] = CHSL2RGB(<i/256, 1, i/(i+8)>);
   #declare i=i+1;
#end

"ColorsArray" give :
    0 : 0.000000 0.000000 0.000000
    1 : 0.222222 0.003704 0.000000
    2 : 0.400000 0.013333 0.000000
    3 : 0.545455 0.027273 0.000000
    4 : 0.666667 0.044444 0.000000
    5 : 0.769231 0.064103 0.000000
    6 : 0.857143 0.085714 0.000000
    7 : 0.933333 0.108889 0.000000
    8 : 1.000000 0.133333 0.000000
    ...


he result is very different and, of course, the image does
not give the same thing... iI suspect the value 'hue' passed to the 
macro, but after several attempts I can't do it (i/360, i*360/max,...)


A little help would be welcome :)




Refs :
-----
* Page for Java source - Let’s draw the Mandelbrot set!
<http://jonisalonen.com/2013/lets-draw-the-mandelbrot-set/>

* Page for online java execution if you want to test code...
<https://www.tutorialspoint.com/compile_java_online.php>




-- 
Kurtz le pirate
Compagnie de la Banquise


Post a reply to this message

From: Bald Eagle
Subject: Re: Any help in colors and java convertions ?
Date: 28 Sep 2019 16:35:00
Message: <web.5d8fc2e7ad658b704eec112d0@news.povray.org>
kurtz le pirate <kur### [at] gmailcom> wrote:

> I'm trying to make pictures of the mandelbrot set. I found several
> examples on the web but I have a problem to adapt the sources.
    ...

Looks like the numbers in the java are hexadecimal, so 256f = 9583 and 8f is
143.
The color map will go from _0 to 1_, so you'd need i/1000, and since HSL goes
from 0 to 360, i'd have _i_ run from 0 to i*(360/1000)
Not sure why they use i+143 as a divisor, but you can fiddle with that as well.

You'll need to go up to and not including ColorsArray[Max-1], correct?
(I never use #while, so I'm assuming if you get no errors, that i<Max gives you
that.)

Maybe check out:
https://www.youtube.com/watch?v=kY7liQVPQSc
for more inspiration.


Post a reply to this message

From: kurtz le pirate
Subject: Re: Any help in colors and java convertions ?
Date: 29 Sep 2019 04:25:55
Message: <5d906a93$1@news.povray.org>
On 28/09/2019 22:30, Bald Eagle wrote:
> 
> kurtz le pirate <kur### [at] gmailcom> wrote:
> 
>> I'm trying to make pictures of the mandelbrot set. I found several
>> examples on the web but I have a problem to adapt the sources.
>      ...
> 
> Looks like the numbers in the java are hexadecimal, so 256f = 9583 and 8f is
> 143.
> The color map will go from _0 to 1_, so you'd need i/1000, and since HSL goes
> from 0 to 360, i'd have _i_ run from 0 to i*(360/1000)
> Not sure why they use i+143 as a divisor, but you can fiddle with that as well.

I'll try it with this... and playing with 0x08 :)


> You'll need to go up to and not including ColorsArray[Max-1], correct?
> (I never use #while, so I'm assuming if you get no errors, that i<Max gives you
> that.)
Array and index is not a problem.


> Maybe check out:
> https://www.youtube.com/watch?v=kY7liQVPQSc
> for more inspiration.

Really interesting link.
Thanks


-- 
Kurtz le pirate
Compagnie de la Banquise


Post a reply to this message

From: Le Forgeron
Subject: Re: Any help in colors and java convertions ?
Date: 29 Sep 2019 12:17:29
Message: <5d90d919$1@news.povray.org>
Le 28/09/2019 à 17:35, kurtz le pirate a écrit :
> Hello,
> 
> I'm trying to make pictures of the mandelbrot set. I found several
> examples on the web but I have a problem to adapt the sources.
> 
> Signifiant part of Java code building colors table :
> 
> import java.awt.Color;
> int max = 1000;
> int[] colors = new int[max];
> for (int i = 0; i<max; i++) {
>   colors[i] = Color.HSBtoRGB(i/256f, 1, i/(i+8f));
>   }
> 

Beware, HSBtoRGB truncate the H part to keep only the part after the
decimal point, multiply it by 360 to get the Hue.


> Displaying "colors" table give :
>    0 : 0.000000 0.000000 0.000000
>    1 : 0.109804 0.003922 0.000000
>    2 : 0.200000 0.007843 0.000000
>    3 : 0.274510 0.019608 0.000000
>    4 : 0.333333 0.031373 0.000000
>    5 : 0.384314 0.043137 0.000000
>    6 : 0.427451 0.058824 0.000000
>    7 : 0.466667 0.078431 0.000000
>    8 : 0.501961 0.094118 0.000000
>    ...
>    ...
> 
> 
> Trying to do in POVRay :
> #include "colors.inc"
> #declare Max = 1000;
> #declare ColorsArray = array[Max];
> #declare i=0;
> #while(i<Max)
>   #declare ColorsArray[i] = CHSL2RGB(<i/256, 1, i/(i+8)>);
>   #declare i=i+1;
> #end
> 
> "ColorsArray" give :
>    0 : 0.000000 0.000000 0.000000
>    1 : 0.222222 0.003704 0.000000
>    2 : 0.400000 0.013333 0.000000
>    3 : 0.545455 0.027273 0.000000
>    4 : 0.666667 0.044444 0.000000
>    5 : 0.769231 0.064103 0.000000
>    6 : 0.857143 0.085714 0.000000
>    7 : 0.933333 0.108889 0.000000
>    8 : 1.000000 0.133333 0.000000
>    ...
> 
> 
> he result is very different and, of course, the image does
> not give the same thing... iI suspect the value 'hue' passed to the
> macro, but after several attempts I can't do it (i/360, i*360/max,...)
> 

for Hue, the macro expect something between 0 to 360, so adaptation
would be :
CHSL2RGB( < 360*i/256, 1, i/(i+8) > )


Post a reply to this message

From: Le Forgeron
Subject: Re: Any help in colors and java convertions ?
Date: 29 Sep 2019 12:25:14
Message: <5d90daea$1@news.povray.org>
Le 28/09/2019 à 22:30, Bald Eagle a écrit :
> 
> kurtz le pirate <kur### [at] gmailcom> wrote:
> 
>> I'm trying to make pictures of the mandelbrot set. I found several
>> examples on the web but I have a problem to adapt the sources.
>     ...
> 
> Looks like the numbers in the java are hexadecimal, so 256f = 9583 and 8f is
> 143.

Sorry to disappoint you, but 256f is notation for a literal float for
256. (bad bad Java !)

Due to division rules, it is important that to get a float, at least one
argument of the / is a float (i.e. int/int gives an integer, which is a
bad idea for hue in HSBtoRGB ).


https://stackoverflow.com/questions/41289696/floating-point-literal-floating-literal-double-literal/41289715


Post a reply to this message

From: kurtz le pirate
Subject: Re: Any help in colors and java convertions ?
Date: 30 Sep 2019 12:57:14
Message: <5d9233ea$1@news.povray.org>
On 29/09/2019 18:17, Le_Forgeron wrote:
>
> for Hue, the macro expect something between 0 to 360, so adaptation
> would be :
> CHSL2RGB( < 360*i/256, 1, i/(i+8) > )
> 

hum... < 360*i/Max, 1, i/(i+8) > ?
;)



-- 
Kurtz le pirate
Compagnie de la Banquise


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.