From e22454a571c107b08194bb829e71628f00b4d05f Mon Sep 17 00:00:00 2001 From: Antonio MATTAR <antonio.mattar@etu.univ-amu.fr> Date: Thu, 30 Jun 2022 15:54:59 +0200 Subject: [PATCH] -Fixed the huge dimensions problem // -Fixed the colors to start by a predefined list and then if needed generate new different colors. --- README.md | 32 ++++++++--------------- image_maker.py | 70 +++++++++++++++++++++++++++++++++++++------------- main.py | 2 +- 3 files changed, 64 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index b453b2a..63afd4e 100644 --- a/README.md +++ b/README.md @@ -9,45 +9,35 @@ The main goal of the program is to generate the result of the beta_reduction of ## Table of contents -<!-- TOC -->- [the structures](#structures)<br /> - [what to install](#needs)<br /> - [how to install](#how)<br /> - [utilisation](#utilisation)<br /> - [parsing syntax ](#parse)<br /> - [documentation](#docu)<br /> - [contribution](#contri)<br /> <!-- /TOC --> +<!-- TOC -->- [The structures](#structures)<br /> - [What to install](#needs)<br /> - [How to install](#how)<br /> - [Usage](#utilisation)<br /> - [Parsing syntax ](#parse)<br /> - [Documentation](#docu)<br /> - [Contribution](#contri)<br /> <!-- /TOC --> -## structures <a name="structures"></a> +## Structures <a name="structures"></a> Lambda terms are respresented by lists, the first element of the list is an indication to the type of the lambda term that it represents.<br /> -Variable: [VAR, name]<br /> -Abstraction: [ABS, input, output] input and output are also lambda terms<br /> -Application: [APP, first_Term, second_Term] first_term and second_term are also lambda terms<br /> +<strong>Variable</strong>: [VAR, name]<br /> +<strong>Abstraction</strong>: [ABS, input, output] input and output are also lambda terms<br /> +<strong>Application</strong>: [APP, first_Term, second_Term] first_term and second_term are also lambda terms<br /> -The png images are already created, to build the image of a lambda term, we just have to concatenate the existing images and to colorate the alligators and eggs by random colors. +The JPEG images are already created, to build the image of a lambda term, we just have to concatenate the existing images and to colorate the alligators and eggs by random colors. ## What to install <a name="needs"></a> -1. PIL library (to generate images) -2. PYFIGLET library(to implement a new font) -3. keyboard module (to get an enter char) +1. PIL library (used to generate images) +2. PYFIGLET library(used to implement a new font) +3. keyboard module (used to get an enter char) 4. shutil module (manipulate directories) -## how to install <a name="how"></a> +## How to install <a name="how"></a> - To install the needed tools, you have to use the following command:<br /> pip install requirements.txt -## utilisation <a name="utilisation"></a> +## Usage <a name="utilisation"></a> The program is very simple to use, these are some advices once we run the code: <br /> 1. When you have to make a choice, click a button which is indicated, the code won't stop asking you to re-enter a choice until you press a right button. 2. The lambda term that is given as an input has to respect some syntactic rules, you can find the rules in the section parsing syntax. 3. When you choose an option in the menu, the images that could have been generated are stocked in a temporary directory which you are free to save or delete at the end. -## Test and Deploy - -Use the built-in continuous integration in GitLab. - -- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) -- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) -- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) -- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) -- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) - *** # Editing this README diff --git a/image_maker.py b/image_maker.py index c294f04..3ac1517 100644 --- a/image_maker.py +++ b/image_maker.py @@ -19,6 +19,19 @@ def color_image(img,color): img.putpixel((i,j),(color[0], color[1], color[2])) return img +colors = ['black','blue','green','orange','pink','purple','red','yellow'] + +dic_colors={'black': (66,66,66), 'blue':(0,119,255), 'green':(0,255,6), 'orange':(255,135,10), 'pink':(249,161,207), 'purple':(255,0,237), 'red':(255,0,6), 'yellow':(247,255,0)} + +inverse_dic_colors={(66,66,66): 'black',(0,119,255):'blue', (0,255,6):'green',(255,135,10):'orange', (249,161,207):'pink', (255,0,237):'purple',(255,0,6):'red', (247,255,0):'yellow' } + +def associateVariableWithColorBis(variable): + if str(variable) not in variables_colors_couple: + variables_colors_couple[str(variable)] = dic_colors[colors[-1]] + return colors.pop() + else: + return inverse_dic_colors[variables_colors_couple[str(variable)]] + def new_color(): for i in range(3): r = random.randint(0,255) @@ -38,8 +51,8 @@ variables_colors_couple = {} def associateVariableWithColor(variable): assert (logic.isVariable(variable)) c = new_color() - colors = list(variables_colors_couple.values()) - for color in colors: + colorss = list(variables_colors_couple.values()) + for color in colorss: if close_colors(c,color): associateVariableWithColor(variable) break @@ -59,23 +72,35 @@ class My_image: else: self.image.resize(min(self.image.width,width), min(self.image.height,height)) #--------------------------------------------------------------------------------------------------------------------------------- -def createVarImage(variable): - assert (logic.isVariable(variable)) - associateVariableWithColor(variable) - egg_img = Image.open("figures/egg_black.png") - egg_img = egg_img.convert("RGB") - egg_img = color_image(egg_img,variables_colors_couple[str(variable)]) - image=My_image(egg_img,True) - return egg_img +def createVarImage(variable): + assert (logic.isVariable(variable)) + if len(colors)!=0: + k=associateVariableWithColorBis(variable) + egg_img = Image.open("figures/egg_"+k+".png") + image=My_image(egg_img,True) + return egg_img.convert("RGB") + else: + associateVariableWithColor(variable) + egg_img = Image.open("figures/egg_black.png") + egg_img = egg_img.convert("RGB") + egg_img = color_image(egg_img,variables_colors_couple[str(variable)]) + image=My_image(egg_img,True) + return egg_img.convert("RGB") def createAlligator(terme): assert (logic.isVariable(terme)) - associateVariableWithColor(terme) - alligator_img = Image.open("figures/alligator_black.png") - alligator_img = alligator_img.convert("RGB") - alligator_img = color_image(alligator_img,variables_colors_couple[str(terme)]) - image=My_image(alligator_img,False) - return alligator_img + if len(colors)!=0: + k=associateVariableWithColorBis(terme) + alligator_img = Image.open("figures/alligator_"+k+".png") + image=My_image(alligator_img,False) + return alligator_img + else: + associateVariableWithColor(terme) + alligator_img = Image.open("figures/alligator_black.png") + alligator_img = alligator_img.convert("RGB") + alligator_img = color_image(alligator_img,variables_colors_couple[str(terme)]) + image=My_image(alligator_img,False) + return alligator_img def createAbsImage(terme): assert (logic.isAbstraction(terme)) @@ -159,9 +184,18 @@ def createImage(terme): if logic.isVariable(terme): return My_image(createVarImage(terme),True) if logic.isAbstraction(terme): - return My_image(createAbsImage(terme),False) + im = createAbsImage(terme) + if im.width * im.height > 2073600: + if ((im.width * 0.5 ) * (im.height * 0.5)) < 518400: + im = im.resize((int(im.width * 0.7), int(im.height * 0.7))) + else: + im = im.resize((int(im.width * 0.5), int(im.height * 0.5))) + return My_image(im,False) if logic.isApplication(terme): - return My_image(createAppImage(terme),False) + im = createAppImage(terme) + if im.width * im.height > 2073600: + im = im.resize((int(im.width * 0.5), int(im.height * 0.5))) + return My_image(im,False) else: raise Exception("Unsupported term type") diff --git a/main.py b/main.py index fcf77e6..2b09b11 100644 --- a/main.py +++ b/main.py @@ -73,6 +73,7 @@ def moveImages(src, dest): shutil.move(src+"/"+filename, dest) def return_main_menu(): + image_maker.colors = ['black','blue','green','orange','pink','purple','red','yellow'] not_pressed = True print('Press ENTER to return to the main menu') while not_pressed: # making a loop @@ -83,7 +84,6 @@ def return_main_menu(): time.sleep(1) logic.image_counter = 0 image_maker.variables_colors_couple = {} - clear() break except: break # if user pressed a key other than the given key the loop will break -- GitLab