From 3ac3e394b57240d1a39aeb90356c7cd9e113417c Mon Sep 17 00:00:00 2001 From: Fomys Date: Sat, 2 Mar 2019 14:41:40 +0100 Subject: [PATCH] Retrait de la PEP8 (mais je remet une fois que tu aura push --- modules/fractale.py | 251 +++++++++++++++++++------------------------- 1 file changed, 109 insertions(+), 142 deletions(-) diff --git a/modules/fractale.py b/modules/fractale.py index 9f110b4..2de74e5 100644 --- a/modules/fractale.py +++ b/modules/fractale.py @@ -1,194 +1,161 @@ -# dummy module -import os -import random -from concurrent.futures import ThreadPoolExecutor - -import discord +#dummy module +import asyncio import fractale.source.main +import random +import discord +import os from PIL import Image - - +from concurrent.futures import ThreadPoolExecutor class MainClass(): def __init__(self, client, modules, owners, prefix): self.client = client self.modules = modules self.owners = owners self.prefix = prefix - self.events = ['on_message'] # events list - self.command = "%sfractale" % self.prefix # command prefix (can be empty to catch every single messages) + self.events=['on_message'] #events list + self.command="%sfractale"%self.prefix #command prefix (can be empty to catch every single messages) - self.name = "Fractale" - self.description = "Module de génération de fractales" - self.interactive = True - self.color = 0x78ffc3 - self.fractals = { - "von_koch_curve_flake": {"Type": "Figures", "Max": ((5000, 5000), 5000, 10), "Min": ((0, 0), 0, 1), - "Default": "(2500 2500) 2000 5 #ffffff 1", - "Indication": "(départ) (arrivée) longueur iterations color bg stroke", - "ParseData": "pfixi"}, - "von_koch_curve": {"Type": "Figures", "Max": ((5000, 5000), (5000, 5000), 10), "Min": ((0, 0), (0, 0), 1), - "Default": "(0 2500) (5000 2500) 5 #ffffff 1", - "Indication": "(départ) (arrivée) iterations color bg stroke", "ParseData": "ppixi"}, - "blanc_manger": {"Type": "Figures", "Max": ((5000, 5000), (5000, 5000), 10), "Min": ((0, 0), (0, 0), 1), - "Default": "(1000 1000) (4000 4000) 7 #ffffff 1", - "Indication": "(départ) (arrivée) iterations color bg stroke", "ParseData": "ppixi"}, - "dragon": {"Type": "Lsystem", "Max": ((5000, 5000), 2500, 19), "Min": ((0, 0), 1, 1), - "Default": "(2500 2500)", "Indication": "(origine) longueur iterations color bg stroke", - "ParseData": "pfixi"}, - "sierpinski_triangle": {"Type": "Lsystem", "Max": ((5000, 5000), 2500, 11), "Min": ((0, 0), 0, 1), - "Default": "(0 0)", "Indication": "(origine) longueur iterations color bg stroke", - "ParseData": "pfixi"}, - "fractal_plant": {"Type": "Lsystem", "Max": ((5000, 5000), 2500, 8), "Min": ((0, 0), 0, 1), - "Default": "(0 2500)", "Indication": "(origine) longueur iterations color bg stroke", - "ParseData": "pfixi"}, - "koch_curve_right_angle": {"Type": "Lsystem", "Max": ((5000, 5000), 2500, 9), "Min": ((0, 0), 0, 1), - "Default": "(0 5000)", - "Indication": "(origine) longueur iterations color bg stroke", - "ParseData": "pfixi"}, - "fractal_binary_tree": {"Type": "Lsystem", "Max": ((5000, 5000), 2500, 15), "Min": ((0, 0), 0, 1), - "Default": "(0 0)", "Indication": "(origine) longueur iterations color bg stroke", - "ParseData": "pfixi"} - } - self.help = """\ + self.name="Fractale" + self.description="Module de génération de fractales" + self.interactive=True + self.color=0x78ffc3 + self.fractals={ + "von_koch_curve_flake":{"Type":"Figures", "Max":((5000,5000), 5000, 10), "Min":((0,0),0,1), "Default":"(2500 2500) 2000 5 #ffffff 1", "Indication":"(départ) (arrivée) longueur iterations color bg stroke", "ParseData":"pfixi"}, + "von_koch_curve":{"Type":"Figures", "Max":((5000,5000),(5000,5000),10), "Min":((0,0),(0,0),1), "Default":"(0 2500) (5000 2500) 5 #ffffff 1", "Indication":"(départ) (arrivée) iterations color bg stroke", "ParseData":"ppixi"}, + "blanc_manger":{"Type":"Figures", "Max":((5000,5000),(5000,5000),10), "Min":((0,0),(0,0),1), "Default":"(1000 1000) (4000 4000) 7 #ffffff 1", "Indication":"(départ) (arrivée) iterations color bg stroke", "ParseData":"ppixi"}, + "dragon":{"Type":"Lsystem", "Max":((5000,5000), 2500,19), "Min":((0,0),1,1), "Default":"(2500 2500)", "Indication":"(origine) longueur iterations color bg stroke", "ParseData":"pfixi"}, + "sierpinski_triangle":{"Type":"Lsystem", "Max":((5000,5000),2500,11), "Min":((0,0),0,1), "Default":"(0 0)", "Indication":"(origine) longueur iterations color bg stroke", "ParseData":"pfixi"}, + "fractal_plant":{"Type":"Lsystem", "Max":((5000,5000),2500,8), "Min":((0,0),0,1), "Default":"(0 2500)", "Indication":"(origine) longueur iterations color bg stroke", "ParseData":"pfixi"}, + "koch_curve_right_angle":{"Type":"Lsystem", "Max":((5000,5000),2500,9), "Min":((0,0),0,1), "Default":"(0 5000)", "Indication":"(origine) longueur iterations color bg stroke", "ParseData":"pfixi"}, + "fractal_binary_tree":{"Type":"Lsystem", "Max":((5000,5000),2500,15), "Min":((0,0),0,1), "Default":"(0 0)", "Indication":"(origine) longueur iterations color bg stroke", "ParseData":"pfixi"} + } + self.help="""\ fractale [fractale] [nombre d'itérations] => Génère une image fractale. (Si on met le nombre d'itérations, on doit mettre le nom de la fractale.) -> Valeurs possible pour [fractale] ```..: Toutes les fractales: -%s```""" % '\n'.join(['......: %s' % t for t in self.fractals.keys()]) +%s```"""%'\n'.join(['......: %s'%t for t in self.fractals.keys()]) + def parse(self, inp): - retDic = {"Success": False, "Message": "", "Result": ()} - # Parsing the fractal name and storing the corresponding dic into a variable + retDic={"Success":False, "Message":"", "Result":()} + #Parsing the fractal name and storing the corresponding dic into a variable try: - fractal = self.fractals[inp.split(' ')[0]] + fractal=self.fractals[inp.split(' ')[0]] except KeyError: - retDic.update({"Success": False, "Message": "La fractale %s n'existe pas." % inp.split(' ')[0]}) - return (retDic) - arg = ' '.join(inp.split(' ')[1:]) # Stuff after the fractal name - # checking for incoherent parentheses usage - parentheses_count = 0 - for i, char in enumerate(arg): - if char == '(': - parentheses_count += 1 - elif char == ')': - parentheses_count -= 1 - if not (-1 < parentheses_count < 2): - retDic.update({"Success": False, - "Message": "Usage invalide de parentheses au charactère numéro %s (à partir d'après le nom de la fractale)." % i}) - return (retDic) + retDic.update({"Success":False, "Message":"La fractale %s n'existe pas."%inp.split(' ')[0]}) + return(retDic) + arg=' '.join(inp.split(' ')[1:]) #Stuff after the fractal name + #checking for incoherent parentheses usage + parentheses_count=0 + for i,char in enumerate(arg): + if char=='(': + parentheses_count+=1 + elif char==')': + parentheses_count-=1 + if not(-1 2 and int(args[2]) <= 20: - iterations = int(args[2]) - await self.client.loop.run_in_executor(ThreadPoolExecutor(), fig.blanc_manger, - *((1000, 1000), (4000, 4000), iterations)) - elif args[1].lower() == "von_koch_curve_flake": - iterations = 5 - if len(args) > 2 and int(args[2]) <= 7: - iterations = int(args[2]) - await self.client.loop.run_in_executor(ThreadPoolExecutor(), fig.von_koch_curve_flake, - *((2500, 2500), 2000, iterations)) - elif args[1].lower() == "von_koch_curve": - iterations = 5 - if len(args) > 2 and int(args[2]) <= 7: - iterations = int(args[2]) - await self.client.loop.run_in_executor(ThreadPoolExecutor(), fig.von_koch_curve, - *((0, 2500), (5000, 2500), iterations)) + fig = fractale.source.main.Figures(im=im)#here + if len(args)==1 : + await self.client.loop.run_in_executor(ThreadPoolExecutor(), fig.von_koch_curve_flake,*((2500, 2500), 2000, 5)) + elif args[1].lower()=="blanc_manger" : + iterations=7 + if len(args)>2 and int(args[2])<=20: + iterations=int(args[2]) + await self.client.loop.run_in_executor(ThreadPoolExecutor(), fig.blanc_manger,*((1000, 1000), (4000, 4000), iterations)) + elif args[1].lower()=="von_koch_curve_flake" : + iterations=5 + if len(args)>2 and int(args[2])<=7: + iterations=int(args[2]) + await self.client.loop.run_in_executor(ThreadPoolExecutor(), fig.von_koch_curve_flake,*((2500, 2500), 2000, iterations)) + elif args[1].lower()=="von_koch_curve" : + iterations=5 + if len(args)>2 and int(args[2])<=7: + iterations=int(args[2]) + await self.client.loop.run_in_executor(ThreadPoolExecutor(), fig.von_koch_curve,*((0, 2500), (5000,2500), iterations)) else: await self.modules['help'][1].send_help(message.channel, self) - return # here - im.save(tmpstr) # here + return#here + im.save(tmpstr)#here await message.channel.send(file=discord.File(tmpstr)) - os.remove(tmpstr) # here + os.remove(tmpstr)#here