예제 #1
0
파일: cone.py 프로젝트: teukkam/crochet-cad
def main(argv, global_options):
    """ Command entry-point for the cone pattern-generator. """
    import optparse
    _ = localization.get_translation()
    opt_parser = optparse.OptionParser(
    _('%prog [GLOBAL-OPTIONS] cone [--row-count=ROWS]'),
        description="""
Generate a crochet pattern for a cone.
""".strip())
    opt_parser.add_option(_('-r'), _('--row-count'), action='store', type='int',
        default=16, metavar='ROWS',
        help=_('the number of rows in the pattern. Defines the height'
        ' of the cone [%default]'))
    opt_parser.add_option(_('-c'), _('--max-circumference'), action='store',
        type='int', default=60, metavar='STITCHES',
        help=_('the number of stitches at the base of the pattern. Defines the'
        ' circumference of the base of the cone [%default]'))
    command_opts, __ = opt_parser.parse_args(argv)
    stitches = cone(command_opts.row_count, command_opts.max_circumference)
    stitches = snap(stitches, 1 if global_options.accurate else 6, 6)
    if not global_options.inhuman:
        title = _("Cone (%d rows, %d max-circumference)") % (
                command_opts.row_count, command_opts.max_circumference)
        print_instructions_txt(title, stitches)
    else:
        print_row_counts(stitches)
예제 #2
0
def main(argv, global_options):
    """
    Command entry-point for the donut pattern-generator.
    """
    import optparse
    _ = localization.get_translation()
    opt_parser = optparse.OptionParser(
        _('%prog [GLOBAL-OPTIONS] '
        'donut [--inner-radius=STITCHES] [--row-count=ROWS]'),
        description="""
Generate a pattern for a donut (torus). The pattern
starts off with a row in the centre (the donut hole) and crocheted up
and around.""".strip())
    opt_parser.add_option(_('-i'), _('--inner-radius'), action='store', type='int',
        default=18, metavar='STITCHES',
        help=_('the circumference of the donut hole, in stitches [%default]'))
    opt_parser.add_option('-r', '--row-count', action='store', type='int',
        default=16, metavar='ROWS',
        help=_("the number of rows in the pattern - defines the 'thickness'"
            " of the donut [%default]"))
    command_opts, __ = opt_parser.parse_args(argv)
    stitches = donut(command_opts.inner_radius, command_opts.row_count)
    stitches = snap(stitches, 1 if global_options.accurate else 6)
    
    if not global_options.inhuman:
        title = _("Donut (inner-radius: %d, %d rows)") % (
                command_opts.inner_radius, command_opts.row_count)
        print_instructions_txt(title, stitches)
    else:
        print_row_counts(stitches)
예제 #3
0
def main(argv, global_options):
    """ Command entry-point for the cone pattern-generator. """
    _ = localization.get_translation()
    opt_parser = optparse.OptionParser(
        '%prog [GLOBAL-OPTIONS] cone [--row-count=ROWS]',
        description=_("Generate a crochet pattern for a cone."))
    opt_parser.add_option(
        '-r',
        '--row-count',
        action='store',
        type='int',
        default=16,
        metavar='ROWS',
        help=_('the number of rows in the pattern. Defines the height'
               ' of the cone [%default]'))
    opt_parser.add_option(
        '-c',
        '--max-circumference',
        action='store',
        type='int',
        default=60,
        metavar='STITCHES',
        help=_('the number of stitches at the base of the pattern. Defines the'
               ' circumference of the base of the cone [%default]'))
    command_opts, __ = opt_parser.parse_args(argv)
    stitches = cone(command_opts.row_count, command_opts.max_circumference)
    stitches = snap(stitches, 1 if global_options.accurate else 6, 6)
    if not global_options.inhuman:
        title = _("Cone (%d rows, %d max-circumference)") % (
            command_opts.row_count, command_opts.max_circumference)
        print_instructions_txt(title, stitches)
    else:
        print_row_counts(stitches)
예제 #4
0
def main(argv, global_options):
    """
    Command entry-point for the donut pattern-generator.
    """
    _ = localization.get_translation()
    opt_parser = optparse.OptionParser(
        '%prog [GLOBAL-OPTIONS] '
        'donut [--inner-radius=STITCHES] [--row-count=ROWS]',
        description=_("""
Generate a pattern for a donut (torus).

The pattern starts off with a row in the centre (the donut hole) and is
crocheted up and around.
""").strip())
    opt_parser.add_option(
        '-i',
        '--inner-radius',
        action='store',
        type='int',
        default=18,
        metavar='STITCHES',
        help=_('the circumference of the donut hole, in stitches [%default]'))
    opt_parser.add_option(
        '-r',
        '--row-count',
        action='store',
        type='int',
        default=16,
        metavar='ROWS',
        help=_("the number of rows in the pattern - defines the 'thickness'"
               " of the donut [%default]"))
    command_opts, __ = opt_parser.parse_args(argv)
    stitches = donut(command_opts.inner_radius, command_opts.row_count)
    stitches = snap(stitches, 1 if global_options.accurate else 6)

    if not global_options.inhuman:
        title = _("Donut (inner-radius: %d, %d rows)") % (
            command_opts.inner_radius, command_opts.row_count)
        print_instructions_txt(title, stitches)
    else:
        print_row_counts(stitches)
예제 #5
0
def main(argv, global_options):
    """ Command entry-point for the ball pattern-generator. """
    _ = localization.get_translation()
    opt_parser = optparse.OptionParser(
        '%prog [GLOBAL-OPTIONS] ball [--row-count=ROWS]',
        description=_("""
Generate a crochet pattern for a ball (sphere).
""").strip())
    opt_parser.add_option('-r', '--row-count', action='store',
        type='int', default=16, metavar='ROWS',
        help=_('the number of rows in the pattern. Defines the size'
        ' of the ball - the circumference is 2x this value. [%default]'))
    command_opts, __ = opt_parser.parse_args(argv)
    stitches = ball(command_opts.row_count)
    stitches = snap(stitches, 1 if global_options.accurate else 6, 6)

    if not global_options.inhuman:
        title = _("Ball (%d rows)") % (command_opts.row_count)
        print_instructions_txt(title, stitches)
    else:
        print_row_counts(stitches)
예제 #6
0
import gettext
import locale

class NullHandler(logging.Handler):
    """
    A Handler that does nothing. Prevents error messages if crocad is used
    as a library and logging is not configured.
    """
    def emit(self, record):
        """Do nothing."""
        pass
logging.getLogger('crocad').addHandler(NullHandler())


from crocad import localization
_ = localization.get_translation()
from crocad import donut, ball, cone

__all__ = ['main']


LOG = logging.getLogger('crocad')


COMMAND_ALIASES = {
    'torus': 'donut',
    'sphere': 'ball',
}


def find_command(command):
예제 #7
0
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""
crocad.donut - donut crochet pattern generation for crochet-cad.
"""

from crocad import localization
_ = localization.get_translation()

import logging
from math import pi, cos
import optparse

from crocad.util import round_to_nearest_iter as snap
from crocad.util import print_instructions_txt, print_row_counts

__all__ = ['donut']
NAMES = ['donut', 'torus']
LOG = logging.getLogger('crocad.donut')


def donut(init_stitches, rows, initial_angle=0):
    """