/* =========================================================== IMP-PROJECT: ESCAPE-IRTC CARD.INC: PLAYING CARDS =========================================================== http://www.imp.org ----------------------------------------------------------- GENERAL ----------------------------------------------------------- Scale: 1cm = 1 POV-Unit ----------------------------------------------------------- THIS FILE ----------------------------------------------------------- This file defines a number of macros for creating playing cards, picking from the pack at random and then building a house of cards from them. Version: 0.01 Author: Andy Read (Andy (at) Azurite.co.uk) */ //SOME DECLARES #declare CARD_WIDTH = 6; #declare CARD_HEIGHT = 9; #declare CARD_THICKNESS = 0.03; #declare CARD_CORNER_RADIUS = 0.3; #declare CARD_SPACING = 7; #declare CARD_LEAN = degrees(asin((CARD_SPACING-CARD_THICKNESS)/2/CARD_HEIGHT)); #declare LAYER_HEIGHT = CARD_HEIGHT*cos(radians(CARD_LEAN)); #macro Card(card_file) intersection { union // face and back { box { <-CARD_WIDTH/2, 0, -CARD_THICKNESS/2>, pigment { image_map { gif card_file } translate x*0.5 scale <6,9,1> } } box { <-CARD_WIDTH/2, 0, 0>, pigment { image_map { jpeg "cards/card_back_blue.jpg" } translate x*0.5 scale <-6,9,1> } } } union // curved corners { cylinder { , , CARD_CORNER_RADIUS } cylinder { , , CARD_CORNER_RADIUS } cylinder { , , CARD_CORNER_RADIUS } cylinder { , , CARD_CORNER_RADIUS } box { <-CARD_WIDTH/2, CARD_CORNER_RADIUS, -CARD_THICKNESS>, } box { , } } pigment { color rgb 1 } } #end #declare CardPack = array[54] { "S1","S2","S3","S4","S5","S6","S7","S8","S9","S10","SJ","SQ","SK", "H1","H2","H3","H4","H5","H6","H7","H8","H9","H10","HJ","HQ","HK", "C1","C2","C3","C4","C5","C6","C7","C8","C9","C10","CJ","CQ","CK", "D1","D2","D3","D4","D5","D6","D7","D8","D9","D10","DJ","DQ","DK", "J1","J2" } #declare PackSize = 52; #declare PackRand = seed(3333); #macro RandCard() #local CardNum = int(PackSize*rand(PackRand)); #declare PackSize = PackSize-1; #local CardStub = CardPack[CardNum]; #declare CardPack[CardNum] = CardPack[PackSize]; #declare CardPack[PackSize] = CardStub; concat ("cards/card_", CardStub, ".gif") #end #macro HouseOfCards(LAYERS) union { #local R1 = seed(12345); // initialize random number streams #local Layer = 0; #while (Layer < LAYERS) #local Position = 0; #while (Position < LAYERS-Layer) #if (Layer>0) object { Card ( RandCard() ) rotate -x*90 translate <0, Layer*LAYER_HEIGHT+mod(Position,2)*CARD_THICKNESS, ((LAYERS-Layer-1)/2-Position)*CARD_SPACING + CARD_HEIGHT/2> rotate y*(3-6*rand(R1)) } #end object { Card ( RandCard() ) rotate -x*CARD_LEAN translate <0, Layer*LAYER_HEIGHT, ((LAYERS-Layer)/2-Position)*CARD_SPACING> } object { Card ( RandCard() ) rotate -x*CARD_LEAN rotate y*180 translate <0, Layer*LAYER_HEIGHT, ((LAYERS-Layer)/2-1-Position)*CARD_SPACING> } #local Position = Position+1; #end #local Layer = Layer+1; #end } #end #macro CardPackDrop(Radius) union { #local RD = seed(123); // initialize random number streams #local CardNum = 0; #while (CardNum < 52) #local PosAngle = radians(360*rand(RD)); #local PosRadius = Radius*rand(RD); #local SideUp = 1; #if (rand(RD)<0.5) #local SideUp = -1; #end object { Card ( RandCard() ) rotate x*90*SideUp rotate y*360*rand(RD) translate } #local CardNum = CardNum+1; #end } #end