From 30a69b782f45c8eb38ee0f5ae1ee18c14a289833 Mon Sep 17 00:00:00 2001 From: Suwako Moriya Date: Wed, 27 Feb 2019 02:49:02 +0100 Subject: [PATCH] [Fractale module]Added non blocking fractal generation + checkpoint --- fractale | 2 +- modules/fractale.py | 34 ++++++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/fractale b/fractale index a52ec4b..b9593de 160000 --- a/fractale +++ b/fractale @@ -1 +1 @@ -Subproject commit a52ec4b63b80b44869a824ea4a8b7f231dc5e3e4 +Subproject commit b9593de2074b68efae51d1ab49ab31666e3477d0 diff --git a/modules/fractale.py b/modules/fractale.py index c54e2e6..8d510c2 100644 --- a/modules/fractale.py +++ b/modules/fractale.py @@ -3,7 +3,9 @@ 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 @@ -21,26 +23,46 @@ class MainClass(): 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.) - [fractale] -...: von_koch -...: blanc_manger + -> Valeurs possible pour [fractale] + nb d'itérations max entre parentheses +```..: Toutes les fractales: +......: von_koch_curve_flake (7) +......: von_koch_curve (7) +......: blanc_manger (20) +......: dragon +......: sierpinski_triangle +......: fractal_plant +......: koch_curve_right_angle +......: fractal_binary_tree``` """ + self.fractals={ + "von_koch_curve_flake":{"Type":"Figures", "Max":((5000,5000), 5000, 10), "Min":((0,0),0,1)} + "von_koch_curve":{"Type":"Figures", "Max":((5000,5000),(5000,5000),10), "Min":((0,0),(0,0),1)}, + "blanc_manger":{"Type":"Figures", "Max":((5000,5000),(5000,5000),10), "Min":((0,0),(0,0),1)}, + "dragon":{"Type":"Lsystem"}, + "sierpinski_triangle":{"Type":"Lsystem"}, + "fractal_plant":{"Type":"Lsystem"}, + "koch_curve_right_angle":{"Type":"Lsystem"}, + "fractal_binary_tree":{"Type":"Lsystem"} + } async def on_message(self, message): args=message.content.split(" ") tmpstr="/tmp/%s.png"%random.randint(1,10000000) im=Image.new('RGB', (5000, 5000), (0, 0, 0)) fig = fractale.source.main.Figures(im=im) + if len(args)==1 : - fig.von_koch_curve_flake((2500, 2500), 2000, 5) + 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]) - fig.blanc_manger((1000, 1000), (4000, 4000), iterations) + await self.client.loop.run_in_executor(ThreadPoolExecutor(), fig.blanc_manger,*((1000, 1000), (4000, 4000), iterations)) elif args[1].lower()=="von_koch" : iterations=5 if len(args)>2 and int(args[2])<=7: iterations=int(args[2]) - fig.von_koch_curve_flake((2500, 2500), 2000, iterations) + await self.client.loop.run_in_executor(ThreadPoolExecutor(), fig.von_koch_curve_flake,*((2500, 2500), 2000, iterations)) + im.save(tmpstr) await message.channel.send(file=discord.File(tmpstr)) + os.remove(tmpstr)