Python Tutorials | (back to the list of tutorials) |
Creating Curves with Arrays
![]()
![]()
![]()
![]()
add_library('igeo')
size( 480, 360, IG.GL )
cpts1 = []
cpts1.append(IVec(-30, 10, 0))
cpts1.append(IVec(-10, 10, 0))
cpts1.append(IVec(-10, 30, 0))
cpts1.append(IVec(-30, 30, 0))
# curve 1 (red)
ICurve(cpts1, 3).clr(1.,0,0)
cpts2 = []
for i in range(10) :
if i%2==0 :
cpts2.append(IVec(i*10, 0, 0))
else :
cpts2.append(IVec(i*10, 10, 0))
# curve 2 (blue)
ICurve(cpts2, 1).clr(0,0,1.)
cpts3 = []
for i in range(16) :
if i%4==0 :
cpts3.append(IVec(-30, -10, i*5))
elif i%4==1 :
cpts3.append(IVec(-10, -10, i*5))
elif i%4==2 :
cpts3.append(IVec(-10, -30, i*5))
else :
cpts3.append(IVec(-30, -30, i*5)) # same with i%4==3
# curve 3 (cyan)
ICurve(cpts3, 3).clr(0,1.,1.)
Creating Surfaces with Arrays
![]()
![]()
![]()
![]()
add_library('igeo')
size( 480, 360, IG.GL )
cpts1 = []
cpts1.append([])
cpts1[0].append(IVec( 0, 0, 0))
cpts1[0].append(IVec( 0,-30, 0))
cpts1.append([])
cpts1[1].append(IVec(-30, 0, 0))
cpts1[1].append(IVec(-30,-30, 0))
# surface 1 (gray)
ISurface(cpts1)
cpts2 = []
for i in range(10) :
cpts2.append([])
if i%2==0 :
cpts2[i].append(IVec(i*10,0,0))
cpts2[i].append(IVec(i*10,0,20))
else :
cpts2[i].append(IVec(i*10,-10,0))
cpts2[i].append(IVec(i*10,10,10))
# surface 2 (purple)
ISurface(cpts2).clr(.5,0,1)
cpts3 = []
for i in range(4) :
cpts3.append([])
for j in range(4) :
if (i==0 or i==3) and (j==1 or j==2) :
cpts3[i].append(IVec(-i*10, j*10, 20))
else :
cpts3[i].append(IVec(-i*10, j*10, 0))
# surface 3 (pink)
ISurface(cpts3,3,3).clr(1,.5,1)
Creating Polygon Mesh with Arrays
![]()
![]()
![]()
![]()
add_library('igeo')
size( 480, 360, IG.GL )
cpts1 = []
for i in range(10) :
cpts1.append([])
for j in range(10) :
if (i+j)%2==0 :
cpts1[i].append(IVec(i*5, -j*5-30, (i+j)*2))
else :
cpts1[i].append(IVec(i*5, -j*5-30, (i+j-1)*2))
# mesh 1 (cyan)
IMesh(cpts1).clr(0,1.,1.)
divNum=30
cpts2 = []
for i in range(10) :
cpts2.append([])
for j in range(divNum+1) :
radius = 30 - i*3
angle = 2 * PI / divNum * j
cpts2[i].append(IVec(cos(angle)*radius, sin(angle)*radius, i*i*.5))
# mesh 2 (red)
IMesh(cpts2).clr(1.,0,0)
Note that the use of constant PI to calculate the angle to be used in
trigonometric function. divNum is dividing 2 * PI,
not 360 because the unit of sin() and cos() is not degree
but radian.
Please also note that the length of the array cpts2 in the
second dimension is not divNum but divNum+1
to match points on the end edge with points on the start edge.
HOME
FOR PROCESSING
DOWNLOAD
DOCUMENTS
TUTORIALS (Java /
Python)
GALLERY
SOURCE CODE(GitHub)
PRIVACY POLICY
ABOUT/CONTACT