[Fractale module]Added non blocking fractal generation + checkpoint
This commit is contained in:
parent
609aef0b5c
commit
30a69b782f
2
fractale
2
fractale
@ -1 +1 @@
|
||||
Subproject commit a52ec4b63b80b44869a824ea4a8b7f231dc5e3e4
|
||||
Subproject commit b9593de2074b68efae51d1ab49ab31666e3477d0
|
@ -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():
|
||||
</prefix>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)
|
||||
|
Loading…
Reference in New Issue
Block a user