CartesianDaemon/pylogram
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
pylogram ======== A very simple declarative linear equation solver and drawing package. A reimplementation of Mark Dominus' linogram, described in: Several blog posts (reverse order) at http://blog.plover.com/linogram/ Source code on github at https://github.com/mjdominus/Linogram Originally developed in the book Higher Order Perl (http://hop.perl.plover.com/book/) In most programming languages you can't assign to expressions: 2+3=x doesn't work. But if x is a pylogram Var x becomes equal to 2+3, unless that conflicts with a previous expression, in which case a Contradiction exception is thrown. An example of use to solve a set of linear equations would be: from pylogram import constrain, default_vars as vars constrain( vars.a + vars.b == 2 , 2*vars.a + vars.b/3 == -7 ) print( "a , b =", vars.a, ",", vars.b ) Which gives output: >> -23/5 , 33/5 An example of geometric drawing would be: from pylogram_draw import * class Lollypop(Primitive): def __init__(self): self.stick = Line('stick') self.circ = Circle('ball') self.circ.bottom = self.stick.pt1 self.stick.pt1.x = self.stick.pt2.x line_height = self.stick.pt2.y - self.stick.pt1.y line_height [:]= self.circ.d * 2 self.bottom = self.stick.pt2 self.height = line_height + self.circ.d lollypop = Lollypop() lollypop.bottom = Point(1,0) lollypop.height = 6 assert lollypop.circ.c == Point(1,-5) lollypop.sim_draw() Which gives output: >> Drawing circle about 1,-5 with radius >> Drawing line from 1,-4 to 1,0 For a linear equation from a riddle 1800 years old, see example_diophantus.py For a slightly longer drawing example including displaying to screen, see example_lollypop.py
About
No description, website, or topics provided.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published