function plotter in blender
Hey, I made two scripts that plot functions. The 2D script plots a function of the form f(x) while the 3D script plots a function of the form (x,y).
2D-Plotter
import bpy
import math
scn = bpy.data.scenes[0]
mesh = bpy.data.meshes.new("me")
ob = bpy.data.objects.new("func",mesh)
start = -1
stop = 1
step = 0.1
#Put your function here:
def function(x):
y=2
return y
k=start
verts=[]
edges=[]
for i in range(0,math.floor((stop-start)/step)+1):
verts.append((k,function(k),0))
if i < math.floor((stop-start)/step):
edges.append((i,i+1))
k=round(k+step,5)
mesh.from_pydata(verts,edges,[])
scn.objects.link(ob)
3D-plotter
import bpy
import math
scn = bpy.data.scenes[0]
mesh = bpy.data.meshes.new("me")
ob = bpy.data.objects.new("func",mesh)
x_a = -1 #Start of x interval
x_b = 1 #End of x interval
y_a = -1 #Start of x interval
y_b = 1 #End of x interval
step = 0.1 #Stepsize
#Put your function in here:
def function(x,y):
z = 2
return z
verts=[]
faces=[]
x = x_a
y = y_a
for j in range(0,math.floor((y_b-y_a)/step)):
for k in range(0,math.floor((x_b-x_a)/step)):
verts.append((x,y,function(x,y)))
x = round(x+step,5)
x = x_a
y = round(y+step,5)
DIM = math.floor((y_b-y_a)/step)
for j in range(0,DIM-1):
for k in range(0,DIM-1):
faces.append((k+j*DIM,(k+1)+j*DIM,(k+1)+(j+1)*DIM,k+(j+1)*DIM))
mesh.from_pydata(verts,[],faces)
scn.objects.link(ob)
Example plots
Tell me what you think of it :) Improvements that can be made?
7 comments · 100% upvoted · other discussions
would i be able to plot a mandelbrot with this script? and how would i do this? im teribad with scripts do i make it a python script and install it like an addon or do i copy paste it in blender
Meta_Riddley [OP] 1 points · Nov 2014
Nope, the mandebrot set is usually defined through a recursive function. This is basically for functions of the form (I'm not really good at formal definitions)
f: R -> R x -> f(x)
f: RxR -> R (x,y) -> f(x,y)
You might be able to do some modifications to it though.
CygnusXmegacorp 1 points · Nov 2014
could u maybe help me out, it would mean the world to me if i could summon the mandelbrot in one solid curve :) teach me sensei, there is a girl involved :d
Meta_Riddley [OP] 1 points · Nov 2014
There is a cooler way of doing it!
http://elbrujodelatribu.blogspot.fr/2013/04/blender-cycles-osl-mandelbrot-fractal.html
copy and paste the script into the text editor and remove the first line (the #include <stdos1.h> line)
delete the default cube and add a plane. Add a new diffuse material to it.
Set up the nodes as in the picture (Set CenterX to 0 and CenterY to 0, Zoom to 0.3 and MaxIteration to 64).
Set you compute device as CPU and check the Open Shading Language checkbox.
Now it should be working. If its not I can make a vid where I show how to set it up.
CygnusXmegacorp 1 points · Nov 2014
WAWAWIWA thanks alot man!
all hail meta riddley!!!
ps: would it be possible to spawn it as a solid curve? it boggles my mind that u can plot it but i cant plot it in blender? o.O
Meta_Riddley [OP] 1 points · Nov 2014
Not sure if it possible to make it a solid curve I would have to think about that a bit.
When it comes to how to use the script in original post, you copy and paste them into the text editor in blender and press run script. You can try the 3D-plotter first remember to set the start and stop intervals the step size and your function. If you run into any problems then just tell me
CygnusXmegacorp 1 points · Nov 2014
the script works just fine man its a blessing :D, altho coloring it smoothly is another challenge but i can figure that out .
i tried the build in plotters and i had no valid results from it. (could be me tho) any tips on how i could make a mandelbrot zoom? in blender or any other program. the script zoom seems to work well but i dont think i could go infinite loop
cant thank u enough for all the responses :)