PageRenderTime 39ms CodeModel.GetById 11ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/rel-1.3.35/Examples/GIFPlot/Python/full/runme.py

#
Python | 64 lines | 49 code | 10 blank | 5 comment | 4 complexity | df9a4776645c3d522ff5652fcabafa13 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
 1# Plot a 3D function
 2# This example uses the low-level C interface.
 3
 4from _gifplot import *
 5from math import *
 6
 7# Here is the function to plot
 8def func(x,y):
 9	return 5*cos(2*sqrt(x*x+y*y))*exp(-0.3*sqrt(x*x+y*y))
10
11# Here are some plotting parameters
12xmin = -5.0
13xmax =  5.0
14ymin = -5.0
15ymax =  5.0
16zmin = -5.0
17zmax =  5.0
18
19# Grid resolution
20nxpoints =  60
21nypoints =  60
22
23cmap  = new_ColorMap("cmap")
24frame = new_FrameBuffer(500,500)
25FrameBuffer_clear(frame,BLACK)
26
27p3    = new_Plot3D(frame,xmin,ymin,zmin,xmax,ymax,zmax)
28Plot3D_lookat(p3,2*max([xmax-xmin,ymax-ymin,zmax-zmin]))
29Plot3D_autoperspective(p3,40)
30Plot3D_rotu(p3,60)
31Plot3D_rotr(p3,30)
32Plot3D_rotd(p3,10)
33
34def drawsolid():
35	Plot3D_clear(p3,BLACK)
36	Plot3D_start(p3)
37	dx = 1.0*(xmax-xmin)/nxpoints
38	dy = 1.0*(ymax-ymin)/nypoints
39	cscale = 240.0/(zmax-zmin)
40	x = xmin
41	for i in xrange(0,nxpoints):
42		y = ymin
43		for j in xrange(0,nypoints):
44			z1 = func(x,y)
45			z2 = func(x+dx,y)
46			z3 = func(x+dx,y+dy)
47			z4 = func(x,y+dy)
48			c1 = cscale*(z1-zmin)
49			c2 = cscale*(z2-zmin)
50			c3 = cscale*(z3-zmin)
51			c4 = cscale*(z4-zmin)
52			c = int((c1+c2+c3+c4)/4)
53			if (c < 0) : c = 0
54			if c > 239 : c = 239
55			Plot3D_solidquad(p3,x,y,z1,x+dx,y,z2,x+dx,y+dy,z3,x,y+dy,z4,c+16)
56			y = y + dy		
57		x = x + dx
58
59print "Making a nice 3D plot..."
60drawsolid()
61
62FrameBuffer_writeGIF(frame,cmap,"image.gif")
63print "Wrote image.gif"
64