Example
Scripts:
 |
ai.noFill()
for i in range(0,100):
ai.strokeColor(i/100.0,0,0,0)
ai.line(0,i,100,i)
ai.oval(i,i,i+5,i+5)
|
 |
ai.noFill() for i in range(0,100): ai.strokeColor(i/100.0,1-i/100.0,0,0) ai.curve(i,0,-50,150,150,-50,i,100)
|
 |
import random
def rnd():
return random.random()/2
for r in range(0,10):
for c in range(0,10):
ai.fillColor(rnd(),rnd(),rnd(),rnd())
ai.rect(r*10,c*10,r*10+10,c*10+10)
ai.fillColor(rnd(),rnd(),rnd(),rnd())
ai.oval(r*10,c*10,r*10+10,c*10+10)
|
 |
import random
def rnd():
return random.random()*100
for i in range(0,100):
ai.strokeWidth(random.random()*2.0)
ai.curve(rnd(),rnd(),rnd(),rnd(),\
rnd(),rnd(),rnd(),rnd())
|
 |
import math
ai.strokeWidth(0.1)
for i in range(0,100):
a = math.cos(i)*10
b = math.sin(i)*10
ai.oval(a,b,a+i,b+100)
|
 |
#Untitled by dk jang <jangdk@yahoo.com> #April 11, 2003
import math
ai.noFill()
rot1 = 0
rot2 = rot1 + ((math.pi/200)*95)
rot3 = rot1 + ((math.pi/200)*105)
num1 = 0.23
num2 = 0.055
step = 0
for i in range(0,501):
ai.strokeWidth(0.1)
ai.strokeColor(0,0.7,1,0)
step = step + math.pi/415
rot1 = rot1 + (math.pi/130)*(math.cos(step))
rot2 = rot1 + ((math.pi/130)*(95+(i*0.02)))
rot3 = rot1 + ((math.pi/130)*(105-(i*0.02)))
x1 = math.cos(rot1)*(50-(i*num1))
y1 = math.sin(rot1)*(50-(i*num1))
x2 = math.cos(rot1)*(50-(i*num1))*-1
y2 = math.sin(rot1)*(50-(i*num1))*-1
x3 = math.cos(rot2)*(30-(i*num2))
y3 = math.sin(rot2)*(30-(i*num2))
x4 = math.cos(rot3)*(30-(i*num2))
y4 = math.sin(rot3)*(30-(i*num2))
ai.curve(x1,y1,x3*10,y3*10,\
x4*10,y4*10,x2,y2)
ai.curve(-x1,-y1,-x3*10,-y3*10,\
-x4*10,-y4*10,-x2,-y2)
|
 |
#00_Pattern
#by Dimitre at dmtr.org
import math
scale = 40
ai.fillColor(0,0,0,1)
ai.noStroke()
for i in range(0,15):
for j in range(0,15):
ai.vertex(i*scale,j*scale,(i)*scale,(j+1)*scale)
ai.vertex((i)*scale,(j+1)*scale,(i+1)*scale,(j+1)*scale)
ai.vertex((i+1)*scale,(j+1)*scale,(i+1)*scale,(j)*scale)
ai.vertex((i+1)*scale,(j)*scale,(i)*scale,(j)*scale)
ai.path(1)
|
 |
#Florespiral
#by Dimitre at dmtr.org
import math
PI = 3.1415926
fator = 8
av = 2
def c2a(x, y):
angle = math.atan2(y,x) * 180/PI
return angle
def c2m (x, y):
m = math.sqrt(x*x + y*y)
return m
def r2x (a, m):
x = m * math.cos(a/3.0)
return x
def r2y (a, m):
y = m * math.sin(a/3.0)
return y
for i in range(20,80):
for j in range(0,2):
angulo = i * 3
magnitude = (90-i)/2.0
xx = r2x (angulo, magnitude) * fator + 300
yy = r2y (angulo, magnitude) * fator + 400
xx2 = r2x (angulo - av, magnitude*2) * fator + 300
yy2 = r2y (angulo - av, magnitude*2) * fator + 400
xx3 = r2x (angulo + av, magnitude*2) * fator + 300
yy3 = r2y (angulo + av, magnitude*2) * fator + 400
ai.vertex (300, 400, xx3, yy3)
ai.vertex (xx, yy, xx2, yy2)
ai.path(1)
|
|
|
About
the ai Python object:
All drawing functions begin with
"ai."
All x-y coordinates are expressed in floated values. If you pass an integer,
it will be converted automatically.
All x-y coordinates are relative to 0,0 defined by the document's ruler,
and units are in the document's default units.
All built-ins and Python included libraries will work in the illustrator
scripting palette. That includes TCPIP, File I/O, and Python language
extension modules.
Illustrator Functions:
ai.line(x1,y1,x2,y2)
Creates a
single opened path with 2 vertices at x1,y1 and x2,y2.
ai.curve(x1,y1,hx1,hy1,hx2,hy2,x2,y2)
Creates a
single opened path with 2 vertices at x1,y1 (with out bezier handles at
hx1,hy1) and x2,y2, (with in bezier handles at hx2,hy2)
ai.rect(x1,y1,x2,y2)
Creates a
rectangle closed path with upper-left corner at x1,y1 and lower right
corner at x2,y2
ai.roundedRect(x1,y1,x2,y2,r)
Creates a
rectangle closed path with upper-left corner at x1,y1 and lower right
corner at x2,y2 and a corner radius of r
ai.oval(x1,y1,x2,y2)
Creates an
inscribed oval closed path with upper-left corner at x1,y1 and lower right
corner at x2,y2
ai.star(numPoints,cx,cy,r1,r2)
Creates an
illustrator "star" closed path (as in the tool). numPoints is
an integer specifying how many points on the star, which is drawn with
center point cx,cy and with one radius r1 and the second radius r2.
ai.regularPolygon(numSides,cx,cy,r)
Creates a
regular polygon closed path (all sides and angles equal). numSides is
an Integer specifying how many sides are on the shape, which is drawn
with center point cx,cy, and with a radius of r.
ai.spiral(firstArcCenterX,
firstArcCenterY, \
startX, startY, decayPercent, numQuarterTurns, clockwiseFromOutside)
Creates a
spiral path (as in the spiral tool). decayPercent is a floated value between
0.0 and 1.0. NumQuarterTurns is an integer. ClockwiseFromOutside is either
1 or 0.
ai.vertex(x,y)
ai.vertex(x,y,inX,inY)
ai.vertex(x,y,inX,inY,outX,outY)
These functions
add vertices to be stroked by the path
function.
An illustrator control-vertex is created, positioned at x,y with in-bezier
handle at inX,inY and with out-bezier handle at outX,outY.
ai.path()
ai.path(closed)
Creates the
multi-point path specified using the vertex
function. By default, the path will be closed (1), unless you pass a 0
for closed.
ai.fillColor(gray)
ai.fillColor(r,g,b)
ai.fillColor(c,m,y,k)
ai.strokeColor(gray)
ai.strokeColor(r,g,b)
ai.strokeColor(c,m,y,k)
Change the
default fill and stroke colors on the tool pallete, respectively. All
values passed should be floats between 0.0 and 1.0. If you pass one value,
it will be interpretted as gray. If you pass three values, it will be
interpretted as RGB. If you pass four values, it will be interpretted
as CMYK. Change the current color in a statement BEFORE creating the shape
you want to be that color.
Note: RGB does not work properly in CMYK color space documents. This option
is chosen during creating a new document (the window that pops up when
you hit Ctrl+N)
ai.noFill()
ai.noStroke()
Disable current stroke and fill, respectively. This is the same as clicking
the color box with a red slash through it.
ai.opacity(o)
Changes the
current opacity in the transparency pallete, and all shapes created afterwards.
o is a floated value between 0.0 (invisible) and 1.0 (completely opaque).
ai.transparencyMode(mode)
Changes the
current transparency mode in the transparency pallete, and all shapes
created afterwards. mode is an integer 0 through 15, following this table:
0
= Normal
1 = Multiply
2 = Screen
3 = Overlay
4 = Soft Light
5 = Hard Light
6 = Color Dodge
7 = Color Burn |
08
= Darken
09 = Lighten
10 = Difference
11 = Exclusion
12 = Hue
13 = Saturation
14 = Color
15 = Luminosity |
ai.strokeWidth(w)
Changes the
current stroke width, where w is a floated value.
ai.miterLimit(L)
Changes the
miter limit (as in the stroke pallete), where L is a floated value. This
only applies if you are using a butt cap.
ai.lineCap(c)
Changes the
current cap style (as in the stroke pallete), where c can only be 0 (butt),1
(round) or 2 (bevel).
ai.lineJoin(c)
Changes the
current join style (as in the stroke pallete), where c can only be 0 (butt),1
(round) or 2 (bevel).
ai.lineDash(dash1)
ai.lineDash(dash1,gap1)
ai.lineDash(dash1,gap1,dash2)
ai.lineDash(dash1,gap1,dash2,gap2)
ai.lineDash(dash1,gap1,dash2,gap2,dash3)
ai.lineDash(dash1,gap1,dash2,gap2,dash3,gap3)
Sets the line
dash, where dashes and gaps are synonimous with those on the Stroke pallete.
The "Dashed Line" checkbox will automatically become "checked."
ai.lineSolid()
"Unchecks"
the Dashed Line field on the stroke pallete.
|
|