Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Alligators-python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Benjamin Monmege
Alligators-python
Commits
e15fb9d3
Commit
e15fb9d3
authored
Jun 8, 2022
by
Antonio MATTAR
Browse files
Options
Downloads
Patches
Plain Diff
-Added createImage function in image_maker.py
parent
8fbe3764
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
figures/space.png
+0
-0
0 additions, 0 deletions
figures/space.png
image_maker.py
+58
-8
58 additions, 8 deletions
image_maker.py
main.py
+8
-5
8 additions, 5 deletions
main.py
processor.py
+2
-2
2 additions, 2 deletions
processor.py
with
68 additions
and
15 deletions
figures/space.png
0 → 100644
+
0
−
0
View file @
e15fb9d3
2.51 KiB
This diff is collapsed.
Click to expand it.
image_maker.py
+
58
−
8
View file @
e15fb9d3
from
ast
import
Raise
from
email.mime
import
application
from
logging
import
exception
from
PIL
import
Image
import
processor
...
...
@@ -18,14 +19,63 @@ def associateVariableWithColor(variable):
variables_colors_couple
[
str
(
variable
)]
=
colors
[
-
1
]
colors
.
pop
()
def
associateVariablesWithColors
(
variables
):
for
variable
in
variables
:
associateVariableWithColor
(
variables
[
variable
])
def
createVarImage
(
variable
):
assert
(
processor
.
isVariable
(
variable
))
return
(
Image
.
open
(
"
figures/egg_
"
+
variables_colors_couple
[
str
(
variable
)]
+
"
.png
"
)).
save
(
str
(
variable
[
1
])
+
"
.png
"
)
associateVariableWithColor
(
variable
)
egg_img
=
Image
.
open
(
"
figures/egg_
"
+
variables_colors_couple
[
str
(
variable
)]
+
"
.png
"
)
egg_img
.
save
(
'
egg_
'
+
str
(
variable
[
1
])
+
"
.png
"
)
return
egg_img
def
createAlligator
(
terme
):
assert
(
processor
.
isVariable
(
terme
))
associateVariableWithColor
(
terme
)
alligator_img
=
Image
.
open
(
"
figures/alligator_
"
+
variables_colors_couple
[
str
(
terme
)]
+
"
.png
"
)
alligator_img
.
save
(
'
alligator_
'
+
str
(
terme
[
1
])
+
"
.png
"
)
return
alligator_img
def
createAbsImage
(
terme
):
assert
(
processor
.
isAbstraction
(
terme
))
input
=
processor
.
getInputFromAbs
(
terme
)
output
=
processor
.
getOutputFromAbs
(
terme
)
im1
=
createAlligator
(
input
)
im2
=
createImage
(
output
)
abstraction
=
Image
.
new
(
'
RGB
'
,
(
max
(
im1
.
width
,
im2
.
width
),
im1
.
height
+
im2
.
height
),
(
255
,
255
,
255
))
abstraction
.
paste
(
im1
,
(
0
,
0
))
abstraction
.
paste
(
im2
,
((
im1
.
width
-
im2
.
width
)
//
2
,
im1
.
height
))
abstraction
.
save
(
'
abs.png
'
)
return
abstraction
def
get_concat_h_multi_resize
(
im_list
,
resample
=
Image
.
BICUBIC
):
min_height
=
min
(
im
.
height
for
im
in
im_list
)
im_list_resize
=
[
im
.
resize
((
int
(
im
.
width
*
min_height
/
im
.
height
),
min_height
),
resample
=
resample
)
for
im
in
im_list
]
total_width
=
sum
(
im
.
width
for
im
in
im_list_resize
)
dst
=
Image
.
new
(
'
RGB
'
,
(
total_width
,
min_height
))
pos_x
=
0
for
im
in
im_list_resize
:
dst
.
paste
(
im
,
(
pos_x
,
0
))
pos_x
+=
im
.
width
return
dst
def
createAppImage
(
terme
):
assert
(
processor
.
isApplication
(
terme
))
left
=
processor
.
getFirstTerm
(
terme
)
right
=
processor
.
getSecondTerm
(
terme
)
im1
=
createImage
(
left
)
im2
=
createImage
(
right
)
space
=
Image
.
open
(
"
figures/space.png
"
)
application
=
get_concat_h_multi_resize
([
im1
,
space
,
im2
])
application
.
save
(
'
application.png
'
)
return
application
def
createImage
(
terme
):
if
processor
.
isVariable
(
terme
):
return
createVarImage
(
terme
)
if
processor
.
isAbstraction
(
terme
):
return
createAbsImage
(
terme
)
if
processor
.
isApplication
(
terme
):
return
createAppImage
(
terme
)
else
:
raise
Exception
(
"
Unsupported term type
"
)
def
createVarsImages
(
variables
):
for
variable
in
variables
:
createVarImage
(
variables
[
variable
])
\ No newline at end of file
(
createImage
(
parser
.
parseTerm
(
input
(
"
Enter a term:
"
))))
\ No newline at end of file
This diff is collapsed.
Click to expand it.
main.py
+
8
−
5
View file @
e15fb9d3
...
...
@@ -3,10 +3,13 @@ import parser
import
image_maker
def
run
():
parser
.
parseTerm
(
input
(
"
Enter a term:
"
))
image_maker
.
associateVariablesWithColors
(
parser
.
variables
)
print
(
parser
.
variables
)
print
(
image_maker
.
variables_colors_couple
)
image_maker
.
createVarsImages
(
parser
.
variables
)
print
(
processor
.
to_string
(
parser
.
parseTerm
(
input
(
"
Enter a term:
"
))))
# image_maker.associateVariablesWithColors(parser.variables)
# print(parser.variables)
# print(image_maker.variables_colors_couple)
# image_maker.createVarsImages(parser.variables)
# image_maker.createAlligator(parser.parseTerm(input("Enter a term: ")))
run
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
processor.py
+
2
−
2
View file @
e15fb9d3
...
...
@@ -41,7 +41,7 @@ def isLambdaTerm(terme): return isVariable(terme) or isAbstraction(terme) or isA
# Prends en parametre une variable P et retourne une liste contenant le nom de la variable
def
getVariablesFromVar
(
terme
):
assert
isVariable
(
terme
),
"
argument is not a variable!
"
return
[
terme
[
1
]
]
return
[
terme
]
# Prends en parametre une abstraction 'P' et renvoie une liste des nom des variables que cette abstraction contient
def
getVariablesFromAbs
(
terme
):
...
...
@@ -203,7 +203,7 @@ def to_string_var(terme):
def
to_string_abs
(
terme
):
assert
(
isAbstraction
(
terme
)),
'
The argument is not an Abstraction
'
return
"
#
"
+
to_string
(
getInputFromAbs
(
terme
))
+
"
.
"
+
to_string
(
getOutputFromAbs
(
terme
))
return
"
λ
"
+
to_string
(
getInputFromAbs
(
terme
))
+
"
.
"
+
to_string
(
getOutputFromAbs
(
terme
))
def
to_string_app
(
terme
):
assert
(
isApplication
(
terme
)),
'
The argument is not an application
'
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment