#
# CSC 112 Ambrosia Example: defining an object to represent arrows
#
# Jim Teresco, The College of Saint Rose, Fall 2015
#
# Based on a model by Duane A. Bailey, Williams College
#
from ambrosia import *
# define some names for constant numbers we will need below
featherThickness = 2.5
featherWidth = 30
featherLength = 100
shaftDiameter = 10
shaftLength = 200
tipLength = 20
# we'll be adding then scaling some of our primitives, so let's define
# 1x1x1 versions of them to simplify scaling later
unitCube = Cube().scale(.01,.01,.01)
unitCone = Cone().scale(.01,.01,.01)
unitCylinder = Cylinder().scale(.01,.01,.01)
# Our arrows will have feathers on the tails, so define those.
# We start with a pair of cubes that cross, which are oriented along the
# y-axis
featherParts = Group()
featherParts.add(unitCube, scale(featherWidth,featherLength,featherThickness))
featherParts.add(unitCube, scale(featherThickness,featherLength,featherWidth))
# Next, intersect the featherParts with a cone to give them a nice
# angled shape. Note that the feathers are still oriented along the
# y-axis
feathers = Intersection()
feathers.add(featherParts)
feathers.add(unitCone, scale(featherWidth,featherLength,featherWidth))
# Compose the arrow as the tip, the main shaft, and the feathers.
# We align the whole thing facing up along the y-axis
arrow = Group()
# main shaft, always whitePlaster
# scaled, then moved atop the origin
arrow.add(unitCylinder,
scale(shaftDiameter,shaftLength,shaftDiameter)*
translate(0,shaftLength/2,0), whitePlaster)
# tip, also always whitePlaster
arrow.add(unitCone,
scale(shaftDiameter,tipLength,shaftDiameter)*
translate(0,shaftLength + tipLength/2, 0), whitePlaster)
# add in the feathers, but don't specify a material for these
arrow.add(feathers, translate(0, featherLength/2, 0))
# Add a few arrows to the scene
# first with default orientation and location
scene.add(arrow, bluePlaster)
# and others subject to some transformations
scene.add(arrow, zRot(90)*translate(100,-100,0), redPlaster)
scene.add(arrow, zRot(75)*translate(250,50,0), greenPlaster)
# back up the camera a bit, then get our image
camera.pos([0,0,-600])
camera.shoot()