Compare commits
23 Commits
e5b6019606
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| c51efebf95 | |||
| ea1ac6490a | |||
| 3d681da551 | |||
| 5864dc5c06 | |||
| a152af6bac | |||
| 121b8fe4b0 | |||
| 1cd4e0fdc6 | |||
| a48457de29 | |||
| 4a6d2a1758 | |||
| 29355191d6 | |||
| 7e44418829 | |||
| fd61a4620f | |||
| 0070094b94 | |||
| 37f8d181c2 | |||
| 5384d9a964 | |||
| ff11c1ce84 | |||
| 0a8a0e3c53 | |||
| b1d56fea04 | |||
| 955aa8f10a | |||
| 3b3053fc3a | |||
| 5e425be098 | |||
| dc4aef2119 | |||
| 2c2b88a6c6 |
202
LICENSE
Normal file
202
LICENSE
Normal file
@@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
77
README.md
Normal file
77
README.md
Normal file
@@ -0,0 +1,77 @@
|
||||
Jam is visualization software for hard-core lattice particle systems. It is
|
||||
designed to explore configurations of particles while enforcing that no two
|
||||
particles overlap.
|
||||
|
||||
**Jam is a work in progress and is nowhere near ready for production.**
|
||||
|
||||
|
||||
# Basic usage
|
||||
|
||||
Run with
|
||||
```bash
|
||||
./src/jam [configuration_file] [-L lattice]
|
||||
```
|
||||
|
||||
* `[configuration_file]` is an optional argument that specifies a file with
|
||||
a list of particle positions that will be loaded on initial execution.
|
||||
|
||||
* `[-L lattice]` is an optional argument that specifies a background grid that
|
||||
constrains the position of the particles. So far, the `lattice` argument must
|
||||
be `square` for the square lattice, or, to specify the unit length of the
|
||||
lattice: `square:<unit_length>`.
|
||||
|
||||
|
||||
|
||||
# Dependencies
|
||||
|
||||
Jam is written in Python 3, and uses Kivy to run the GUI.
|
||||
|
||||
|
||||
# User interface
|
||||
|
||||
* `<right-click>`: create a new particle under the mouse pointer (if the
|
||||
particle fits)
|
||||
|
||||
* `<shift><left-click>`: select/unselect multiple particles
|
||||
|
||||
* `<left-click>` and drag: move selected particle(s).
|
||||
|
||||
* `backspace`: delete selected particle(s)
|
||||
|
||||
|
||||
# Commands
|
||||
|
||||
Commands can be executed by typing `:` (similarly to vim).
|
||||
|
||||
* `:q`: exit
|
||||
|
||||
* `:w [path_to_file]`: Write particle configuration to file. This will not
|
||||
overwrite existing files; use `:w!` to overwrite.
|
||||
|
||||
* `:e <path_to_file>`: edit file.
|
||||
|
||||
* `:export <path_to_file>`: Export configuration to LaTeX (using TikZ)
|
||||
|
||||
* `:set color <color_spec>`: Set color of selected particles to
|
||||
`<color_spec>`. The supported format for `<color_spec>` is either `r,g,b`
|
||||
with `r`, `g`, and `b` in [0,1], or one of
|
||||
`red|green|blue|brown|lime|orange|pink|purple|teal|violet|cyan|magenta|yellow|olive|black|darkgray|gray|lightgray|white`.
|
||||
|
||||
* `:set zoom <zoom_level>`: Scale all particles by `<zoom_level>`.
|
||||
|
||||
* `:set grid [on|off]`: Add a visual grid centered on one of the selected
|
||||
particles. The size of the mesh can be specified by passing
|
||||
`:set grid <size_of_mesh>`.
|
||||
|
||||
|
||||
# Current developments
|
||||
|
||||
So far, Jam supports particles made of combinations of rectangles, but there is
|
||||
no infrastructure to set the shape of the particle at runtime.
|
||||
|
||||
|
||||
# License
|
||||
|
||||
Jam is distributed under the Apache 2.0 License.
|
||||
|
||||
Copyright 2021-2023 Ian Jauslin
|
||||
32
TeX/jam.sty
32
TeX/jam.sty
@@ -1,3 +1,17 @@
|
||||
% Copyright 2021-2023 Ian Jauslin
|
||||
%
|
||||
% Licensed under the Apache License, Version 2.0 (the "License");
|
||||
% you may not use this file except in compliance with the License.
|
||||
% You may obtain a copy of the License at
|
||||
%
|
||||
% http://www.apache.org/licenses/LICENSE-2.0
|
||||
%
|
||||
% Unless required by applicable law or agreed to in writing, software
|
||||
% distributed under the License is distributed on an "AS IS" BASIS,
|
||||
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
% See the License for the specific language governing permissions and
|
||||
% limitations under the License.
|
||||
|
||||
% square lattice (width #1, height #2, origin #3, spacing #4)
|
||||
\def\grid#1#2#3{
|
||||
\foreach\i in {0,...,#2}{
|
||||
@@ -14,3 +28,21 @@
|
||||
\fill[color=#1]#2++(0.5,0.5)--++(0,1)--++(-1,0)--++(0,-1)--++(-1,0)--++(0,-1)--++(1,0)--++(0,-1)--++(1,0)--++(0,1)--++(1,0)--++(0,1)--++(-1,0);
|
||||
\draw[color=black]#2++(0.5,0.5)--++(0,1)--++(-1,0)--++(0,-1)--++(-1,0)--++(0,-1)--++(1,0)--++(0,-1)--++(1,0)--++(0,1)--++(1,0)--++(0,1)--++(-1,0);
|
||||
}
|
||||
|
||||
% 3-staircase (color #1, position #2)
|
||||
\def\staircase#1#2{
|
||||
\fill[color=#1]#2++(-0.5,-0.5)--++(3,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,-3);
|
||||
\draw[color=black]#2++(-0.5,-0.5)--++(3,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,1)--++(-1,0)--++(0,-3);
|
||||
}
|
||||
|
||||
% disk (color #1, position #2)
|
||||
\def\disk#1#2{
|
||||
\fill[color=#1]#2circle(2.5);
|
||||
\draw[color=black]#2circle(2.5);
|
||||
}
|
||||
|
||||
% square (color #1, position #2)
|
||||
\def\square#1#2{
|
||||
\fill[color=#1]#2++(-1,-1)--++(0,2)--++(2,0)--++(0,-2)--cycle;
|
||||
\draw[color=black]#2++(-1,-1)--++(0,2)--++(2,0)--++(0,-2)--cycle;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
# Copyright 2021-2023 Ian Jauslin
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# find named color that is closest to rgb values
|
||||
def closest_color(rgb,names):
|
||||
name=""
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
# Copyright 2021-2023 Ian Jauslin
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from kivy.uix.label import Label
|
||||
from kivy.core.window import Window
|
||||
from kivy.graphics import Color,Rectangle
|
||||
@@ -6,6 +20,7 @@ import os.path
|
||||
|
||||
import filecheck
|
||||
import colors
|
||||
from polyomino import Cross,Disk,Staircase,Square2
|
||||
|
||||
class Command_prompt(Label):
|
||||
|
||||
@@ -324,9 +339,15 @@ class Command_prompt(Label):
|
||||
if argv[1]=="color":
|
||||
self.run_set_color(argv)
|
||||
return
|
||||
elif argv[1]=="shape":
|
||||
self.run_set_shape(argv)
|
||||
return
|
||||
elif argv[1]=="grid":
|
||||
self.run_set_grid(argv)
|
||||
return
|
||||
elif argv[1]=="voronoi":
|
||||
self.run_set_voronoi(argv)
|
||||
return
|
||||
elif argv[1]=="zoom":
|
||||
self.run_set_zoom(argv)
|
||||
else:
|
||||
@@ -336,7 +357,7 @@ class Command_prompt(Label):
|
||||
# set color
|
||||
def run_set_color(self,argv):
|
||||
if len(argv)<3:
|
||||
self.message="error: 'set color' command was run with without anargument -- usage: 'set color <color_descriptor>'"
|
||||
self.message="error: 'set color' command was run with without an argument -- usage: 'set color <color_descriptor>'"
|
||||
return
|
||||
# find color name in list
|
||||
for color in colors.xcolor_names:
|
||||
@@ -358,6 +379,23 @@ class Command_prompt(Label):
|
||||
return
|
||||
self.app.painter.set_color(color)
|
||||
|
||||
# set particle shape
|
||||
def run_set_shape(self,argv):
|
||||
if len(argv)<3:
|
||||
self.message="error: 'set shape' command was run with without an argument -- usage: 'set shape <shape_descriptor>'"
|
||||
return
|
||||
elif argv[2]=="cross":
|
||||
self.app.painter.shape=Cross
|
||||
elif argv[2]=="disk":
|
||||
self.app.painter.shape=Disk
|
||||
elif argv[2]=="staircase":
|
||||
self.app.painter.shape=Staircase
|
||||
elif argv[2]=="2square":
|
||||
self.app.painter.shape=Square2
|
||||
else:
|
||||
self.message="error: unrecognized shape '"+argv[2]+"'; supported shapes are cross|disk|staircase|2square"
|
||||
return
|
||||
|
||||
# toggle grid
|
||||
def run_set_grid(self,argv):
|
||||
if len(argv)==2:
|
||||
@@ -378,6 +416,19 @@ class Command_prompt(Label):
|
||||
return
|
||||
self.app.painter.set_grid(mesh)
|
||||
|
||||
# toggle Voronoi cells
|
||||
def run_set_voronoi(self,argv):
|
||||
if len(argv)==2:
|
||||
# no argument: set to toggle
|
||||
self.app.painter.set_voronoi(-1)
|
||||
elif argv[2]=="on":
|
||||
self.app.painter.set_voronoi(1)
|
||||
elif argv[2]=="off":
|
||||
self.app.painter.set_voronoi(0)
|
||||
else:
|
||||
self.message="error: unrecognized argument '"+argv[2]+"' -- usage 'set voronoi [on|off]'"
|
||||
return
|
||||
|
||||
# set zoom level (changes size of elements)
|
||||
def run_set_zoom(self,argv):
|
||||
if len(argv)==2:
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
# Copyright 2021-2023 Ian Jauslin
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
## elements that polyominoes are made of
|
||||
import math
|
||||
import sys
|
||||
@@ -81,8 +95,20 @@ class Element_square(Element):
|
||||
*(coordx-0.5*self.size*painter.base_size,coordy-0.5*self.size*self.aspect*painter.base_size)
|
||||
))
|
||||
|
||||
# for use with lattices
|
||||
# list of lattice points covered by square
|
||||
def lattice_points(self,lattice):
|
||||
out=[]
|
||||
dx=math.floor(0.5*self.size/lattice.spacing)
|
||||
dy=math.floor(0.5*self.size*self.aspect/lattice.spacing)
|
||||
for i in range(-dx,dx+1):
|
||||
for j in range(-dy,dy+1):
|
||||
out.append(Point(self.pos.x+i*lattice.spacing,self.pos.y+j*lattice.spacing))
|
||||
return out
|
||||
|
||||
|
||||
# check whether an element interacts with square
|
||||
# TODO: this only works if element is a square!
|
||||
# TODO: this only works if element is a rectangle!
|
||||
def check_interaction(self,element):
|
||||
# allow for error
|
||||
return max(abs(element.pos.x-self.pos.x)/(self.size+element.size),abs(element.pos.y-self.pos.y)/(self.size*self.aspect+element.size*element.aspect))<1/2-1e-11
|
||||
@@ -92,7 +118,7 @@ class Element_square(Element):
|
||||
return max(abs(self.pos.x-x.x),abs(self.pos.y-x.y)/self.aspect)<=1/2
|
||||
|
||||
# check whether an element is touching self
|
||||
# TODO: this only works if element is a square!
|
||||
# TODO: this only works if element is a rectangle!
|
||||
def check_touch(self,element):
|
||||
# allow for error
|
||||
if in_interval(max(abs(element.pos.x-self.pos.x)/(self.size+element.size),abs(element.pos.y-self.pos.y)/(self.size*self.aspect+element.size*element.aspect)),1/2-1e-11,1/2+1e-11):
|
||||
@@ -100,7 +126,7 @@ class Element_square(Element):
|
||||
return False
|
||||
|
||||
# find position along a line that comes in contact with the line going through element.pos in direction v
|
||||
# TODO: this only works if element is a square!
|
||||
# TODO: this only works if element is a rectangle!
|
||||
def move_on_line_to_stick(self,element,v):
|
||||
size_x=(self.size+element.size)/2
|
||||
size_y=(self.size*self.aspect+element.size*element.aspect)/2
|
||||
@@ -146,7 +172,7 @@ class Element_square(Element):
|
||||
return closest-element.pos
|
||||
|
||||
# move along edge of square
|
||||
# TODO: this only works if element is a square!
|
||||
# TODO: this only works if element is a rectangle!
|
||||
def move_along(self,delta,element):
|
||||
size_x=(self.size+element.size)/2
|
||||
size_y=(self.size*self.aspect+element.size*element.aspect)/2
|
||||
@@ -256,3 +282,16 @@ class Element_circle(Element):
|
||||
def move_along(self,delta,element):
|
||||
x=element.pos-self.pos+delta
|
||||
return x/l_2(x)*(element.size+self.size)/2+self.pos-element.pos
|
||||
|
||||
# for use with lattices
|
||||
# list of lattice points covered by square
|
||||
def lattice_points(self,lattice):
|
||||
out=[]
|
||||
dx=math.floor(0.5*self.size/lattice.spacing)
|
||||
for i in range(-dx,dx+1):
|
||||
for j in range(-dx,dx+1):
|
||||
if lattice.spacing*lattice.spacing*(i*i+j*j)<=self.size*self.size/4:
|
||||
out.append(Point(self.pos.x+i*lattice.spacing,self.pos.y+j*lattice.spacing))
|
||||
return out
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
# Copyright 2021-2023 Ian Jauslin
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# check that a file is creatable/writable/editable
|
||||
|
||||
import os.path
|
||||
|
||||
63
src/jam
63
src/jam
@@ -1,5 +1,19 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright 2021-2023 Ian Jauslin
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import sys
|
||||
import os.path,os
|
||||
import filecheck
|
||||
@@ -26,6 +40,10 @@ def read_cli():
|
||||
# lattice
|
||||
if c=='L':
|
||||
flag="lattice"
|
||||
else:
|
||||
print("error: unrecognized option '"+c+"'\n", file=sys.stderr)
|
||||
exit(-1)
|
||||
|
||||
|
||||
else:
|
||||
# read lattice argument
|
||||
@@ -46,6 +64,51 @@ def read_cli():
|
||||
if ret<0:
|
||||
print(message,file=sys.stderr)
|
||||
exit(-1)
|
||||
preread_conf(openfile)
|
||||
|
||||
# read command line arguments from configuration file
|
||||
def preread_conf(file):
|
||||
global lattice
|
||||
try:
|
||||
ff=open(file,"r")
|
||||
except:
|
||||
return
|
||||
|
||||
# counter
|
||||
i=0
|
||||
try:
|
||||
lines=ff.readlines()
|
||||
except:
|
||||
print("error: could not read the contents of file '"+file+"'", file=sys.stderr)
|
||||
exit(-1)
|
||||
|
||||
for line in lines:
|
||||
i+=1
|
||||
# remove newline
|
||||
line=line[:len(line)-1]
|
||||
# ignore comments
|
||||
if '#' in line:
|
||||
line=line[:line.find('#')]
|
||||
# ignore empty lines
|
||||
if len(line)==0:
|
||||
continue
|
||||
|
||||
# read options
|
||||
if line[0]=='%':
|
||||
# ignore empty line
|
||||
if len(line)==1:
|
||||
continue
|
||||
[key,val]=line[1:].split('=',1)
|
||||
if key=="lattice":
|
||||
# test the specification
|
||||
(obj,message)=Lattice.new(val)
|
||||
if obj==None:
|
||||
print("error: line "+str(i)+" in file '"+file+"': "+message,file=sys.stderr)
|
||||
exit(-1)
|
||||
lattice=val
|
||||
|
||||
ff.close()
|
||||
|
||||
|
||||
# read cli
|
||||
read_cli()
|
||||
|
||||
14
src/jam.kv
14
src/jam.kv
@@ -1,5 +1,19 @@
|
||||
#: kivy 2.0.0
|
||||
|
||||
# Copyright 2021-2023 Ian Jauslin
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
<Status_bar>:
|
||||
canvas.before:
|
||||
Color:
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
# Copyright 2021-2023 Ian Jauslin
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# define background lattices
|
||||
|
||||
from point import Point
|
||||
@@ -59,4 +73,22 @@ class Lattice_square(Lattice):
|
||||
return (Lattice_square(spacing=spacing),"")
|
||||
except:
|
||||
return (None,"error: '"+spec+"' is not a valid specification for the square lattice: should be 'square[:spacing]'")
|
||||
|
||||
# distance on the lattice between (x1,x2) and (y1,y2)
|
||||
def distance(self, x1, x2, y1, y2):
|
||||
return round((abs(x1-y1)+abs(x2-y2))/self.spacing)
|
||||
|
||||
# distance between a lattice site and a particle
|
||||
def distance_to_particle(self, x1, x2, particle):
|
||||
mindist=self.distance_to_element(x1, x2, particle.elements[0])
|
||||
for i in range(1,len(particle.elements)):
|
||||
mindist=min(self.distance_to_element(x1, x2, particle.elements[i]),mindist)
|
||||
return mindist
|
||||
# distance between a lattice site and an element
|
||||
def distance_to_element(self, x1, x2, element):
|
||||
pts=element.lattice_points(self)
|
||||
mindist=self.distance(x1, x2, pts[0].x, pts[0].y)
|
||||
for i in range(1,len(pts)):
|
||||
mindist=min(self.distance(x1, x2, pts[i].x, pts[i].y),mindist)
|
||||
return mindist
|
||||
|
||||
|
||||
167
src/painter.py
167
src/painter.py
@@ -1,13 +1,27 @@
|
||||
# Copyright 2021-2023 Ian Jauslin
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# main drawing class
|
||||
|
||||
import sys
|
||||
import math
|
||||
from kivy.uix.widget import Widget
|
||||
from kivy.core.window import Window
|
||||
from kivy.graphics import Color,Line
|
||||
from kivy.graphics import Color,Line,Rectangle
|
||||
|
||||
from point import Point
|
||||
from polyomino import Cross,Disk
|
||||
from polyomino import Cross,Disk,Staircase,Square2
|
||||
|
||||
from tools import remove_fromlist
|
||||
|
||||
@@ -21,6 +35,12 @@ class Painter(Widget):
|
||||
# list of particles
|
||||
self.particles=[]
|
||||
|
||||
# shape of particle to add next
|
||||
self.shape=Cross
|
||||
|
||||
# color of particle to add next
|
||||
self.color=(0,0,1)
|
||||
|
||||
# underlying lattice
|
||||
self.lattice=None
|
||||
|
||||
@@ -107,6 +127,12 @@ class Painter(Widget):
|
||||
if particle.grid>0:
|
||||
self.draw_grid(particle.elements[0].pos,particle.grid)
|
||||
|
||||
# draw Voronoi cells
|
||||
if self.lattice!=None:
|
||||
for particle in self.particles:
|
||||
if particle.voronoi>0:
|
||||
self.draw_voronoi(particle)
|
||||
|
||||
for particle in self.particles:
|
||||
particle.draw(self,alpha=0.5)
|
||||
|
||||
@@ -140,6 +166,55 @@ class Painter(Widget):
|
||||
Line(points=(0,self.pos_tocoord_y(yy),self.width,self.pos_tocoord_y(yy)))
|
||||
yy-=mesh
|
||||
|
||||
# draw the discrete Voronoi cell of a particle
|
||||
def draw_voronoi(self,particle):
|
||||
# only works for lattices
|
||||
if self.lattice!=None:
|
||||
pos=particle.elements[0].pos
|
||||
# loop over all points
|
||||
xx=pos.x
|
||||
while self.pos_tocoord_x(xx)<self.width:
|
||||
yy=pos.y
|
||||
while self.pos_tocoord_y(yy)<self.height:
|
||||
self.draw_voronoi_site(xx,yy,particle.color,self.is_in_voronoi(xx,yy,particle))
|
||||
yy+=self.lattice.spacing
|
||||
yy=pos.y-self.lattice.spacing
|
||||
while self.pos_tocoord_y(yy)>0:
|
||||
self.draw_voronoi_site(xx,yy,particle.color,self.is_in_voronoi(xx,yy,particle))
|
||||
yy-=self.lattice.spacing
|
||||
xx+=self.lattice.spacing
|
||||
xx=pos.x-self.lattice.spacing
|
||||
while self.pos_tocoord_x(xx)>0:
|
||||
yy=pos.y
|
||||
while self.pos_tocoord_y(yy)<self.height:
|
||||
self.draw_voronoi_site(xx,yy,particle.color,self.is_in_voronoi(xx,yy,particle))
|
||||
yy+=self.lattice.spacing
|
||||
yy=pos.y-self.lattice.spacing
|
||||
while self.pos_tocoord_y(yy)>0:
|
||||
self.draw_voronoi_site(xx,yy,particle.color,self.is_in_voronoi(xx,yy,particle))
|
||||
yy-=self.lattice.spacing
|
||||
xx-=self.lattice.spacing
|
||||
# check whether a site is in the Voronoi cell of a particle
|
||||
def is_in_voronoi(self,x,y,particle):
|
||||
d_to_particle=self.lattice.distance_to_particle(x,y,particle)
|
||||
# count how many are in voronoi cell
|
||||
count=1
|
||||
# TODO: start with a particle that is close to x,y
|
||||
for q in self.particles:
|
||||
dd=self.lattice.distance_to_particle(x,y,q)
|
||||
if q!=particle and dd<d_to_particle:
|
||||
return 0
|
||||
if dd==d_to_particle:
|
||||
count+=1
|
||||
return count
|
||||
# draw a site in a Voronoi cell
|
||||
def draw_voronoi_site(self,x,y,color,count):
|
||||
if count==0:
|
||||
return
|
||||
Color(color[0],color[1],color[2],1-count*0.1)
|
||||
Rectangle(pos=(self.pos_tocoord_x(x-0.5*self.lattice.spacing),self.pos_tocoord_y(y-0.5*self.lattice.spacing)),size=(self.base_size*self.lattice.spacing,self.base_size*self.lattice.spacing))
|
||||
|
||||
|
||||
|
||||
# respond to keyboard
|
||||
def on_key_down(self, keyboard, keycode, text, modifiers):
|
||||
@@ -215,8 +290,7 @@ class Painter(Widget):
|
||||
|
||||
# create new particle
|
||||
if touch.button=="right":
|
||||
new=Cross(touchx,touchy)
|
||||
#new=Disk(touchx,touchy)
|
||||
new=self.shape(touchx,touchy,color=self.color)
|
||||
# snap to lattice
|
||||
if self.lattice!=None:
|
||||
new.move(self.lattice.nearest_delta(new.elements[0].pos))
|
||||
@@ -241,6 +315,9 @@ class Painter(Widget):
|
||||
# record relative position of click with respect to reference
|
||||
if self.undermouse!=None:
|
||||
self.offset=Point(touchx,touchy)-self.undermouse.elements[0].pos
|
||||
# snap to lattice
|
||||
if self.lattice!=None:
|
||||
self.offset=self.lattice.nearest(self.offset)
|
||||
|
||||
# no modifiers
|
||||
if self.modifiers==[]:
|
||||
@@ -287,13 +364,17 @@ class Painter(Widget):
|
||||
# only respond to touch in drawing area
|
||||
if self.collide_point(*touch.pos):
|
||||
# convert to logical
|
||||
touchx=self.coord_topos_x(touch.x)
|
||||
touchy=self.coord_topos_y(touch.y)
|
||||
touchc=Point(self.coord_topos_x(touch.x),self.coord_topos_y(touch.y))
|
||||
|
||||
# snap to lattice
|
||||
if self.lattice!=None:
|
||||
touchc=self.lattice.nearest(touchc)
|
||||
|
||||
# only move on left click
|
||||
if touch.button=="left" and self.modifiers==[] and self.undermouse!=None:
|
||||
# attempted move determined by the relative position to the relative position of click within self.undermouse
|
||||
delta=self.adjust_move(Point(touchx,touchy)-(self.offset+self.undermouse.elements[0].pos),0)
|
||||
delta=self.adjust_move(touchc-(self.offset+self.undermouse.elements[0].pos),0)
|
||||
|
||||
|
||||
# snap to lattice
|
||||
if self.lattice!=None:
|
||||
@@ -424,6 +505,9 @@ class Painter(Widget):
|
||||
|
||||
# set color of selected particles
|
||||
def set_color(self,color):
|
||||
# set color for next particles
|
||||
self.color=color
|
||||
# set color of selected particles
|
||||
for particle in self.selected:
|
||||
particle.color=color
|
||||
# redraw
|
||||
@@ -443,15 +527,45 @@ class Painter(Widget):
|
||||
# redraw
|
||||
self.draw()
|
||||
|
||||
# set voronoi for selected particles
|
||||
def set_voronoi(self, onoff):
|
||||
for particle in self.selected:
|
||||
if onoff==0:
|
||||
particle.voronoi=False
|
||||
elif onoff==1:
|
||||
particle.voronoi=True
|
||||
elif onoff==-1:
|
||||
particle.voronoi=not particle.voronoi
|
||||
# redraw
|
||||
self.draw()
|
||||
|
||||
# write configuration to file
|
||||
def write(self,file):
|
||||
ff=open(file,"w")
|
||||
# save state (particle shape, zoom, lattice)
|
||||
if self.shape==Cross:
|
||||
ff.write("%shape=cross\n")
|
||||
elif self.shape==Disk:
|
||||
ff.write("%shape=disk\n")
|
||||
elif self.shape==Staircase:
|
||||
ff.write("%shape=staircase\n")
|
||||
elif self.shape==Square2:
|
||||
ff.write("%shape=2square\n")
|
||||
else:
|
||||
print("bug: unrecognized shape in write: '"+str(self.shape)+"'")
|
||||
ff.write("%zoom={:1.1f}\n".format(self.base_size/50))
|
||||
ff.write("%color={:1.1f},{:1.1f},{:1.1f}\n".format(self.color[0],self.color[1],self.color[2]))
|
||||
if self.lattice != None:
|
||||
ff.write("%lattice="+self.lattice.type+':'+str(self.lattice.spacing)+"\n")
|
||||
for particle in self.particles:
|
||||
if type(particle)==Cross:
|
||||
ff.write("{:d};".format(CROSS_INDEX))
|
||||
elif type(particle)==Disk:
|
||||
ff.write("{:d};".format(DISK_INDEX))
|
||||
elif type(particle)==Staircase:
|
||||
ff.write("{:d};".format(STAIRCASE_INDEX))
|
||||
elif type(particle)==Square2:
|
||||
ff.write("{:d};".format(SQUARE2_INDEX))
|
||||
ff.write("{:05.2f},{:05.2f};{:3.1f},{:3.1f},{:3.1f}\n".format(particle.elements[0].pos.x,particle.elements[0].pos.y,particle.color[0],particle.color[1],particle.color[2]))
|
||||
ff.close()
|
||||
|
||||
@@ -486,12 +600,35 @@ class Painter(Widget):
|
||||
if len(line)==0:
|
||||
continue
|
||||
|
||||
# read options
|
||||
if line[0]=='%':
|
||||
# ignore empty line
|
||||
if len(line)==1:
|
||||
continue
|
||||
[key,val]=line[1:].split('=',1)
|
||||
if key=="shape":
|
||||
self.app.command_prompt.run_set_shape(["set","shape",val])
|
||||
elif key=="zoom":
|
||||
self.app.command_prompt.run_set_zoom(["set","zoom",val])
|
||||
elif key=="color":
|
||||
color_str=val.split(',')
|
||||
try:
|
||||
self.set_color((float(color_str[0]),float(color_str[1]),float(color_str[2])))
|
||||
except:
|
||||
print("warning: ignoring line "+str(i)+" in file '"+file+"': color '"+color_str+"' cannot be read",file=sys.stderr)
|
||||
# lattice is handled by main function
|
||||
elif key=="lattice":
|
||||
continue
|
||||
else:
|
||||
print("warning: ignoring line "+str(i)+" in file '"+file+"': unrecognized option '"+key+"'",file=sys.stderr)
|
||||
continue
|
||||
|
||||
entries=line.split(";")
|
||||
# skip line if improperly formatted
|
||||
if len(entries)>3:
|
||||
print("warning: ignoring line "+str(i)+" in file '"+file+"': more than three ';' spearated entries in '"+line+"'",file=sys.stderr)
|
||||
print("warning: ignoring line "+str(i)+" in file '"+file+"': more than three ';' separated entries in '"+line+"'",file=sys.stderr)
|
||||
if len(entries)<2:
|
||||
print("warning: ignoring line "+str(i)+" in file '"+file+"': fewer than two ';' spearated entries in '"+line+"'",file=sys.stderr)
|
||||
print("warning: ignoring line "+str(i)+" in file '"+file+"': fewer than two ';' separated entries in '"+line+"'",file=sys.stderr)
|
||||
continue
|
||||
|
||||
# position
|
||||
@@ -531,6 +668,10 @@ class Painter(Widget):
|
||||
candidate=Cross(pos.x,pos.y,color=color)
|
||||
elif particle_type==DISK_INDEX:
|
||||
candidate=Disk(pos.x,pos.y,color=color)
|
||||
elif particle_type==STAIRCASE_INDEX:
|
||||
candidate=Staircase(pos.x,pos.y,color=color)
|
||||
elif particle_type==SQUARE2_INDEX:
|
||||
candidate=Square2(pos.x,pos.y,color=color)
|
||||
else:
|
||||
print("warning: ignoring line "+str(i)+" in file '"+file+"': unrecognized particle type: '"+entries[0]+"'",file=sys.stderr)
|
||||
continue
|
||||
@@ -567,6 +708,12 @@ class Painter(Widget):
|
||||
for particle in self.particles:
|
||||
if type(particle)==Cross:
|
||||
ff.write("\cross{"+colors.closest_color(particle.color,colors.xcolor_names)+"}")
|
||||
elif type(particle)==Disk:
|
||||
ff.write("\disk{"+colors.closest_color(particle.color,colors.xcolor_names)+"}")
|
||||
elif type(particle)==Staircase:
|
||||
ff.write("\staircase{"+colors.closest_color(particle.color,colors.xcolor_names)+"}")
|
||||
elif type(particle)==Square2:
|
||||
ff.write("\square{"+colors.closest_color(particle.color,colors.xcolor_names)+"}")
|
||||
ff.write("{{({:05.2f},{:05.2f})}};\n".format(particle.elements[0].pos.x-self.particles[0].elements[0].pos.x,particle.elements[0].pos.y-self.particles[0].elements[0].pos.y))
|
||||
|
||||
ff.write("\\end{tikzpicture}\n")
|
||||
@@ -584,5 +731,7 @@ class Painter(Widget):
|
||||
# global variables (used like precompiler variables)
|
||||
CROSS_INDEX=1
|
||||
DISK_INDEX=2
|
||||
STAIRCASE_INDEX=3
|
||||
SQUARE2_INDEX=4
|
||||
|
||||
|
||||
|
||||
14
src/point.py
14
src/point.py
@@ -1,3 +1,17 @@
|
||||
# Copyright 2021-2023 Ian Jauslin
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# two-dimensional point structure
|
||||
|
||||
import math
|
||||
|
||||
@@ -1,6 +1,19 @@
|
||||
# Copyright 2021-2023 Ian Jauslin
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# a polyomino is a collection of elements, defined in elements.py
|
||||
from kivy.graphics import Color,Line
|
||||
|
||||
from point import l_infinity
|
||||
from element import Element_square,Element_circle
|
||||
|
||||
@@ -16,6 +29,9 @@ class Polyomino():
|
||||
# mesh of background grid (no grid for mesh size 0)
|
||||
self.grid=kwargs.get("grid",0)
|
||||
|
||||
# draw Voronoi cell
|
||||
self.voronoi=kwargs.get("voronoi",False)
|
||||
|
||||
# draw function
|
||||
def draw(self,painter,**kwargs):
|
||||
alpha=kwargs.get("alpha",1)
|
||||
@@ -107,3 +123,57 @@ class Cross(Polyomino):
|
||||
class Disk(Polyomino):
|
||||
def __init__(self,x,y,**kwargs):
|
||||
super(Disk,self).__init__(**kwargs,elements=[Element_circle(x,y,size=kwargs.get("size",1.0))])
|
||||
|
||||
# 3-staircase
|
||||
class Staircase(Polyomino):
|
||||
def __init__(self,x,y,**kwargs):
|
||||
super(Staircase,self).__init__(**kwargs,elements=[\
|
||||
Element_square(x,y+1,1,aspect=3),\
|
||||
Element_square(x+1,y,1),\
|
||||
Element_square(x+1,y+1,1),\
|
||||
Element_square(x+2,y,1)\
|
||||
])
|
||||
|
||||
# redefine stroke to avoid lines between touching elements
|
||||
def stroke(self,painter):
|
||||
# convert to graphical coordinates
|
||||
coordx=painter.pos_tocoord_x(self.elements[0].pos.x)
|
||||
coordy=painter.pos_tocoord_y(self.elements[0].pos.y)
|
||||
|
||||
Color(1,1,1)
|
||||
Line(points=(
|
||||
*(coordx-0.5*painter.base_size,coordy-1.5*painter.base_size),
|
||||
*(coordx+2.5*painter.base_size,coordy-1.5*painter.base_size),
|
||||
*(coordx+2.5*painter.base_size,coordy-0.5*painter.base_size),
|
||||
*(coordx+1.5*painter.base_size,coordy-0.5*painter.base_size),
|
||||
*(coordx+1.5*painter.base_size,coordy+0.5*painter.base_size),
|
||||
*(coordx+0.5*painter.base_size,coordy+0.5*painter.base_size),
|
||||
*(coordx+0.5*painter.base_size,coordy+1.5*painter.base_size),
|
||||
*(coordx-0.5*painter.base_size,coordy+1.5*painter.base_size),
|
||||
*(coordx-0.5*painter.base_size,coordy-1.5*painter.base_size),
|
||||
))
|
||||
|
||||
# 2-square
|
||||
class Square2(Polyomino):
|
||||
def __init__(self,x,y,**kwargs):
|
||||
super(Square2,self).__init__(**kwargs,elements=[\
|
||||
Element_square(x,y,1),\
|
||||
Element_square(x+1,y,1),\
|
||||
Element_square(x,y+1,1),\
|
||||
Element_square(x+1,y+1,1)\
|
||||
])
|
||||
|
||||
# redefine stroke to avoid lines between touching elements
|
||||
def stroke(self,painter):
|
||||
# convert to graphical coordinates
|
||||
coordx=painter.pos_tocoord_x(self.elements[0].pos.x)
|
||||
coordy=painter.pos_tocoord_y(self.elements[0].pos.y)
|
||||
|
||||
Color(1,1,1)
|
||||
Line(points=(
|
||||
*(coordx-0.5*painter.base_size,coordy-0.5*painter.base_size),
|
||||
*(coordx+1.5*painter.base_size,coordy-0.5*painter.base_size),
|
||||
*(coordx+1.5*painter.base_size,coordy+1.5*painter.base_size),
|
||||
*(coordx-0.5*painter.base_size,coordy+1.5*painter.base_size),
|
||||
*(coordx-0.5*painter.base_size,coordy-0.5*painter.base_size),
|
||||
))
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
# Copyright 2021-2023 Ian Jauslin
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from kivy.uix.label import Label
|
||||
from kivy.graphics import Color,Rectangle
|
||||
from kivy.utils import escape_markup
|
||||
|
||||
14
src/tools.py
14
src/tools.py
@@ -1,3 +1,17 @@
|
||||
# Copyright 2021-2023 Ian Jauslin
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import math
|
||||
|
||||
# sign function
|
||||
|
||||
Reference in New Issue
Block a user