I'm still not sure the following got sent yesterday,  so here's
a fourth attempt.
Sorry about the double-line-spacing,
M

On 24/06/2015 15:46, Mike Day wrote:
I've just had a look at the correspondence.

It seems to me that it's better to consider the 8 corners of the cube.
If we specify their colours,  then we merely need to interpolate the
colours along the edges and within the faces.

Here's an attempt to do that, plagiarising blatantly from Raul's earlier
postings. Over to Linda to render the code in basic J.

The 8 corners may indeed use the 8 colours in #:i.8,  but don't need to
do so,  and may use 8 triples of any numbers in [0.0,1.0].

The code follows below, with some comments, and apologies for line-wraps,
line-skips or whatever.

Also apologies for any typos in this patter,

Mike

NB. revision of Raul's colour-mixing verb,  with 4 corner colours
rather than 3
NB. given corner colours ABCD (4x3 array), and x>1 steps from A to B etc

NB. make an (x+1)x(x+1)x3 array of mixed colours

NB. assumes input colours are in [0,1], but output in [0,255]

msc=:mysquarecolours =: 3 : 0

:

nsteps =. x

'A B C D' =. y

lamda =. (,:~-.)@:(%~ i.@>:) nsteps

AB =. lamda +/@:(*/"1) A,:B NB. mix of colours between corners A & B

CD =. lamda +/@:(*/"1) D,:C NB. mix of colours between corners C & D

1 0 2 |: <.255 * lamda +/@:(*/"1) AB,:CD NB. transpose 'cos I got the
order wrong!

)


NB. Cube layout: A-H label the corners;

NB. (looked ok in the edit window, added ... to
NB.    force spacing!!!)
NB. ..H-G

NB. ..|+|

NB. H-E-F-G sides are AB,BC,...,BF,EA,...FG,GH

NB. |+|+|+| faces are ABCD, DCGH, ... HGFE

NB. D-A-B-C

NB. ..|+|

NB. ..D-C

NB. ..|+|

NB. ..H-G


NB. verb to draw the plan

NB. lhs = number of steps = %: number of facets on a face

NB. rhs = 8 x 3 array of corner colours in range [0,1]

mycube=: 3 : 0

:

nsteps =. 2 >. <: x

'A B C D H G F E' =. y

BLANK =. < BLACK;BLACK;BLACK;BLACK

FRONT =. < A;B;C;D

BACK =. < H;G;F;E

TOP =. < E;F;B;A

LEFT =. < H;E;A;D

RIGHT =. < F;G;C;B

BASE =. < D;C;G;H

plan =: BASE(<3 1)}FRONT(<2 1)}(LEFT,TOP,RIGHT)1}BACK(<0 1)}4 3$blank

colours =: ,/,/>,"_1 each/"1 nsteps mysquarecolours each plan

colours viewmat i.4 3*nsteps+1

)


NB. sample call using all colours in #:i.8

NB. 4 mycube BLACK,BLUE,WHITE,GREEN,RED,YELLOW,CYAN,:MAGENTA


NB. The colours don't have to be all distinct

NB. 3 mycube BLACK,BLUE,WHITE,GREEN,RED,YELLOW,BLUE,:BLACK


On 24/06/2015 07:18, Raul Miller wrote:
A color, for viewmat, the way you are using it, is a sequence of three
integers in the range 0 .. 255.

The problem is that none of the sequences in FRONT nor BASE are valid
colors.

This problem is made more confusing because while BLACK and WHITE are
single valued "colors", the others range from black to white with the
named color appearing in the middle. And then you're using just parts
of those sequences. The grammar may be "simple" but the abstractions
are not.

So... there are several problems to fix here, but the biggest problem
is that your results are not valid colors. If I subtract 255 from each
of the values you have there, they are better, but still not correct.

Anyways, if I look at the adjacent squares, FRONT should have:

at index 0 (upper left corner):  255 0 0
at index 4 (upper right corner):  255 0 255
at index 20 (lower left corner):  255 255 0
at index 24 (lower right corner): 255 255 255

  Similarly, BASE should have:

at index 0: 255 255 0
at index 4: 255 255 255
at index 20: 0 255 0
at index 24: 0 255 255

Instead, you have this:

     0 4 20 24{ FRONT -255
255 255 255
255   0 255
255 255   0
255   0   0
     0 4 20 24{ BASE -255
255 255 255
255 255   0
   0 255 255
   0 255   0

Hopefully this helps...




---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to