POV-Ray : Newsgroups : povray.general : Lego Problems : Re: Lego Problems Server Time
3 Aug 2024 18:21:42 EDT (-0400)
  Re: Lego Problems  
From: Mike Williams
Date: 22 Nov 2003 07:17:21
Message: <Mi4AXDAhN1v$EwOY@econym.demon.co.uk>
Wasn't it Stonefox who wrote:
>Hi All
>
>Im new to povray and Im studying computer graphics as a module for my final
>uni course.
>
>Ive been having a play around with povray and Im trying to make a lego brick
>wall.
>
>Ive written a macro that creates a lego brick of what ever size u want to
>make it then ive written a loop which will create a brick wall given in a
>multidimensional array
>
>so if the array is like
>
>2,4,4,4,2
>4,4,4,4,0
>
>then the brick wall should look like this
>
>[..][..][..][..]
>[][..][..][..][]
>
>but somewhere my maths for the brick translation has gone wrong and what i
>actually get is this
>
>[..][..][..][..]
>[][..]  [..][..][]
>
>i know i need to some how translate each brick based on the size of the
>previous brick as well as the current brick size but i just cant get my
>head around what i need to do.

What you're currently doing is offsetting the brick by 
(number of bricks so far) * (size of previous brick)
which only really works if the bricks in a row are all the same size.

E.g. when processing the row "2, 4, 4, 2" the third brick should be
offset by 6, but you're offsetting it by (2)*(4).

The only way to position the bricks correctly if the brick size can vary
along a row is to keep a running total of the position by adding the
width of each brick.

Replace your placement loop with the following code. The running total
of sizes of bricks placed is held in the new variable PX. It is then
possible to remove the lastX parameter from the macro if you wish, it no
longer does anything.

#declare R1 = seed(0);
#declare aicnt=0;
#while(aicnt<WallY)
 #declare PX = 0;
 #declare ajcnt=0;
 #while(ajcnt<WallX)
   legobrick(Wall[aicnt][ajcnt],2,
             pigment{rgb<rand(R1),rand(R1),rand(R1)>},PX,aicnt,1)
  #declare PX=PX+Wall[aicnt][ajcnt] ;
  #declare ajcnt=ajcnt+1;
 #end
 #declare aicnt=aicnt+1;
#end

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

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