POV-Ray : Newsgroups : povray.binaries.images : New year post Server Time
7 Aug 2024 23:16:38 EDT (-0400)
  New year post (Message 21 to 22 of 22)  
<<< Previous 10 Messages Goto Initial 10 Messages
From: Bill Pragnell
Subject: Re: New year post
Date: 5 Jan 2006 11:10:00
Message: <web.43bd44938e10781731f01d10@news.povray.org>
"Gail Shaw" <gsh### [at] sentechsacom> wrote:
> "Bill Pragnell" <bil### [at] hotmailcom> wrote in message
> news:web.43bcf1ff8e10781731f01d10@news.povray.org...
> > I can post the code if anybody wants, although I've not finished tinkering
> > with it yet...!
> Please, I'd love to play with it.

Right, here's the whole thing so far. It's the complete scene, which is
obviously more complicated than single object placement. I've included the
brick macro I used as well (not smoothed, sadly). It's a bit involved, and
some of the numbers in the stair set-up are critical to the start/finish
meeting each other neatly, but hopefully you get the idea. If you have any
problems with any of it feel free to email me or post a query.
Here goes... :)

#include "colors.inc"
#include "shapes.inc"
#include "math.inc"
#include "transforms.inc"

camera {
  location <0, 26, 0.05>
  up <0, 1, 0>
  right <4/3, 0, 0>
  direction <0, 0, FoV_30>
  look_at <0, 0, -0.5> }

light_source { <-70, 50, -100> color rgb 2*<0.25,0.75,1> }
light_source { <100, 0, 0> color rgb 2*<1,0.25,0> }

// rectangle mesh macro
#macro Rect(p1, p2, p3, p4)
  triangle { p1, p2, p3 }
  triangle { p1, p3, p4 }
#end

// rough rounded box mesh macro
#macro RoundedBox_M(xs, ys, zs, r)
  #local rb = r*(1 - sin(radians(45)));
  mesh {
  // near face
  Rect( <-xs+r, -ys+r, -zs>, <-xs+r, ys-r, -zs>, <xs-r, ys-r, -zs>, <xs-r,
-ys+r, -zs> )
  // near top horizontal curve
  Rect( <-xs+r, ys-r, -zs>, <-xs+r, ys-rb, -zs+rb>, <xs-r, ys-rb, -zs+rb>,
<xs-r, ys-r, -zs> )
  Rect( <-xs+r, ys-rb, -zs+rb>, <-xs+r, ys, -zs+r>, <xs-r, ys, -zs+r>,
<xs-r, ys-rb, -zs+rb> )
  // near bottom horizontal curve
  Rect( <-xs+r, -ys+rb, -zs+rb>, <-xs+r, -ys+r, -zs>, <xs-r, -ys+r, -zs>,
<xs-r, -ys+rb, -zs+rb> )
  Rect( <-xs+r, -ys, -zs+r>, <-xs+r, -ys+rb, -zs+rb>, <xs-r, -ys+rb,
-zs+rb>, <xs-r, -ys, -zs+r> )
  // near left vertical curve
  Rect( <-xs+r, -ys+r, -zs>, <-xs+rb, -ys+r, -zs+rb>, <-xs+rb, ys-r,
-zs+rb>, <-xs+r, ys-r, -zs> )
  Rect( <-xs+rb, -ys+r, -zs+rb>, <-xs, -ys+r, -zs+r>, <-xs, ys-r, -zs+r>,
<-xs+rb, ys-r, -zs+rb> )
  // near right vertical curve
  Rect( <xs-r, -ys+r, -zs>, <xs-rb, -ys+r, -zs+rb>, <xs-rb, ys-r, -zs+rb>,
<xs-r, ys-r, -zs> )
  Rect( <xs-rb, -ys+r, -zs+rb>, <xs, -ys+r, -zs+r>, <xs, ys-r, -zs+r>,
<xs-rb, ys-r, -zs+rb> )
  // top face
  Rect( <-xs+r, ys, -zs+r>, <-xs+r, ys, zs-r>, <xs-r, ys, zs-r>, <xs-r, ys,
-zs+r> )
  // left top long curve
  Rect( <-xs+r, ys, -zs+r>, <-xs+rb, ys-rb, -zs+r>, <-xs+rb, ys-rb, zs-r>,
<-xs+r, ys, zs-r> )
  Rect( <-xs+rb, ys-rb, -zs+r>, <-xs, ys-r, -zs+r>, <-xs, ys-r, zs-r>,
<-xs+rb, ys-rb, zs-r> )
  // right top long curve
  Rect( <xs-r, ys, -zs+r>, <xs-r, ys, zs-r>, <xs-rb, ys-rb, zs-r>, <xs-rb,
ys-rb, -zs+r> )
  Rect( <xs-rb, ys-rb, -zs+r>, <xs-rb, ys-rb, zs-r>, <xs, ys-r, zs-r>, <xs,
ys-r, -zs+r> )
  // left bottom long curve
  Rect( <-xs, -ys+r, -zs+r>, <-xs+rb, -ys+rb, -zs+r>, <-xs+rb, -ys+rb,
zs-r>, <-xs, -ys+r, zs-r> )
  Rect( <-xs+rb, -ys+rb, -zs+r>, <-xs+r, -ys, -zs+r>, <-xs+r, -ys, zs-r>,
<-xs+rb, -ys+rb, zs-r> )
  // right bottom long curve
  Rect( <xs, -ys+r, -zs+r>, <xs, -ys+r, zs-r>, <xs-rb, -ys+rb, zs-r>,
<xs-rb, -ys+rb, -zs+r> )
  Rect( <xs-rb, -ys+rb, -zs+r>, <xs-rb, -ys+rb, zs-r>, <xs-r, -ys, zs-r>,
<xs-r, -ys, -zs+r> )
  // bottom face
  Rect( <-xs+r, -ys, -zs+r>, <xs-r, -ys, -zs+r>, <xs-r, -ys, zs-r>, <-xs+r,
-ys, zs-r> )
  // left face
  Rect( <-xs, ys-r, -zs+r>, <-xs, -ys+r, -zs+r>, <-xs, -ys+r, zs-r>, <-xs,
ys-r, zs-r> )
  // right face
  Rect( <xs, ys-r, -zs+r>, <xs, ys-r, zs-r>, <xs, -ys+r, zs-r>, <xs, -ys+r,
-zs+r> )
  // back face
  Rect( <-xs+r, -ys+r, zs>, <xs-r, -ys+r, zs>, <xs-r, ys-r, zs>, <-xs+r,
ys-r, zs> )
  // back top horizontal curve
  Rect( <-xs+r, ys-r, zs>, <xs-r, ys-r, zs>, <xs-r, ys-rb, zs-rb>, <-xs+r,
ys-rb, zs-rb> )
  Rect( <-xs+r, ys-rb, zs-rb>, <xs-r, ys-rb, zs-rb>, <xs-r, ys, zs-r>,
<-xs+r, ys, zs-r> )
  // back bottom horizontal curve
  Rect( <-xs+r, -ys+r, zs>, <-xs+r, -ys+rb, zs-rb>, <xs-r, -ys+rb, zs-rb>,
<xs-r, -ys+r, zs> )
  Rect( <-xs+r, -ys+rb, zs-rb>, <-xs+r, -ys, zs-r>, <xs-r, -ys, zs-r>,
<xs-r, -ys+rb, zs-rb> )
  // back left vertical curve
  Rect( <-xs+r, ys-r, zs>, <-xs+rb, ys-r, zs-rb>, <-xs+rb, -ys+r, zs-rb>,
<-xs+r, -ys+r, zs> )
  Rect( <-xs+rb, ys-r, zs-rb>, <-xs, ys-r, zs-r>, <-xs, -ys+r, zs-r>,
<-xs+rb, -ys+r, zs-rb> )
  // back right vertical curve
  Rect( <xs-r, ys-r, zs>, <xs-r, -ys+r, zs>, <xs-rb, -ys+r, zs-rb>, <xs-rb,
ys-r, zs-rb> )
  Rect( <xs-rb, ys-r, zs-rb>, <xs-rb, -ys+r, zs-rb>, <xs, -ys+r, zs-r>, <xs,
ys-r, zs-r> )
  // near top left corner
  triangle { <-xs+r, ys, -zs+r>, <-xs+r, ys-rb, -zs+rb>, <-xs+rb, ys-rb,
-zs+r> }
  triangle { <-xs+r, ys-rb, -zs+rb>, <-xs+r, ys-r, -zs>, <-xs+rb, ys-r,
-zs+rb> }
  triangle { <-xs+rb, ys-rb, -zs+r>, <-xs+rb, ys-r, -zs+rb>, <-xs, ys-r,
-zs+r> }
  triangle { <-xs+r, ys-rb, -zs+rb>, <-xs+rb, ys-r, -zs+rb>, <-xs+rb, ys-rb,
-zs+r> }
  // near top right corner
  triangle { <xs-r, ys, -zs+r>, <xs-rb, ys-rb, -zs+r>, <xs-r, ys-rb, -zs+rb>
}
  triangle { <xs-r, ys-rb, -zs+rb>, <xs-rb, ys-r, -zs+rb>, <xs-r, ys-r, -zs>
}
  triangle { <xs-rb, ys-rb, -zs+r>, <xs, ys-r, -zs+r>, <xs-rb, ys-r, -zs+rb>
}
  triangle { <xs-rb, ys-rb, -zs+r>, <xs-rb, ys-r, -zs+rb>, <xs-r, ys-rb,
-zs+rb> }
  // near bottom left corner
  triangle { <-xs+r, -ys+r, -zs>, <-xs+r, -ys+rb, -zs+rb>, <-xs+rb, -ys+r,
-zs+rb> }
  triangle { <-xs+rb, -ys+r, -zs+rb>, <-xs+rb, -ys+rb, -zs+r>, <-xs, -ys+r,
-zs+r> }
  triangle { <-xs+rb, -ys+rb, -zs+r>, <-xs+r, -ys+rb, -zs+rb>, <-xs+r, -ys,
-zs+r> }
  triangle { <-xs+rb, -ys+rb, -zs+r>, <-xs+rb, -ys+r, -zs+rb>, <-xs+r,
-ys+rb, -zs+rb> }
  // near bottom right corner
  triangle { <xs-r, -ys+r, -zs>, <xs-rb, -ys+r, -zs+rb>, <xs-r, -ys+rb,
-zs+rb> }
  triangle { <xs, -ys+r, -zs+r>, <xs-rb, -ys+r, -zs+rb>, <xs-rb, -ys+rb,
-zs+r> }
  triangle { <xs-r, -ys, -zs+r>, <xs-r, -ys+rb, -zs+rb>, <xs-rb, -ys+rb,
-zs+r> }
  triangle { <xs-r, -ys+rb, -zs+rb>, <xs-rb, -ys+r, -zs+rb>, <xs-rb, -ys+rb,
-zs+r> }
  // far top left corner
  triangle { <-xs+r, ys, zs-r>, <-xs+rb, ys-rb, zs-r>, <-xs+r, ys-rb, zs-rb>
}
  triangle { <-xs, ys-r, zs-r>, <-xs+rb, ys-r, zs-rb>, <-xs+rb, ys-rb, zs-r>
}
  triangle { <-xs+r, ys-r, zs>, <-xs+rb, ys-r, zs-rb>, <-xs+r, ys-rb, zs-rb>
}
  triangle { <-xs+rb, ys-r, zs-rb>, <-xs+rb, ys-rb, zs-r>, <-xs+r, ys-rb,
zs-rb> }
  // far top right corner
  triangle { <xs-r, ys, zs-r>, <xs-r, ys-rb, zs-rb>, <xs-rb, ys-rb, zs-r> }
  triangle { <xs-r, ys-r, zs>, <xs-rb, ys-r, zs-rb>, <xs-r, ys-rb, zs-rb> }
  triangle { <xs, ys-r, zs-r>, <xs-rb, ys-r, zs-rb>, <xs-rb, ys-rb, zs-r> }
  triangle { <xs-rb, ys-r, zs-rb>, <xs-rb, ys-rb, zs-r>, <xs-r, ys-rb,
zs-rb> }
  // far bottom left corner
  triangle { <-xs+r, -ys+r, zs>, <-xs+rb, -ys+r, zs-rb>, <-xs+r, -ys+rb,
zs-rb> }
  triangle { <-xs+r, -ys, zs-r>, <-xs+r, -ys+rb, zs-rb>, <-xs+rb, -ys+rb,
zs-r> }
  triangle { <-xs, -ys+r, zs-r>, <-xs+rb, -ys+rb, zs-r>, <-xs+rb, -ys+r,
zs-rb> }
  triangle { <-xs+rb, -ys+rb, zs-r>, <-xs+r, -ys+rb, zs-rb>, <-xs+rb, -ys+r,
zs-rb> }
  // far bottom right corner
  triangle { <xs-r, -ys, zs-r>, <xs-rb, -ys+rb, zs-r>, <xs-r, -ys+rb, zs-rb>
}
  triangle { <xs, -ys+r, zs-r>, <xs-rb, -ys+r, zs-rb>, <xs-rb, -ys+rb, zs-r>
}
  triangle { <xs-r, -ys+r, zs>, <xs-r, -ys+rb, zs-rb>, <xs-rb, -ys+r, zs-rb>
}
  triangle { <xs-r, -ys+rb, zs-rb>, <xs-rb, -ys+rb, zs-r>, <xs-rb, -ys+r,
zs-rb> } }
#end

#macro Knot_Pos(a)
  (<sin(a) + 2*sin(2*a), sin(3*a), cos(a) - 2*cos(2*a)>)
#end

// find knot length
#declare b = 0;
#declare db = 2*pi/10000;
#declare dist = 0;
#while (b <= 2*pi)
  #declare dpos1 = Knot_Pos(b);
  #declare dpos2 = Knot_Pos(b+db);
  #declare dist = dist + vlength(dpos2-dpos1);
  #declare b = b + db;
#end
#declare length = dist;

// set up brick array
#declare arraysize = 10;
#declare dlength = length/500;
#declare r1 = seed(1);
#declare ba = array[arraysize];
#declare c = 0;
#while (c < arraysize)
  #declare ba[c] = object {
    RoundedBox_M(0.03, dlength/2, 0.01, 0.005)
    pigment { color rgb rand(r1)*0.6+0.4 }
    finish { ambient 0 }
    normal { granite 0.2 scale rand(r1)*0.2 } }
  #declare c = c + 1;
#end

// brickknot
#declare nbricks = 50;
#declare b = 0;
#declare dbi = 0.0001;
#declare dist = 0;
#declare ob = b;
#declare ang = 0;
#declare dang = 360/nbricks;
#declare ap = 0;
#while (b <= 2*pi)
  #declare dpos1 = Knot_Pos(b);
  #declare dpos2 = Knot_Pos(b+dbi);
  #declare dist = dist + vlength(dpos2-dpos1);
  #if (dist >= dlength)
    #declare nb = b;
    #declare dir = Knot_Pos(nb) - Knot_Pos(ob);
    #declare midpos = Knot_Pos(ob + (nb-ob)/2);
    #declare axis = VPerp_To_Plane(dir,y);
    #declare rot = VRotationD(y,dir,axis);
    #while (ap < nbricks)
      object {
        ba[rand(r1)*arraysize]
        rotate <0, rand(r1)*10-5, 0>
        translate <0, 0, -0.5>
        rotate <0, ang, 0>
        Axis_Rotate_Trans(axis, rot)
        translate midpos }
      #declare ap = ap + 1;
      #declare ang = ang + dang;
    #end
    #declare dist = 0;
    #declare ob = nb;
    #declare ap = 0;
    // bet you can't guess what the next line does!
    #declare ang = ang + ((cos(3*b)+1)/2)*dang/2;
  #end
  #declare b = b + dbi;
#end

// set up stair array
#declare arraysize = 10;
#declare dlength = length/1051;
#declare sa = array[arraysize];
#declare c = 0;
#declare col = MediumWood;
#while (c < arraysize)
  #declare sa[c] = object {
    RoundedBox_M(0.65, dlength/2, 0.05, 0.005)
    pigment { color rgb col*(rand(r1)*0.6+0.4) }
    finish { ambient 0 }
    normal { granite 0.2 scale <rand(r1)*0.5+0.5, 0.1, 0.1> } }
  #declare c = c + 1;
#end

// handrail post
#declare Post = mesh {
  Rect( <-0.005, 0, -0.005>, <-0.005, 0.12, -0.005>, <0.005, 0.12, -0.005>,
<0.005, 0, -0.005> )
  Rect( <0.005, 0, -0.005>, <0.005, 0.12, -0.005>, <0.005, 0.12, 0.005>,
<0.005, 0, 0.005> )
  Rect( <0.005, 0, 0.005>, <0.005, 0.12, 0.005>, <-0.005, 0.12, 0.005>,
<-0.005, 0, 0.005> )
  Rect( <-0.005, 0, 0.005>, <-0.005, 0.12, 0.005>, <-0.005, 0.12, -0.005>,
<-0.005, 0, -0.005> )
  pigment { color Gray40 }
  finish { ambient 0 } }

// handrail cross-sections
#declare pos1_1 = <-0.64, 0.115, 0>;
#declare pos1_2 = <-0.64, 0.125, 0>;
#declare pos1_3 = <-0.62, 0.125, 0>;
#declare pos1_4 = <-0.62, 0.115, 0>;
#declare pos2_1 = <0.62, 0.115, 0>;
#declare pos2_2 = <0.62, 0.125, 0>;
#declare pos2_3 = <0.64, 0.125, 0>;
#declare pos2_4 = <0.64, 0.115, 0>;

// stairs
#declare b = 0;
#declare dbi = 0.00001;
#declare dist = 0;
#declare cdist = 0;
#declare ob = b;
#declare ang = 0;
#declare dang = 360/75;
#declare totalsteps = 0;
#while (cdist <= length+dlength)
  #declare dpos1 = Knot_Pos(b);
  #declare dpos2 = Knot_Pos(b+dbi);
  #declare dist = dist + vlength(dpos2-dpos1);
  #if (dist >= dlength)
    // calculate knot path location
    #declare nb = b;
    #declare dir = Knot_Pos(nb) - Knot_Pos(ob);
    #declare midpos = Knot_Pos(ob + (nb-ob)/2);
    #declare axis = VPerp_To_Plane(dir,y);
    #declare rot = VRotationD(y,dir,axis);
    #if (totalsteps > 0)
      #declare tran_old = tran;
    #end
    #declare tran = transform {
      rotate <0, ang, 0>
      Axis_Rotate_Trans(axis, rot)
      translate midpos }
    #if (totalsteps = 0)
      #declare tran_old = tran;
    #end
    // place stair
    object {
      sa[rand(r1)*arraysize]
      transform { tran } }
    // place handrail post
    #if (mod(totalsteps,3) = 0)
      object {
        Post
        translate <-0.63, 0, 0>
        transform { tran } }
      object {
        Post
        translate <0.63, 0, 0>
        transform { tran } }
    #end
    // grow handrails
    #declare oldpos1 = vtransform(pos1_1, tran_old);
    #declare oldpos2 = vtransform(pos1_2, tran_old);
    #declare oldpos3 = vtransform(pos1_3, tran_old);
    #declare oldpos4 = vtransform(pos1_4, tran_old);
    #declare newpos1 = vtransform(pos1_1, tran);
    #declare newpos2 = vtransform(pos1_2, tran);
    #declare newpos3 = vtransform(pos1_3, tran);
    #declare newpos4 = vtransform(pos1_4, tran);
    mesh {
      Rect(oldpos1, oldpos2, newpos2, newpos1)
      Rect(oldpos2, oldpos3, newpos3, newpos2)
      Rect(oldpos3, oldpos4, newpos4, newpos3)
      Rect(oldpos4, oldpos1, newpos1, newpos4)
      pigment { color DarkWood }
      finish { ambient 0 } }
    #declare oldpos1 = vtransform(pos2_1, tran_old);
    #declare oldpos2 = vtransform(pos2_2, tran_old);
    #declare oldpos3 = vtransform(pos2_3, tran_old);
    #declare oldpos4 = vtransform(pos2_4, tran_old);
    #declare newpos1 = vtransform(pos2_1, tran);
    #declare newpos2 = vtransform(pos2_2, tran);
    #declare newpos3 = vtransform(pos2_3, tran);
    #declare newpos4 = vtransform(pos2_4, tran);
    mesh {
      Rect(oldpos1, oldpos2, newpos2, newpos1)
      Rect(oldpos2, oldpos3, newpos3, newpos2)
      Rect(oldpos3, oldpos4, newpos4, newpos3)
      Rect(oldpos4, oldpos1, newpos1, newpos4)
      pigment { color DarkWood }
      finish { ambient 0 } }
    // increment counters
    #declare ang = ang + dang;
    #declare cdist = cdist + dist;
    #declare dist = 0;
    #declare ob = nb;
    #declare totalsteps = totalsteps + 1;
  #end
  #declare b = b + dbi;
#end


Post a reply to this message

From: povray
Subject: Re: New year post
Date: 6 Jan 2006 11:14:28
Message: <pan.2006.01.05.23.34.51.258041@localhost>
On Thu, 05 Jan 2006 05:17:42 -0500, Bill Pragnell wrote:

>> How the heck do you make this shape in POV-Ray?
> It's a parametric curve:
> x=sin(a)+2sin(2a)
> y=sin(3a)
> z=cos(a)-2cos(2a)
> 0 > a > 2pi
> 

Woa.  Cool.  Thanks  :D



-- 
to all the companies who wait until a large user base becomes
dependant on their freeware, then shafting said happy campers with
mandatory payment for continued usage. I spit on your grave.


Post a reply to this message

<<< Previous 10 Messages Goto Initial 10 Messages

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