[fractale module] finished module.
This commit is contained in:
parent
333ac8b732
commit
0fc44eef2f
@ -1,7 +1,9 @@
|
|||||||
# dummy module
|
# dummy module
|
||||||
import discord
|
import discord
|
||||||
|
import random
|
||||||
|
|
||||||
|
import fractale.source.main
|
||||||
|
from PIL import Image
|
||||||
class MainClass():
|
class MainClass():
|
||||||
def __init__(self, client, modules, owners, prefix):
|
def __init__(self, client, modules, owners, prefix):
|
||||||
self.client = client
|
self.client = client
|
||||||
@ -16,32 +18,32 @@ class MainClass():
|
|||||||
self.interactive = True
|
self.interactive = True
|
||||||
self.color = 0x78ffc3
|
self.color = 0x78ffc3
|
||||||
self.fractals = {
|
self.fractals = {
|
||||||
"von_koch_curve_flake": {"Type": "Figures", "Max": ((5000, 5000), 5000, 10), "Min": ((0, 0), 0, 1),
|
"von_koch_curve_flake": {"Type": "Figures", "Max": ((5000, 5000), 5000, 10, 16777215, 16777215, 5000), "Min": ((0, 0), 0, 1, 0, 0, 0),
|
||||||
"Default": "(2500 2500) 2000 5 #ffffff 1",
|
"Default": "(2500 2500) 2000 5 #81ff65 #191919 2",
|
||||||
"Indication": "(départ) (arrivée) longueur iterations color bg stroke",
|
"Indication": "(départ) (arrivée) longueur iterations couleur_trait couleur_fond stroke",
|
||||||
"ParseData": "pfixi"},
|
"ParseData": "pfixxi"},
|
||||||
"von_koch_curve": {"Type": "Figures", "Max": ((5000, 5000), (5000, 5000), 10), "Min": ((0, 0), (0, 0), 1),
|
"von_koch_curve": {"Type": "Figures", "Max": ((5000, 5000), (5000, 5000), 10, 16777215, 16777215, 5000), "Min": ((0, 0), (0, 0), 1, 0, 0, 0),
|
||||||
"Default": "(0 2500) (5000 2500) 5 #ffffff 1",
|
"Default": "(0 2500) (5000 2500) 5 #81ff65 #191919 2",
|
||||||
"Indication": "(départ) (arrivée) iterations color bg stroke", "ParseData": "ppixi"},
|
"Indication": "(départ) (arrivée) iterations couleur_trait couleur_fond stroke", "ParseData": "ppixxi"},
|
||||||
"blanc_manger": {"Type": "Figures", "Max": ((5000, 5000), (5000, 5000), 10), "Min": ((0, 0), (0, 0), 1),
|
"blanc_manger": {"Type": "Figures", "Max": ((5000, 5000), (5000, 5000), 10, 16777215, 16777215, 5000), "Min": ((0, 0), (0, 0), 1, 0, 0, 0),
|
||||||
"Default": "(1000 1000) (4000 4000) 7 #ffffff 1",
|
"Default": "(1000 1000) (4000 4000) 7 #81ff65 #191919 2",
|
||||||
"Indication": "(départ) (arrivée) iterations color bg stroke", "ParseData": "ppixi"},
|
"Indication": "(départ) (arrivée) iterations couleur_trait couleur_fond stroke", "ParseData": "ppixxi"},
|
||||||
"dragon": {"Type": "Lsystem", "Max": ((5000, 5000), 2500, 19), "Min": ((0, 0), 1, 1),
|
"dragon": {"Type": "Lsystem", "Max": ((5000, 5000), 2500, 19, 16777215, 16777215, 5000), "Min": ((0, 0), 1, 1, 0, 0, 0),
|
||||||
"Default": "(2500 2500)", "Indication": "(origine) longueur iterations color bg stroke",
|
"Default": "(2500 2500) 4 18 #81ff65 #191919 2", "Indication": "(origine) longueur iterations couleur_trait couleur_fond stroke",
|
||||||
"ParseData": "pfixi"},
|
"ParseData": "pfixxi"},
|
||||||
"sierpinski_triangle": {"Type": "Lsystem", "Max": ((5000, 5000), 2500, 11), "Min": ((0, 0), 0, 1),
|
"sierpinski_triangle": {"Type": "Lsystem", "Max": ((5000, 5000), 2500, 11, 16777215, 16777215, 5000), "Min": ((0, 0), 0, 1, 0, 0, 0),
|
||||||
"Default": "(0 0)", "Indication": "(origine) longueur iterations color bg stroke",
|
"Default": "(0 0) 10 9 #81ff65 #191919 2", "Indication": "(origine) longueur iterations couleur_trait couleur_fond stroke",
|
||||||
"ParseData": "pfixi"},
|
"ParseData": "pfixxi"},
|
||||||
"fractal_plant": {"Type": "Lsystem", "Max": ((5000, 5000), 2500, 8), "Min": ((0, 0), 0, 1),
|
"fractal_plant": {"Type": "Lsystem", "Max": ((5000, 5000), 2500, 8, 16777215, 16777215, 5000), "Min": ((0, 0), 0, 1, 0, 0, 0),
|
||||||
"Default": "(0 2500)", "Indication": "(origine) longueur iterations color bg stroke",
|
"Default": "(0 2500) 6.5 8 #81ff65 #191919 2", "Indication": "(origine) longueur iterations couleur_trait couleur_fond stroke",
|
||||||
"ParseData": "pfixi"},
|
"ParseData": "pfixxi"},
|
||||||
"koch_curve_right_angle": {"Type": "Lsystem", "Max": ((5000, 5000), 2500, 9), "Min": ((0, 0), 0, 1),
|
"koch_curve_right_angle": {"Type": "Lsystem", "Max": ((5000, 5000), 2500, 9, 16777215, 16777215, 5000), "Min": ((0, 0), 0, 1, 0, 0, 0),
|
||||||
"Default": "(0 5000)",
|
"Default": "(0 5000) 2.25 7 #81ff65 #191919 2",
|
||||||
"Indication": "(origine) longueur iterations color bg stroke",
|
"Indication": "(origine) longueur iterations couleur_trait couleur_fond stroke",
|
||||||
"ParseData": "pfixi"},
|
"ParseData": "pfixxi"},
|
||||||
"fractal_binary_tree": {"Type": "Lsystem", "Max": ((5000, 5000), 2500, 15), "Min": ((0, 0), 0, 1),
|
"fractal_binary_tree": {"Type": "Lsystem", "Max": ((5000, 5000), 2500, 15, 16777215, 16777215, 5000), "Min": ((0, 0), 0, 1, 0, 0, 0),
|
||||||
"Default": "(0 0)", "Indication": "(origine) longueur iterations color bg stroke",
|
"Default": "(0 0) 1.2 12 #81ff65 #191919 2", "Indication": "(origine) longueur iterations couleur_trait couleur_fond stroke",
|
||||||
"ParseData": "pfixi"}
|
"ParseData": "pfixxi"}
|
||||||
}
|
}
|
||||||
self.help = """\
|
self.help = """\
|
||||||
</prefix>fractale info <fractale>
|
</prefix>fractale info <fractale>
|
||||||
@ -62,27 +64,48 @@ class MainClass():
|
|||||||
if len(args) == 1:
|
if len(args) == 1:
|
||||||
await self.modules['help'][1].send_help(message.channel, self)
|
await self.modules['help'][1].send_help(message.channel, self)
|
||||||
elif len(args) == 2:
|
elif len(args) == 2:
|
||||||
pass
|
if args[1] in self.fractals.keys():
|
||||||
|
await self.send_fractal(message, args[1]+' '+' '.join(['*']*len(self.fractals[args[1]]['ParseData'])))
|
||||||
elif len(args) == 3:
|
elif len(args) == 3:
|
||||||
if args[1] == "" and args[2] in self.fractals.keys():
|
if args[1] == "info" and args[2] in self.fractals.keys():
|
||||||
description = """\
|
description = """\
|
||||||
La fractale {nom} attend les arguments suivant :
|
La fractale {nom} attend les arguments suivant :
|
||||||
`{arguments}`
|
`{arguments}`
|
||||||
avec le type suivant:
|
avec le type suivant:
|
||||||
`{type}`
|
`{type}`
|
||||||
|
Les nombres décimaux sont des nombres à virgules là où les nombres entiers n'en ont pas. **(mettre un point à la place de la virgule)**
|
||||||
|
|
||||||
Attention, les coordonnées des points doivent être entre parentheses et son considérés comme un unique argument.
|
Attention, les coordonnées des points doivent être entre parentheses et sont considérées comme un unique argument.
|
||||||
|
Gardez aussi en tête que **l'image a pour résolution 5000*5000.**
|
||||||
|
|
||||||
Les arguments valent par défaut :
|
Les arguments valent par défaut :
|
||||||
`{defaut}`""".format(nom=args[2])
|
`{defaut}`""".format(nom=args[2], arguments=self.fractals[args[2]]['Indication'], type=' '.join(["point decimal entier hexadecimal".split(" ")["pfix".index(ch)] for ch in self.fractals[args[2]]['ParseData']]), defaut=self.fractals[args[2]]['Default'])
|
||||||
await message.channel.send(
|
await message.channel.send(
|
||||||
embed=discord.Embed(title="[%s] - Infos : *%s*" % (self.name, args[2]), description=""))
|
embed=discord.Embed(title="[%s] - Infos : *%s*" % (self.name, args[2]), description=description, color=self.color))
|
||||||
else:
|
else:
|
||||||
await self.modules['help'][1].send_help(message.channel, self)
|
await self.modules['help'][1].send_help(message.channel, self)
|
||||||
# parsed_data=self.parse(message.content[len("%sfractale "%self.prefix):])))
|
elif args[1] in self.fractals.keys():
|
||||||
|
await self.send_fractal(message, ' '.join(args[1:]))
|
||||||
|
else:
|
||||||
|
await self.modules['help'][1].send_help(message.channel, self)
|
||||||
|
|
||||||
async def send_fractal(self, message, command):
|
async def send_fractal(self, message, command):
|
||||||
return # TODO Coder la fonction
|
parsed_data=self.parse(command)
|
||||||
|
if parsed_data["Success"]:
|
||||||
|
res=parsed_data["Result"]
|
||||||
|
tmpstr="/tmp/%s.png"%random.randint(1,10000000)
|
||||||
|
im=Image.new('RGB', (5000,5000), tuple([int(i, 16) for i in map(''.join, zip(*[iter(hex(res[-2])[2:].ljust(6,'0'))]*2))]))
|
||||||
|
fig = eval("fractale.source.main."+self.fractals[command.split(' ')[0]]["Type"]+"(im=im)")
|
||||||
|
if self.fractals[command.split(' ')[0]]["Type"]=="Lsystem":
|
||||||
|
fig.state.x,fig.state.y=res[0]
|
||||||
|
#fig.state.color,fig.state.width=tuple([int(i, 16) for i in map(''.join, zip(*[iter(hex(res[-3])[2:].ljust(6,'0'))]*2))]),res[-1]
|
||||||
|
eval("fig."+command.split(' ')[0])(*res[1:-3],color=tuple([int(i, 16) for i in map(''.join, zip(*[iter(hex(res[-3])[2:].ljust(6,'0'))]*2))]), width=res[-1])
|
||||||
|
else:
|
||||||
|
eval("fig."+command.split(' ')[0])(*res[:-3],color=tuple([int(i, 16) for i in map(''.join, zip(*[iter(hex(res[-3])[2:].ljust(6,'0'))]*2))]), width=res[-1])
|
||||||
|
im.save(tmpstr)
|
||||||
|
await message.channel.send(file=discord.File(tmpstr))
|
||||||
|
else:
|
||||||
|
await message.channel.send(parsed_data["Message"])
|
||||||
|
|
||||||
def parse(self, inp):
|
def parse(self, inp):
|
||||||
retDic = {"Success": False, "Message": "", "Result": ()}
|
retDic = {"Success": False, "Message": "", "Result": ()}
|
||||||
@ -181,5 +204,15 @@ Les arguments valent par défaut :
|
|||||||
parsed_args.append(
|
parsed_args.append(
|
||||||
self.parse(inp.split(' ')[0] + ' ' + fractal['Default'])['Result'][len(parsed_args)])
|
self.parse(inp.split(' ')[0] + ' ' + fractal['Default'])['Result'][len(parsed_args)])
|
||||||
i += 1
|
i += 1
|
||||||
|
for i,element in enumerate(parsed_args):
|
||||||
|
print(element,fractal['Max'][i])
|
||||||
|
if element>fractal['Max'][i]:
|
||||||
|
retDic.update({"Success": False,
|
||||||
|
"Message": "Les valeurs sont trop grandes (%s > %s)"%(str(element),str(fractal['Max'][i]))})
|
||||||
|
return retDic
|
||||||
|
elif element<fractal['Min'][i]:
|
||||||
|
retDic.update({"Success": False,
|
||||||
|
"Message": "Les valeurs sont trop petites (%s < %s)"%(str(element),str(fractal['Min'][i]))})
|
||||||
|
return retDic
|
||||||
retDic.update({"Success": True, "Result": parsed_args})
|
retDic.update({"Success": True, "Result": parsed_args})
|
||||||
return (retDic)
|
return (retDic)
|
||||||
|
Loading…
Reference in New Issue
Block a user