"""
Copyright (c) 2008, Carl Scheffler
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* The name of the copyright owner may not be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
from __future__ import division
import math
from fablib.FabTurtle import *
from fablib.FabSim import *
board = [[0.25, 0.25], [8.0, 8.0]] # (x, y), (dx, dy)
shaft_radius = 2 / 25.4 # 2mm
shafts = [[4.0, 4.0]]
for i in range(4):
x = 4.0
y = 4.0
ang = [i*pi/2, pi/3, pi/4]
dist = [2.5, 1.75, 1.2]
theta = 0
for j in range(len(ang)):
theta += ang[j]
x += dist[j]*math.cos(theta)
y += dist[j]*math.sin(theta)
shafts.append([x, y])
N = 20
commands = ['PU', 'POS', 0, 0, 'PD',
'POS', 0, board[1][1],
'POS', board[1][0], board[1][1],
'POS', board[1][0], 0,
'POS', 0, 0]
for shaft in shafts:
commands += ['PU', 'POS', shaft[0]+shaft_radius, shaft[1], 'PD']
for i in range(1, N+1):
commands += ['POS',
shaft[0] + shaft_radius * math.cos(i/N*2*math.pi),
shaft[1] + shaft_radius * math.sin(i/N*2*math.pi)]
myturtle = FabTurtle(commands)
myturtle.write_epi('board.epi', rate=500, power=10, speed=1, xoff=board[0][0], yoff=12-(board[1][1]+board[0][1]))
window = simulate_epi('board.epi')
window.wait_window()