Code Monkey home page Code Monkey logo

Comments (7)

Ben-Hampson avatar Ben-Hampson commented on August 22, 2024

I'll work on this!

from pyknit.

Ben-Hampson avatar Ben-Hampson commented on August 22, 2024

It was indeed a font problem. I went for Courier New as that seems to be a good and universal monospace font. Here's the code I have so far for Chart.py:

# draw symbol for each cell
    fnt = ImageFont.truetype("Courier New.ttf", 40)
    for i, stitch in enumerate(stitch_array):
        draw.text(
            ((cell_width + 1) * i, 3), stitch, font=fnt, fill=(255, 255, 255, 255)
        )
    return chart_image

I tested it with this code:

pattern = "k1 p4 k1 p4 k kfb r ssk k2tog"
legend = {
        "k": " ",
        "p": ".",
        "kfb": "\\/",
        "ssk": "\\",
        "k2tog": "k2tog",
        "r": "r"
    }

pattern_parsed = pyknit.parse_written(pattern, legend)
print(pattern_parsed)

pattern_printed = pyknit.print_chart(pattern_parsed)
pattern_printed.show()

and it produced this image:
tmpnqe4m1zy

I don't know how knitting patterns should look so I could do with some pointers here.

  1. I presume you intentionally want it to print \/ and not \/? Is that correct?
  2. k2tog doesn't fit in the box at the moment. What would you like to do with that?

An example of input and desired output of print_chart would help me here. Thanks.

from pyknit.

terriko avatar terriko commented on August 22, 2024

In a typical knitting chart, stitch symbols are a width that indicates either the starting or final size of the stitch. There's some sort of unspoken conventions about which ones are which, and I'm not sure I could articulate it (and different designers may prefer different things, hence why I'm starting with a legend rather than assuming a standard set of symbols)

  1. kfb is "knit front and back" and it takes a single stitch and turns it into two stitches. I've seen it represented a few ways and I was experimenting with how it worked. Probably the easiest thing to do for now is replace it in the legend with a V (looks like one stitch at the bottom and two at the top that way, and takes up one space). I have seen it listed as a two-space symbol too.
  2. k2tog is "knit two together" and normally would be represented as / (I probably had not set this because I was experimenting with what would happen if my symbol was too large). It's a decrease stitch (take two stitches, turn them into one) but because people find it easier to "read" what it looks like on the final knitting, it's basically always represented as a single-wide symbol.

So this chart would likely be supposed to look something like...

.... .... Vr\/

Which is kind of a nonsense chart by itself, but could make sense as part of a longer pattern.

from pyknit.

terriko avatar terriko commented on August 22, 2024

My first try used standard keyboard symbols, but if you want to take a look at some more standard symbols, here's the list from the crafts americana website: https://www.craftyarncouncil.com/standards/knit-chart-symbols

Note that they use V to represent "slip stitch" and don't have an explicit kfb symbol, but it would likely be a v with a 2 over it, showing that you're increasing to two stitches.

I'm not sure what the best way to handle these in pyKnit is yet -- there are knitting symbol fonts but I didn't see one that looked like it had a license for redistribution with pyKnit, so we might want to import images/svg or draw them ourselves and find a way to specify 'use built-in symbol" in the legend.

from pyknit.

terriko avatar terriko commented on August 22, 2024

And also, this is looking great. Even if we only use standard font symbols to start, that can get you a pretty large range of patterns into a state where we can chart them!

from pyknit.

terriko avatar terriko commented on August 22, 2024

A thought: we are going to eventually want to make symbols that are more than one unit wide. We'll probably want the legend to have 3 parts, then: written instruction, symbol, width (possibly as start size/end size for calculating). It might be time to turn legend into some sort of more explicitly defined datatype.

from pyknit.

terriko avatar terriko commented on August 22, 2024

Closed thanks to @Ben-Hampson ! I'm going to open a new issue for improving our default stitch dictionary.

from pyknit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.