POV-Ray : Newsgroups : povray.general : Lego Problems Server Time
16 Nov 2024 15:17:02 EST (-0500)
  Lego Problems (Message 1 to 3 of 3)  
From: Stonefox
Subject: Lego Problems
Date: 22 Nov 2003 06:10:02
Message: <web.3fbf43385172f455535179f30@news.povray.org>
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.

here is the povray code:-

global_settings{ambient_light 1}
#include "colors.inc"
#include "textures.inc"
#include "transforms.inc"

#declare block=
union{
box{<0,0,0><0.15,0.25,0.15>}

difference{
cylinder{<0,0,0><0,0.04,0>0.06 translate<0.075,0.25,0.075>}
//text{
  // ttf "arial.ttf",
  // "LEGO",0.45,0
  // rotate <0,90,-90> scale <0.025,0.025,0.025> translate<0.06,0.295,0.1> }
}

}


#macro legobrick(X,Z,col,xup,yup,lastX)

#declare icount=0;
#declare myblock=

union
  {
#while(icount<Z)
 #declare jcount=0;
  #while(jcount<X)
object {block pigment{col} translate<(jcount*0.15),0,icount*0.15>}
    #declare jcount=jcount+1;
  #end
  #declare icount=icount+1;
 #end
 }

object{myblock translate<(lastX*0.15)*xup,yup*0.25,0>}

#end

#declare WallX=5;
#declare WallY=2;

#declare Wall =
 array[WallY][WallX]
 {
  {2,4,4,4,2},
  {4,4,4,4,0}
 }

 #declare R1 = seed(0);
#declare lx=Wall[0][0];
#declare aicnt=0;
#while(aicnt<WallY)
 #declare ajcnt=0;
 #while(ajcnt<WallX)


legobrick(Wall[aicnt][ajcnt],2,pigment{rgb<rand(R1),rand(R1),rand(R1)>},ajcnt,aicnt,lx)
#declare lx=Wall[aicnt][ajcnt] ;
  #declare ajcnt=ajcnt+1;
 #end
 #declare aicnt=aicnt+1;
#end

background {color rgb <0.500, 0.500, 1.000>}
light_source {<0,15,-25> White}
light_source {<30,10,50> White}
light_source {<0,50,0> White}
light_source {<-8,14.6,3> rgbt<0.6,0.2,0.2,0.6>}
camera{location <4,1,-2> look_at <1,0,1>}


If anyone can post the right way of doing this so the bricks translate
properly id be very grateful:D

thank you in advance


Post a reply to this message

From: Stonefox
Subject: Re: Lego Problems
Date: 22 Nov 2003 07:05:01
Message: <web.3fbf4fee2c16dbaa535179f30@news.povray.org>
Fixed it, silly me

the new code:

global_settings{ambient_light 1}
#include "colors.inc"
#include "textures.inc"
#include "transforms.inc"

#declare block=
union{
box{<0,0,0><0.15,0.25,0.15>}

difference{
cylinder{<0,0,0><0,0.04,0>0.06 translate<0.075,0.25,0.075>}
text{
ttf "arial.ttf",
"LEGO",0.45,0
rotate <0,90,-90> scale <0.025,0.025,0.025> translate<0.06,0.295,0.1> }
}

}


#macro legobrick(X,Z,col,xup,yup,lastX)

#declare icount=0;
#declare myblock=

union
  {
#while(icount<Z)
 #declare jcount=0;
  #while(jcount<X)
object {block pigment{col} translate<(jcount*0.15),0,icount*0.15>}
    #declare jcount=jcount+1;
  #end
  #declare icount=icount+1;
 #end
 }

object{myblock translate<lastX*0.15,yup*0.25,0>}

#end

#declare WallX=5;
#declare WallY=4;

#declare Wall =
 array[WallY][WallX]
 {
  {2,4,4,4,2},
  {4,2,4,4,0},
  {2,4,4,4,2},
  {4,4,4,4,0}
 }

 #declare R1 = seed(0);

#declare aicnt=0;
#while(aicnt<WallY)
 #declare ajcnt=0;
 #declare lx=Wall[0][0];
 #while(ajcnt<WallX)


legobrick(Wall[aicnt][ajcnt],2,pigment{rgb<rand(R1),rand(R1),rand(R1)>},ajcnt,aicnt,lx)
#declare lx=Wall[aicnt][ajcnt]+lx ;
  #declare ajcnt=ajcnt+1;
 #end
 #declare aicnt=aicnt+1;
#end

background {color rgb <0.500, 0.500, 1.000>}
light_source {<0,15,-25> White}
light_source {<30,10,50> White}
light_source {<0,50,0> White}
light_source {<-8,14.6,3> rgbt<0.6,0.2,0.2,0.6>}
camera{location <4,3,-2> look_at <1,0,1>}


Stonefox 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.
>
>here is the povray code:-
>
>global_settings{ambient_light 1}
>#include "colors.inc"
>#include "textures.inc"
>#include "transforms.inc"
>
>#declare block=
>union{
>box{<0,0,0><0.15,0.25,0.15>}
>
>difference{
>cylinder{<0,0,0><0,0.04,0>0.06 translate<0.075,0.25,0.075>}
>//text{
>  // ttf "arial.ttf",
>  // "LEGO",0.45,0
>  // rotate <0,90,-90> scale <0.025,0.025,0.025> translate<0.06,0.295,0.1> }
>}
>
>}
>
>
>#macro legobrick(X,Z,col,xup,yup,lastX)
>
>#declare icount=0;
>#declare myblock=
>
>union
>  {
>#while(icount<Z)
> #declare jcount=0;
>  #while(jcount<X)
>object {block pigment{col} translate<(jcount*0.15),0,icount*0.15>}
>    #declare jcount=jcount+1;
>  #end
>  #declare icount=icount+1;
> #end
> }
>
>object{myblock translate<(lastX*0.15)*xup,yup*0.25,0>}
>
>#end
>
>#declare WallX=5;
>#declare WallY=2;
>
>#declare Wall =
> array[WallY][WallX]
> {
>  {2,4,4,4,2},
>  {4,4,4,4,0}
> }
>
> #declare R1 = seed(0);
>#declare lx=Wall[0][0];
>#declare aicnt=0;
>#while(aicnt<WallY)
> #declare ajcnt=0;
> #while(ajcnt<WallX)
>
>
>legobrick(Wall[aicnt][ajcnt],2,pigment{rgb<rand(R1),rand(R1),rand(R1)>},ajcnt,aicnt,lx)
>#declare lx=Wall[aicnt][ajcnt] ;
>  #declare ajcnt=ajcnt+1;
> #end
> #declare aicnt=aicnt+1;
>#end
>
>background {color rgb <0.500, 0.500, 1.000>}
>light_source {<0,15,-25> White}
>light_source {<30,10,50> White}
>light_source {<0,50,0> White}
>light_source {<-8,14.6,3> rgbt<0.6,0.2,0.2,0.6>}
>camera{location <4,1,-2> look_at <1,0,1>}
>
>
>If anyone can post the right way of doing this so the bricks translate
>properly id be very grateful:D
>
>thank you in advance
>


Post a reply to this message

From: Mike Williams
Subject: Re: Lego Problems
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.