#!/usr/bin/python
from __future__ import division
import sys
sys.path.append('../')
import colorsys
import dcfile
import shapes
from math import sqrt

if __name__ == "__main__" :
	#First we must define a file to write to
	mydcfile= dcfile.dcfile('photonic_crystal_fs')
	mydcfile.initialize()

	def fshape(i, j) : 
		a = shapes.circle(2)
		if i in (9,10,11) and j == 10 : return None
		if i == 2 and j == 2 : 
			a.setradius(.2)
			a.position = [.1,.1]
		else : 
			a.setradius(.3)
		return a
	mypc=shapes.photonic_crystal_fixed_spacing(fshape,[21,20], basis=((1,0),(.5,.5 * sqrt(3))))
	mypc.write(mydcfile)

	#Finally, we close the file we are writing to. This is not always 
	#necessary, but still recommended.
	mydcfile.close()
Esempio n. 2
0
	mycircle.setcolor([0,1,0])
	mycircle.write(mydcfile)

	#We can also write a rectangle. This is a simpler form of a polyline.
	#Again, we use position to change its location. Offset must be an array of
	#length 2 or 3. Also, this time I set the color after defining the shape.
	myrect=shapes.rectangle([3,4],position=[-5,0,0])
	myrect.setcolor([0,0,1])
	myrect.write(mydcfile)

	#To write a lattice: we define a function that returns a shape. This 
	#function must accept two arguments, which represent the row number and the 
	#column number. So if we want to change the properties of one of the 
	#circles, we can add an if statement to change it. This will change the 
	#position and the radius of the circle.
	def fshape(i, j) : 
		a = shapes.circle(2)
		if i == 2 and j == 2 : 
			a.setradius(1)
			a.position = [2, 2]
		#else : 
			#a.position = [0, 0]
		a.space = [5, 5]
		return a
	mypc=shapes.photonic_crystal_fixed_spacing(fshape,[5,5], basis=((10,0),(0,10)))
	mypc.write(mydcfile)

	#Finally, we close the file we are writing to. This is not always 
	#necessary, but still recommended.
	mydcfile.close()