[script] Add examples

Add some simple examples to demonstrate CairoScript, courtesy of M Joonas
Philaja.
This commit is contained in:
Chris Wilson 2008-12-10 13:50:23 +00:00
parent 463dc28913
commit 6f284587a4
12 changed files with 1849 additions and 0 deletions

View file

@ -554,6 +554,7 @@ test/pdiff/Makefile
perf/Makefile
util/Makefile
util/cairo-script/Makefile
util/cairo-script/examples/Makefile
util/cairo-trace/Makefile
util/cairo-trace/cairo-trace
doc/Makefile

View file

@ -1,3 +1,5 @@
SUBDIRS = examples
lib_LTLIBRARIES = libcairo-script-interpreter.la
noinst_PROGRAMS = csi-replay csi-exec

View file

@ -0,0 +1,10 @@
EXTRA_DIST = \
dragon.cs \
hilbert.cs \
infinichess.cs \
interference.cs \
pythagoras-tree.cs \
sierpinski.cs \
wedgeAnnulus_crop_ybRings.cs \
world-map.cs \
zrusin.cs

View file

@ -0,0 +1,48 @@
%!CairoScript
/pot { % n -- n
1 sub
dup -1 bitshift or
dup -2 bitshift or
dup -4 bitshift or
dup -8 bitshift or
dup -16 bitshift or
1 add
} bind def
/direction { % i -- bool
dup 2 lt { pop true } {
dup 1 add dup pot dup 3 -1 roll eq { pop pop true } {
2 div 1 sub 2 mul exch sub direction not
} ifelse
} ifelse
} bind def
/path { % cr dx dy -- cr
0 1 2048 {
4 1 roll 3 copy L pop 4 -1 roll direction {
exch neg
} {
neg exch
} ifelse
} for
pop pop
} bind def
dict
/width 512 set
/height 512 set
surface context
1 g set-source paint
//LINE_CAP_ROUND set-line-cap
//LINE_JOIN_ROUND set-line-join
4 set-line-width
256 256 m 12 0 path 0 0 0 rgb set-source stroke
256 256 m -12 0 path 1 0 0 rgb set-source stroke
256 256 m 0 12 path 0 1 0 rgb set-source stroke
256 256 m 0 -12 path 0 0 1 rgb set-source stroke
/target get (out.png) write-to-png pop
pop

View file

@ -0,0 +1,51 @@
%!CairoScript
/hA { % cr dist lvl *hA* cr dist
dup not { pop } {
1 sub
3 copy hB 0 exch L pop
3 copy hA 0 L pop
3 copy hA neg 0 exch L pop
hC
} ifelse
} bind def
/hB { % cr dist lvl *hB* cr dist
dup not { pop } {
1 sub
3 copy hA 0 L pop
3 copy hB 0 exch L pop
3 copy hB neg 0 L pop
hD
} ifelse
} bind def
/hC { % cr dist lvl *hC* cr dist
dup not { pop } {
1 sub
3 copy hD neg 0 L pop
3 copy hC neg 0 exch L pop
3 copy hC 0 L pop
hA
} ifelse
} bind def
/hD { % cr dist lvl *hD* cr dist
dup not { pop } {
1 sub
3 copy hC neg 0 exch L pop
3 copy hD neg 0 L pop
3 copy hD 0 exch L pop
hB
} ifelse
} bind def
dict
/width 1024 set
/height 1024 set
surface context
2 2 m 4 10 hA pop 1 g set-source stroke
/target get (out.png) write-to-png pop
pop

View file

@ -0,0 +1,29 @@
/xdef { exch def } def
/-rot { 3 1 roll } def
/rot { 3 -1 roll } def
/2dup { 2 copy } def
/SIZE 600. def
<< /width SIZE /height SIZE >> surface context
1 1 1 set-source-rgb paint
0 0 0 set-source-rgb
EVEN_ODD set-fill-rule
SIZE SIZE scale
0.5 0 translate
save
1 1 scale
/n 90 def
n neg 1 n {
/x xdef
0 0 m
x 1 l
x 0.5 add 1 l
0 0 l
} for
restore
fill
/target get (out.png) write-to-png pop
pop

View file

@ -0,0 +1,46 @@
/rot { 3 -1 roll } def
/2dup { 2 copy } def
/circle { % context radius -- context
2dup 0 m pop
0 0 rot 0 math.2pi arc h
} def
/circles { % context #circles -- context
1 1 rot { circle } for
} def
/SIDE 600. def
/SIZE 600. def
<< /width SIZE /height SIZE >> surface context
1 1 1 set-source-rgb paint
0 0 0 set-source-rgb
//EVEN_ODD set-fill-rule
/r 4 def
/n SIDE 1.5 mul r div integer def
SIZE SIDE div dup scale
save
302 200 translate
r dup scale
n circles
restore
save
100 300 translate
r dup scale
n circles
restore
save
500 400 translate
r dup scale
n circles
restore
fill
/target get (out.png) write-to-png pop
pop

View file

@ -0,0 +1,53 @@
%!CairoScript
/pi4 0.785398163 def
/sqrt2 1.414213562 def
/R { % cr size *R* cr
dup 1 lt { pop } {
exch /current-point get % size cr x y
4 2 roll % x y size cr
% draw a rectangle in relative co-ordinates
1 index 2 div neg dup exch M
1 index 0 L
0 2 index L
1 index neg 0 L
h
save
1 index dup 2 div neg exch translate
4 2 roll 3 copy % size cr x y cr x y
m
//pi4 rotate
pop 4 2 roll % x y size cr
1 index //sqrt2 div
R
restore
save
1 index dup 2 div exch translate
4 2 roll 3 copy % size cr x y cr x y
m
//pi4 neg rotate
pop 4 2 roll % x y size cr
1 index //sqrt2 div
R
restore
4 1 roll pop pop pop
} ifelse
} bind def
dict
/width 1024 set
/height 512 set
surface context
1 1 1 set-source-rgb paint
0 512 translate 1 -1 scale
512 64 m 128. R 0 0 0 set-source-rgb fill
/target get (out.png) write-to-png pop
pop

View file

@ -0,0 +1,37 @@
%!CairoScript
/1sqrt3 0.577359269 def
/T { % cr size -- cr
exch % size cr
0 0 m 1 index 0 l 1 index dup 2 div exch //1sqrt3 mul l h
exch 2 div
dup 4 ge {
exch % size/2 cr
1 index T
save 1 index 0 translate 1 index T restore
save 1 index dup 2 div exch //1sqrt3 mul translate 1 index T restore
exch
} if
pop
} bind def
dict
/width 512 set
/height 300 set
surface context
1 1 1 set-source-rgb paint
.5 set-line-width
0 300 translate
1 -1 scale
512 T 0 0 0 set-source-rgb stroke
/target get (out.png) write-to-png pop
pop

View file

@ -0,0 +1,30 @@
/SIDE 600 def
<< /width SIDE /height SIDE >> surface context
1 1 1 rgb set-source
paint
SIDE dup scale
0.5 0.5 translate
0.5 -0.5 scale
/theta math.pi 10 div def
10 {
N
0 0 1.0 0 //theta arc
0 0 0.2 //theta 0 arc-
h
//theta rotate
//theta rotate
} repeat
0 0 0.2 0 0 1 radial
0.0 1 1 0 1 add-color-stop
1.0 0 0 1 1 add-color-stop
set-source
fill
/target get (out.png) write-to-png pop
pop

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load diff