Drawing cubic lattice in Python -


so want draw simple cubic lattice in python using visual package.

i have simple way of making lattice small spheres have same color, want colors alternate: make nacl lattice need have sphere of 1 color surrounded 6 spheres of other color.

so did this:

from __future__ import division visual import sphere,color l = 5 r = 0.3 = [] odd = [] in range(-l,l+1): if i%2==0: even.append(i) else: odd.append(i) in even: j in even: k in even: sphere(pos=[i,j+1,k+1],radius=r,color=color.green) in odd: j in odd: k in odd: sphere(pos=[i,j,k],radius=r,color=color.yellow) 

and spheres of 1 color next speres of different color, in rows:

lattice

but need them alternate :\ correct placement in direction. how correct others make simple cubic lattice? tried fiddling positions of spheres (i,j,k+-number), way got bcc lattice (one green sphere in middle, others around it).

i'm stuck...

what need this:

from visual import sphere,color count = 3 r=0.3 x in range(-count,count+1): y in range(-count,count+1): z in range(-count,count+1): if ((x+y+z+3*count)%2) == 0: sphere(pos=[x,y,z],radius=r,color=color.green) else: sphere(pos=[x,y,z],radius=r,color=color.yellow) 

the point is, should switch colors depending on whether sum of (integral, in case) coordinates divisible 2 or not.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

c++ - Accessing inactive union member and undefined behavior? -

php - Get uncommon values from two or more arrays -