reorganize examples
This commit is contained in:
12
examples/fib.script
Normal file
12
examples/fib.script
Normal file
@@ -0,0 +1,12 @@
|
||||
x := 1
|
||||
y := 1
|
||||
|
||||
i := 60
|
||||
|
||||
while i {
|
||||
z := x + y
|
||||
y = x
|
||||
x = z
|
||||
print(z)
|
||||
i = i - 1
|
||||
}
|
||||
87
examples/mandelbrot.script
Normal file
87
examples/mandelbrot.script
Normal file
@@ -0,0 +1,87 @@
|
||||
width := 280
|
||||
height := 100
|
||||
|
||||
iterations := 100
|
||||
xmin := -2.0
|
||||
xmax := 0.5
|
||||
ymin := -1.0
|
||||
ymax := 1.0
|
||||
|
||||
// Some further coordinates:
|
||||
/*iterations := 1000
|
||||
xmin := -0.9072945999
|
||||
xmax := -0.8984310833
|
||||
ymin := 0.2304178999
|
||||
ymax := 0.2370858666*/
|
||||
|
||||
/*iterations := 100
|
||||
xmin := -0.193596288
|
||||
xmax := -0.119260320
|
||||
ymin := 1.006960992
|
||||
ymax := 1.062687264*/
|
||||
|
||||
/*iterations := 800
|
||||
xmin := -0.1675326254
|
||||
xmax := -0.1675148625
|
||||
ymin := 1.0413005672
|
||||
ymax := 1.0413138086*/
|
||||
|
||||
/*iterations := 918
|
||||
xmin := -0.7506201104
|
||||
xmax := -0.7503409687
|
||||
ymin := 0.0170447020
|
||||
ymax := 0.0172540583*/
|
||||
|
||||
/*iterations := 400
|
||||
xmin := -0.7548484315
|
||||
xmax := -0.7540548595
|
||||
ymin := 0.0530077004
|
||||
ymax := 0.0536039518*/
|
||||
|
||||
y := 0
|
||||
while y < height {
|
||||
c_im := (float(height - y) / float(height)) * (ymax - ymin) + ymin
|
||||
x := 0
|
||||
while x < width {
|
||||
c_re := (float(x) / float(width)) * (xmax - xmin) + xmin
|
||||
|
||||
z_re := 0.0
|
||||
z_im := 0.0
|
||||
|
||||
it := 0
|
||||
loop := true
|
||||
while it < iterations && loop {
|
||||
/* z = z*z + c */
|
||||
/* (a + bi)^2 = a^2 + 2abi - b^2 */
|
||||
z_re_tmp := z_re * z_re - z_im * z_im + c_re
|
||||
z_im = 2.0 * z_re * z_im + c_im
|
||||
z_re = z_re_tmp
|
||||
|
||||
/* Break if the number shoots off to infinity. */
|
||||
if z_re * z_re + z_im * z_im > 4.0 {
|
||||
loop = false
|
||||
}
|
||||
|
||||
it = it + 1
|
||||
}
|
||||
|
||||
if it <= iterations / 5 {
|
||||
put(' ')
|
||||
} else if it <= iterations / 5 * 2 {
|
||||
put('.')
|
||||
} else if it <= iterations / 5 * 3 {
|
||||
put(',')
|
||||
} else if it <= iterations / 5 * 4 {
|
||||
put('*')
|
||||
} else if it < iterations {
|
||||
put('+')
|
||||
} else if it == iterations {
|
||||
put('#')
|
||||
}
|
||||
|
||||
x = x + 1
|
||||
}
|
||||
put('\n')
|
||||
|
||||
y = y + 1
|
||||
}
|
||||
17
examples/pi.script
Normal file
17
examples/pi.script
Normal file
@@ -0,0 +1,17 @@
|
||||
sum := 0.0
|
||||
k := 0
|
||||
|
||||
iterations := 100
|
||||
|
||||
while k < iterations {
|
||||
k_f := float(k)
|
||||
sum = sum + 1.0 / pow(16.0, k_f) *
|
||||
(4.0 / (8.0 * k_f + 1.0) -
|
||||
2.0 / (8.0 * k_f + 4.0) -
|
||||
1.0 / (8.0 * k_f + 5.0) -
|
||||
1.0 / (8.0 * k_f + 6.0))
|
||||
k = k + 1
|
||||
}
|
||||
|
||||
put("π ≈ ")
|
||||
print(sum)
|
||||
Reference in New Issue
Block a user