# x, y are matrices containing the real and imaginary parts
# of all z values in the grid
x, y = meshgrid(linspace(x_min, x_max, density),
linspace(y_min, y_max, density))
# we define c as c=x+iy, c is a 1000x1000 matrix
c = x + 1j*y
# initially, z=c, we copy so that z and c are different objects in memory
z = c.copy()
# m is used to plot the fractal
m = zeros((density, density))
# iterations
for n in xrange(iterations):
print "Completed %d %%" % (100 * float(n)/iterations)
# indices of the numbers c such that |z(c)|<=10, with z = z_n
indices = (abs(z) <= 10)
# update z
z[indices] = z[indices]**2 + c[indices]
# we update the values in m
m[indices] = n
# we plot log(m)
imshow(log(m), cmap=cm.hot,
extent=(x_min, x_max, y_min, y_max))
Il faut importer Numpy, que j'ai pu installer par:
apt-get install python3-numpy
Ensuite il semblerait que pylab, qui dépend de matplotlib, n'existe pas pour python3.
Je voudrais donc savoir si il existe un équivalent à matplotlib pour python3, ou, tout au moins, comment adapter ce fichier d'exemple pour Blender 2.63, si c'est possible.
Matplotlib pour Pyhton3 n'existe pas en version officielle ... mais, tu peux aller faire un tour ici
Le seul hic à ma connaissance est que ça ne soit disponible que sous Windows.
J'ai travaillé avec cette version sans rencontrer de bugs, mais ... je n'ai pas tout testé !
Il te reste sinon la solution de repasser sous Python 2.7
Jusqu'ici, tout va bien. Il passe avec un import pixel dans Blender.
Donc j'ouvre un éditeur de texte dans Blender, et je met ça:
import bpy
from mathutils import *
from math import *
import pixel
n_max = 500
x_min = -2.0
x_max = 1.0
y_min = -1.0
y_max = +1.0
pixel.initialiser(240, 160, 1)
pixel.couleur()
def mandelbrot(c):
z = 0.0
for i in range(n_max):
z = z * z + c
if abs(z) > 2.0:
return i
def convertir(x, y):
xx = x_min + (x + 0.5) * (x_max - x_min) / pixel.largeur
yy = y_max + (y + 0.5) * (y_min - y_max) / pixel.hauteur
return xx, yy
def dessiner():
for x in range(pixel.largeur):
for y in range(pixel.hauteur):
xx, yy = convertir(x, y)
n = mandelbrot(complex(xx, yy))
if n != None:
pixel.marquer(x, y, n * 0.01)
else:
pixel.marquer(x, y, None)
pixel.afficher(0)
def zoom(x, y):
global x_min
global x_max
global y_min
global y_max
xx, yy = convertir(x, y)
dx = 0.25 * (x_max - x_min)
dy = 0.25 * (y_max - y_min)
x_min = xx - dx
x_max = xx + dx
y_min = yy - dy
y_max = yy + dy
print("zoom:")
print("x_min =", x_min)
print("x_max =", x_max)
print("y_min =", y_min)
print("y_max =", y_max)
dessiner()
dessiner()
pixel.sur_clic(zoom)
pixel.afficher()
Je fait alt+p, mais le problème est que cela ne s'ouvre pas dans Blender, mais dans une fenêtre externe Python. Moi je voudrais que cela s'ouvre directement dans Blender (forcément sinon quel intérêt ? ).
Voilà, donc comment adapter tout ça pour que cela s'ouvre dans Blender directement, si bien sur c'est possible ?
Merci de votre aide.
PS: le fichier d'exemple de mon premier message me renvoie une erreur ici dans blender:
Et n'affiche que la fenêtre vide pour le code python dans un terminal.
Je n'ai pas vraiment cherché à la corriger, je me concentre sur ceux qui semble marcher, mais enfin, au cas où quelqu'un saurait ou ça cafouille, ça éviterait de laisser un fichier foireux traîner.
À bientôt...
Matplotlib python3.2
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.