In [1]:
using Konthe
using Images
using Color


WARNING: deprecated syntax "x[i:]" at /Users/fgans/.julia/v0.3/GetC/src/GetC.jl:19.
Use "x[i:end]" instead.
36053

Let's start with something simple, we generate 1000 random points on a unit sphere, give them some nice colors and plot them.


In [3]:
using Distributions
N=1000
a=[rand(Normal(0,sqrt(3))) for i=1:N, j=1:3]
for i=1:N s=sub(a,(i,1:3)); scale!(s,inv(norm(s))) end
col=[RGB(abs(a[i,1]),abs(a[i,2]),abs(a[i,3])) for i=1:N]

# Here comes the plotting
points3D(a[:,1],a[:,2],a[:,3],color=col,ps=2)
lightsOFF()
im=plot3D()
imwrite(im,"fig1.png")
im


Out[3]:

We can also draw lines, here is a nice spiral:


In [4]:
newPlot3D()
z=linspace(-1.5,1.5,300)
x=sin(10*z)
y=cos(10*z)
col=linspace(RGB(1.0,0.0,0.0),RGB(0.0,1.0,0.0),300)
lines3D(x,y,z,color=col)
im=plot3D()
imwrite(im,"fig2.png")
im


Out[4]:

Here come some spheres connected by lines, note that the lines start from the center, but the plot looks correct (depth buffer is working)


In [5]:
newPlot3D()
red=RGB(1.0,0.0,0.0)
blue=RGB(0.0,0.0,1.0)
sphere3D(0.0,0.0,0.0,0.4,color=red,slices=40,stacks=40)
sphere3D(1.0,0.0,0.0,0.2,color=blue,slices=40,stacks=40)
sphere3D(0.0,1.0,0.0,0.2,color=blue,slices=40,stacks=40)
sphere3D(0.0,0.0,1.0,0.2,color=blue,slices=40,stacks=40)
lines3D([0.0,0.0],[0.0,0.0],[0.0,1.0],color=[RGB(0.0,1.0,0.0)],lw=3)
lines3D([0.0,0.0],[0.0,1.0],[0.0,0.0],color=[RGB(0.0,1.0,0.0)],lw=3)
lines3D([0.0,1.0],[0.0,0.0],[0.0,0.0],color=[RGB(0.0,1.0,0.0)],lw=3)
lightsON()
im=plot3D()
imwrite(im,"fig3.png")
im


Out[5]:

You can do surface plots on matrices. The first surf3D command plots the filled area, the second one plots the grid.


In [6]:
newPlot3D()
lightsOFF()
x=linspace(-1.0,1.0,40)
y=linspace(-1.0,1.0,40)
z=float64([0.8*sin(2*x*pi)+0.8*cos(2*y*pi) for x in x, y in y])
surf3D(z,x=x,y=y,filled=true)
surf3D(z,x=x,y=y,filled=false,lw=2,color=[RGB(0.0,0.0,0.0)])
im=plot3D()
imwrite(im,"fig4.png")
im


Out[6]:

And of course, the One to rule them all must not miss. We define a parametric function for a torus and give a parameter range.


In [7]:
newPlot3D()
function ring(p,t)
    Ri=0.2
    Ra=1.5
    x=cos(t)*(Ra+Ri*cos(p))
    y=sin(t)*(Ra+Ri*cos(p))
    z=2*Ri*sin(p)
    return(x,y,z)
end
p=linspace(0.01,2.01*pi,40)
t=linspace(0.01,2.01*pi,40)
lightsON()
setLightDirection(0.0,0.0,-1.0)
surf3D(ring,p,t,filled=true,color=[RGB(1.0,0.8,0.0)])
im=plot3D()
imwrite(im,"fig5.png")
im


Out[7]:

In [ ]: