A programming language that for tech savvy graphic designers

Related tags

Miscellaneous PhoTex
Overview

Microsoft Hackathon - PhoTex

Idea

A programming language that allows tech savvy graphic designers develop scalable vector graphics using plain text code. The designer can create a canvas and declare various elements that are to be rendered on that canvas. They can also define and name custom fonts, colors, and complex objects that can be reused in their project.

A video we made about the project containing more information and a coding tutorial: https://www.youtube.com/watch?v=-G7Mk0YNnjw

The designer’s code (stored in a .ptex file) is interpretted by PhoTeX and an SVG representation of their design is generated. The resulting image can be outputted in many common image file formats.

Inspiration

There does not exist a good universal text-based tool for creating general purpose vector and raster graphics. Almost all existing tools are GUI-based visual editors and thus have several limitations that could be overcome by using a WYSIWYM approach. For example, in GUI-based tools like Photoshop and Illustrator, it can be a lot of work to bring in assets you have created for other projects that you wish to name, reuse, and customize.

We were inspired by visualization and formatting tools such as LaTeX, Graphviz, Markdown and ORG. Our goal is to build a similar style tool, but with less steep of a learning curve. It will be purpose built to create highly customizable graphics that export to any format. Moreover, we want to build a system that automates some aspects of graphic design that Photoshop and other visual tools cannot.

How It Works

We decided to break the problem into two parts, the parser and the exporter. The parser will read in the plain text .ptex file into an abstract syntax tree and check the semantics of the user’s program. This approach will allow us to deliver the user meaninful error messages in the cases of synactic and semantic errors. If the parser doesn’t find any semantic or syntax errors it will pass a compiled hierarchy of graphical elements (shapes, images, text, etc.) to the exporter. The exporter will convert the parse tree into a set of hierarchically grouped primitive objects which can then be easily be converted to SVG format. Lastly, the exporter will convert the resulting svg into the final file output type (.png, .jpg, .svg, etc).

We are currently using the Lark parser (https://github.com/lark-parser/lark). Lark is an open-source python library that enables us to build our abstract syntax trees based on an EBNF-like context-free grammar. To assist in building and exporting SVG files, we are using SVGLib (https://github.com/deeplook/svglib).

Getting Started

  1. If you haven’t already, install Python 3.x.x (https://www.python.org/)
  2. Open a terminal window and navigate to the project root
  3. [Optional] Create a new virtual environment
  4. Run pip -r requirements.txt in the terminal to acquire all pip dependencies
  5. Navigate to the src folder
  6. Create a .ptex file and write your code!
  7. Build your code by running python photex.py [YOUR_FILE_NAME].ptex
  8. If there were no errors, your output files should be located in the same folder as your code
Comments
  • Canvas-level rendering of lines is wrong

    Canvas-level rendering of lines is wrong

    The following code generates the image provided below it. The coordinates passed into the line via PhoTeX are not having their coordinate system properly converted before being passed into svg.

    define color blue #0000FF
    define font arial "Arial" 12
    
    canvas "Test.png" 300 300 {
        line -50w 0 50w 0 blue 3
    }
    

    Test

    bug 
    opened by JoeFurfaro 2
  • Clip! Clip! Clip!

    Clip! Clip! Clip!

    Changes In This Clippy Update

    Proper Clipping

    Fixed clipping for:

    • Rect
    • Circle
    • Ellipse
    • Polygon Performed basic tests for these, but did not try any crazy edge cases. You can make a clipped object by doing this:
    clipped rect 0 0 300 300 { ... } // All items inside ... that overflow the rect boundaries will be cut off
    

    [New feature] Inner and Outer Clipping

    I felt there was a need for two types of clipping when clipping an outlined object. This is due to the fact that you can either clip inside the stroke or outside the stroke and obtain a completely different effect. I explain the two types below with examples.

    Inner Clipping

    One can "inner clip", or clip inside the stroke by writing code like the following:

    clipped in outlined #FF0000 10 rect 0 0 300 300 {
            image 0 0 500 500 "scor.jpg"
    }
    
    // OR just
    
    clipped outlined #FF0000 10 rect 0 0 300 300 {
            image 0 0 500 500 "scor.jpg"
    }
    

    Yielding something like: Test

    Inner Clipping

    One can "outer clip", or clip outside the stroke by writing code like the following:

    clipped out outlined #FF0000 10 rect 0 0 300 300 {
            image 0 0 500 500 "scor.jpg"
    }
    

    Yielding something more like this: Test

    An Important Note

    Both inner and outer clipping work perfectly for circles, rectangles, and ellipses. But for custom polygons, clipping can be quite difficult, so as of now, only inner clipping is supported. I hope to work on this again in the future to add outer clipping for custom polygons.

    enhancement 
    opened by JoeFurfaro 1
  • Ignore WS_INLINE

    Ignore WS_INLINE

    @JoeFurfaro It seems to work. I think we should use this as it simplifies the lark code and makes it much more flexible in terms of allowing whitespace.

    opened by Daniel-Genkin 1
  • Fixes To Canvas Coordinates Issues

    Fixes To Canvas Coordinates Issues

    Some Stuff I Fixed

    • Top level placement of polygons (#5)
    • Top level placement of lines (#4)
    • Image primitive scaling and placement (#2)

    Issue(s) That Still Need To Be Fixed

    (At some point)

    • Some placements of lines / polygons are still weird in PNG export, but all placements seem perfect for SVG preview in VS code and in browser
    • I will make a new issue for the above point soon ^
    opened by JoeFurfaro 0
  • Canvas-level rendering for polygon's is wrong

    Canvas-level rendering for polygon's is wrong

    When trying to build a simple triangle with this code:

    define color blue #0000FF
    
    canvas "Test.png" 300 300 {
        polygon -50w 50h 0 -50h 50w 50h blue
    }
    

    I get this output: Test

    This has to do with no parent element translating the points in the polygon

    Note if I place the polygon inside of a rect that is the same size as the canvas, I get the following output

    Test

    (with this code)

    define color blue #0000FF
    
    canvas "Test.png" 300 300 {
        rect 0 0 100w 100h {
            polygon -50w 50h 0 -50h 50w 50h blue
        }
    }
    
    bug 
    opened by JoeFurfaro 0
  • Requirements

    Requirements

    Modifications

    • Updated requirements.txt to contain all dependencies
    • Created a conda environment that contains all dependencies
    • Exported photex conda environment to environment.yml in project root
    • Added install instructions for conda environment to README.org Getting Started section

    Reasons for Changes

    • Faster quickstart for virtual environment users
    • Clearer "Getting Started" instructions
    • Requirements file was out of date
    hacktoberfest-accepted 
    opened by JoeFurfaro 0
  • Images render with their top left at the given location

    Images render with their top left at the given location

    I think it should be their center. Here is an example:

    image

    From this code: canvas "Test.png" 1000 1000 { image 0 0 200 "scor.jpg" }

    Svg is: <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1000" height="1000"> <image x="500" y="500" width="200" height="104.16666666666667" href="scor.jpg" /> </svg>

    bug 
    opened by JoeFurfaro 0
  • Add JPEG/JPG export support

    Add JPEG/JPG export support

    Currently we only export to SVG and/or PNG. Let's add JPG/JPEG as well. According to Joe, this can probably be done via the already added Pillow library.

    enhancement 
    opened by Daniel-Genkin 0
  • Idea: Usings/imports

    Idea: Usings/imports

    I just realized that implementing the proposed usings/imports is actually quite trivial! We can do something similar to how C++ handles header files. We can copy the import into the file we are processing at the location of the import statement.

    Proposed changes

    Add another pass over the input file before the main pass. This pass will simply replace all lines that start are in the form of using [relative path to file] with the contents of the file at the path location. Then we can run through and do the main parsing.

    @JoeFurfaro what are your thoughts about this?

    enhancement 
    opened by Daniel-Genkin 5
  • Can't Export to Multiple File Types

    Can't Export to Multiple File Types

    The Problem

    What if I want an SVG, PNG, and JPG export of my canvas?! I shouldn't have to write the canvas definition 3 times!!!

    The Solution

    Modify canvas definitions to support multiple file type arguments after the name... eg:

    canvas MyCanvas svg 500 500 {
        ...
    }
    

    OR

    canvas MyOtherCanvas svg png jpg 500 500 {
        ...
    }
    enhancement 
    opened by JoeFurfaro 0
  • [Work In Progress] Constants.py

    [Work In Progress] Constants.py

    Idea

    The goal is to automatically generate a Constants.py file from our Lark grammar file. This will help to minimize hardcoded and magic values throughout the interpretter.

    What's changed

    • There is a new Constants.py file that contains the constants expressed in the global lark grammar file.
      • This file can be regenerated by running python3 ConstantsBuilder.py from the src/classes/parser folder
    • There is a new file that parses the grammar for the hardcoded values and extracts them into Constants.py

    Why

    • To make life easier by removing hardcoded values (less mistakes as things change as well as convenience as you need to remember less magic values to make changes)
    • To add flexibility and freedom to change and experiment more easily
    • Also acts as documentation as types and other things can be added later

    TODO

    • [x] Basic functionality
    • [x] Apply to all files. Currently only photex.py uses the constants.py file
    • [x] Add alias extraction
    • [x] Test it
    • [ ] Cleanup code (currently it is quite ugly
    documentation enhancement 
    opened by Daniel-Genkin 2
  • cairo lib installation over pip3 fails on MacOS

    cairo lib installation over pip3 fails on MacOS

    I ran pip3 install -r requirements.txt but kept getting the following error

    OSError: no library called "cairo-2" was found
    no library called "cairo" was found
    no library called "libcairo-2" was found
    cannot load library 'libcairo.so.2': dlopen(libcairo.so.2, 2): image not found
    cannot load library 'libcairo.2.dylib': dlopen(libcairo.2.dylib, 2): image not found
    cannot load library 'libcairo-2.dll': dlopen(libcairo-2.dll, 2): image not found
    

    I think we need to clarify in the readme the troubleshooting steps for those who get this (and other) installation issues

    documentation 
    opened by Daniel-Genkin 1
Owner
Joe Furfaro
AGV Software Developer @ Martinrea | Lead Developer @ eatDipole
Joe Furfaro
Rick Astley Language is a rick roll oriented, dynamic, strong, esoteric programming language.

Rick Roll Language / Rick Astley Language A rick roll oriented, dynamic, strong, esoteric programming language. Prolegomenon The reasons that I made t

Rick Roll Programming Language 658 Jan 9, 2023
PyGo custom language, New but similar language programming

New but similar language programming. Now we are capable to program in a very similar language to Python but at the same time get the efficiency of Go.

Fernando Perez 4 Nov 19, 2022
A collection of online resources to help you on your Tech journey.

Everything Tech Resources & Projects About The Project Coming from an engineering background and looking to up skill yourself on a new field can be di

Mohamed A 396 Dec 31, 2022
Calibre Libgen Non-fiction / Sci-tech store plugin

CalibreLibgenSci A Libgen Non-Fiction/Sci-tech store plugin for Calibre Installation Download the latest zip file release from here Open Calibre Navig

IDDQD 9 Dec 27, 2022
Short, introductory guide for the Python programming language

100 Page Python Intro This book is a short, introductory guide for the Python programming language.

Sundeep Agarwal 185 Dec 26, 2022
sawa (ꦱꦮ) is an open source programming language, an interpreter to be precise, where you can write python code using javanese character.

ꦱꦮ sawa (ꦱꦮ) is an open source programming language, an interpreter to be precise, where you can write python code using javanese character. sawa iku

Rony Lantip 307 Jan 7, 2023
The Zig programming language, packaged for PyPI

Zig PyPI distribution This repository contains the script used to repackage the releases of the Zig programming language as Python binary wheels. This

Zig Programming Language 100 Nov 4, 2022
The Official interpreter for the Pix programming language.

The official interpreter for the Pix programming language. Pix Pix is a programming language dedicated to readable syntax and usability Q) Is Pix the

Pix 6 Sep 25, 2022
A topology optimization framework written in Taichi programming language, which is embedded in Python.

Taichi TopOpt (Under Active Development) Intro A topology optimization framework written in Taichi programming language, which is embedded in Python.

Li Zhehao 41 Nov 17, 2022
An esoteric programming language that supports concurrency, regex, and web requests.

The Hofstadter Esoteric Programming Language Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's La

Austin Henley 19 Dec 27, 2022
Built with Python programming language and QT library and Guess the number in three easy, medium and hard rolls

guess-the-numbers Built with Python programming language and QT library and Guess the number in three easy, medium and hard rolls Number guessing game

Amir Hussein Sharifnezhad 5 Oct 9, 2021
Built with Python programming language and QT library and Guess the number in three easy, medium and hard rolls

password-generator Built with Python programming language and QT library and Guess the number in three easy, medium and hard rolls Password generator

Amir Hussein Sharifnezhad 3 Oct 9, 2021
🚀 emojimash 🚀 is a programming language with ALL THE EMOJI

?? emojimash ?? is a programming language with ALL THE EMOJI

Python Whiz 256 1 Oct 26, 2021
Nook is a simple, concatenative programming language written in Python.

Nook Nook is a simple, concatenative programming language written in Python. Status Nook is currently WIP. It lacks a lot of basic feature, and will n

Wumi4 4 Jul 20, 2022
Python most simple|stupid programming language (MSPL)

Most Simple|Stupid Programming language. (MSPL) Stack - Based programming language "written in Python" Features: Interpretate code (Run). Generate gra

Kirill Zhosul 14 Nov 3, 2022
a simple functional programming language compiler written in python

Functional Programming Language A compiler for my small functional language. Written in python with SLY lexer/parser generator library. Requirements p

Ashkan Laei 3 Nov 5, 2021
Sodium is a general purpose programming language which is instruction-oriented

Sodium is a general purpose programming language which is instruction-oriented (a new programming concept that we are developing and devising)

Satin Wuker 22 Jan 11, 2022
Plock : A stack based programming language

Plock : A stack based programming language

null 1 Oct 25, 2021
Eros is an expiremental programming language built using simple Python code.

Eros is an expiremental programming language built using simple Python code. Featuring an easy syntax and unique features like type slicing, the language remains an expirement that grows in down time.

zxro 2 Nov 21, 2021