Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
|
|
@ -3,3 +3,4 @@ Produce a graphical representation of a [[wp:Sierpinski triangle|Sierpinski tria
|
|||
An example of Sierpinski's triangle (order = 8) looks like this: <br/><br/>
|
||||
[[File:Sierpinski_Triangle_Unicon.PNG]]
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,130 @@
|
|||
use16
|
||||
org 0x7c00
|
||||
|
||||
start:
|
||||
;graphics mode 11h
|
||||
mov ax, 0x0011
|
||||
int 0x10
|
||||
;reserve 8 bytes on the stack
|
||||
;word [bp+6] is the state of the xorshift16 prng
|
||||
;word [bp+2] is the current x position
|
||||
;word [bp+4] is the current y position
|
||||
sub sp, 8
|
||||
mov bp, sp
|
||||
mov cx, [numbers]
|
||||
outerloop:
|
||||
push cx
|
||||
mov word [bp], cx
|
||||
dec word [bp]
|
||||
shl word [bp], 2
|
||||
;seed the random number generator with 1
|
||||
mov word [bp+6], 1
|
||||
;initialize the current position
|
||||
mov word [bp+2], 320
|
||||
mov word [bp+4], 240
|
||||
;run the main loop 65535 times
|
||||
mov cx, 0xffff
|
||||
mainloop0:
|
||||
mov di, 3
|
||||
call rand
|
||||
mov di, ax
|
||||
add di, word [bp]
|
||||
call ave
|
||||
mov di, [bp + 2]
|
||||
mov si, [bp + 4]
|
||||
call pset
|
||||
loop mainloop0
|
||||
pop cx
|
||||
loop outerloop
|
||||
busyloop:
|
||||
jmp $
|
||||
|
||||
ave:
|
||||
push ax
|
||||
push bx
|
||||
push cx
|
||||
push dx
|
||||
shl di, 2
|
||||
mov ax, [corners + di]
|
||||
mov bx, [corners + di + 2]
|
||||
mov cx, [bp + 2]
|
||||
mov dx, [bp + 4]
|
||||
add cx, ax
|
||||
add dx, bx
|
||||
shr cx, 1
|
||||
shr dx, 1
|
||||
mov [bp + 2], cx
|
||||
mov [bp + 4], dx
|
||||
pop dx
|
||||
pop cx
|
||||
pop bx
|
||||
pop ax
|
||||
ret
|
||||
|
||||
rand:
|
||||
push bx
|
||||
push cx
|
||||
push dx
|
||||
mov ax, [bp+6]
|
||||
mov bx, ax
|
||||
shl bx, 7
|
||||
xor ax, bx
|
||||
mov bx, ax
|
||||
shr bx, 9
|
||||
xor ax, bx
|
||||
mov bx, ax
|
||||
shl bx, 8
|
||||
xor ax, bx
|
||||
mov [bp+6], ax
|
||||
xor dx, dx
|
||||
div di
|
||||
mov ax, dx
|
||||
pop dx
|
||||
pop cx
|
||||
pop bx
|
||||
ret
|
||||
|
||||
pset:
|
||||
push ds
|
||||
mov bx, 0xa000
|
||||
mov ds, bx
|
||||
push ax
|
||||
push bx
|
||||
push cx
|
||||
push dx
|
||||
xor dx, dx
|
||||
mov cx, di
|
||||
shr di, 3
|
||||
and cx, 0x07
|
||||
mov bl, 0x80
|
||||
shr bl, cl
|
||||
mov cl, bl
|
||||
mov ax, 80
|
||||
mul si
|
||||
add ax, di
|
||||
mov bx, ax
|
||||
mov al, [bx]
|
||||
or al, cl
|
||||
mov [bx], al
|
||||
pop dx
|
||||
pop cx
|
||||
pop bx
|
||||
pop ax
|
||||
pop ds
|
||||
ret
|
||||
|
||||
;this calculates the number of triangles.
|
||||
numbers:
|
||||
dw ((filler-corners) / 16)
|
||||
;--------------------------------------------------------------
|
||||
;the format for the corners is x1, y1, x2, y2, x3, y3, 4 bytes filler
|
||||
;you can theorically have up to 65536 triangles.
|
||||
;It'll draw them one at a time.
|
||||
;But, you have only 512 bytes. That not enough for 65536 triangles. :(
|
||||
corners:
|
||||
dw 320, 0, 0, 480, 640, 480, 0xffff, 0xffff
|
||||
;just put more triangles here.
|
||||
filler:
|
||||
times 510-($-$$) db 0
|
||||
magic:
|
||||
dw 0xaa55
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
pragma Ada_2022;
|
||||
with Ada.Command_Line; use Ada.Command_Line;
|
||||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
with Easy_Graphics; use Easy_Graphics;
|
||||
|
||||
procedure Sierpinski_Triangle_Graphical is
|
||||
Max_Order : constant Integer := 8;
|
||||
subtype Valid_Order is Integer range 0 .. Max_Order;
|
||||
Length : constant Positive := 2 ** (Max_Order + 1);
|
||||
Order : Valid_Order;
|
||||
Img : Easy_Image := New_Image ((1, 1), (550, 550), BLACK);
|
||||
Turtle : Turtle_Rec := New_Turtle (Img'Unrestricted_Access);
|
||||
|
||||
procedure Sier_Triangle (Order : Valid_Order; Length : Positive) is
|
||||
begin
|
||||
if Order > 0 then
|
||||
for I in 1 .. 3 loop
|
||||
Sier_Triangle (Order - 1, Length / 2);
|
||||
Turtle.Forward (Length);
|
||||
Turtle.Right (120);
|
||||
end loop;
|
||||
end if;
|
||||
end Triangle;
|
||||
|
||||
begin
|
||||
if Argument_Count /= 1 then
|
||||
Put_Line ("Usage: sierpinski_triangle_graphical <order>");
|
||||
Put_Line ("Where: <order> is 0 .. 8");
|
||||
return;
|
||||
end if;
|
||||
Order := Natural'Value (Argument (1));
|
||||
Turtle.Pen_Color (MAGENTA);
|
||||
Turtle.Go_To ((25, 25));
|
||||
Turtle.Pen_Down;
|
||||
Sier_Triangle (Order, Length);
|
||||
Write_GIF (Img, "sierpinski_triangle.gif");
|
||||
end Sierpinski_Triangle_Graphical;
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
require "bitmap"
|
||||
|
||||
local bmp
|
||||
|
||||
local function sierpinski_triangle(level, x, y, size)
|
||||
if level > 0 then
|
||||
local col = color.black
|
||||
bmp:triangle(x, y, x + size, y, x, y + size, col, 1)
|
||||
local size2 = size // 2
|
||||
sierpinski_triangle(level - 1, x, y, size2)
|
||||
sierpinski_triangle(level - 1, x + size2, y, size2)
|
||||
sierpinski_triangle(level - 1, x, y + size2, size2)
|
||||
end
|
||||
end
|
||||
|
||||
local size <const> = 800
|
||||
local level = 8
|
||||
bmp = bitmap.of(size, size, color.white, "Sierpinski Triangle")
|
||||
sierpinski_triangle(level, 20, 20, size - 40)
|
||||
bmp:view()
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
(import srfi/231)
|
||||
|
||||
(define (bit-Kronecker-product A B)
|
||||
;; Assumes that A and B are specialized arrays with u1-storage-class
|
||||
;; i.e., that each array element is zero or one.
|
||||
(array-block! (array-map (lambda (a) (array-map (lambda (b) (* a b)) B)) A)
|
||||
u1-storage-class))
|
||||
|
||||
(define (bit-Kronecker-power A n)
|
||||
;; Assumes n >= 1
|
||||
(do ((i 1 (+ i 1))
|
||||
(result A (bit-Kronecker-product A result)))
|
||||
((= i n) result)))
|
||||
|
||||
(define (write-pbm array file)
|
||||
(with-output-to-file file
|
||||
(lambda ()
|
||||
(let* ((domain (array-domain array))
|
||||
(rows (interval-width domain 0))
|
||||
(columns (interval-width domain 1)))
|
||||
(display "P1") (newline)
|
||||
(display columns) (display " ") (display rows) (newline)
|
||||
(array-for-each (let ((next-pixel-in-line 1))
|
||||
(lambda (p)
|
||||
(write p)
|
||||
(if (zero? (modulo next-pixel-in-line 64)) (newline))
|
||||
(set! next-pixel-in-line (+ 1 next-pixel-in-line))))
|
||||
array)))))
|
||||
|
||||
(write-pbm
|
||||
(bit-Kronecker-power (list*->array 2 '((1 0 0)
|
||||
(1 1 0)
|
||||
(1 1 1))
|
||||
u1-storage-class)
|
||||
5)
|
||||
"sierpinski-triangle-5.pbm")
|
||||
|
|
@ -0,0 +1,120 @@
|
|||
option explicit
|
||||
'outputs turtle graphics to svg file and opens it
|
||||
|
||||
const pi180= 0.01745329251994329576923690768489 ' pi/180
|
||||
const pi=3.1415926535897932384626433832795 'pi
|
||||
class turtle
|
||||
|
||||
dim fso
|
||||
dim fn
|
||||
dim svg
|
||||
|
||||
dim iang 'radians
|
||||
dim ori 'radians
|
||||
dim incr
|
||||
dim pdown
|
||||
dim clr
|
||||
dim x
|
||||
dim y
|
||||
|
||||
public property let orient(n):ori = n*pi180 :end property
|
||||
public property let iangle(n):iang= n*pi180 :end property
|
||||
public sub pd() : pdown=true: end sub
|
||||
public sub pu() :pdown=FALSE :end sub
|
||||
|
||||
public sub rt(i)
|
||||
ori=ori - i*iang:
|
||||
'if ori<0 then ori = ori+pi*2
|
||||
end sub
|
||||
public sub lt(i):
|
||||
ori=(ori + i*iang)
|
||||
'if ori>(pi*2) then ori=ori-pi*2
|
||||
end sub
|
||||
|
||||
public sub bw(l)
|
||||
x= x+ cos(ori+pi)*l*incr
|
||||
y= y+ sin(ori+pi)*l*incr
|
||||
' ori=ori+pi '?????
|
||||
end sub
|
||||
|
||||
public sub fw(l)
|
||||
dim x1,y1
|
||||
x1=x + cos(ori)*l*incr
|
||||
y1=y + sin(ori)*l*incr
|
||||
if pdown then line x,y,x1,y1
|
||||
x=x1:y=y1
|
||||
end sub
|
||||
|
||||
Private Sub Class_Initialize()
|
||||
setlocale "us"
|
||||
initsvg
|
||||
x=400:y=400:incr=100
|
||||
ori=90*pi180
|
||||
iang=90*pi180
|
||||
clr=0
|
||||
pdown=true
|
||||
end sub
|
||||
|
||||
Private Sub Class_Terminate()
|
||||
disply
|
||||
end sub
|
||||
|
||||
private sub line (x,y,x1,y1)
|
||||
svg.WriteLine "<line x1=""" & x & """ y1= """& y & """ x2=""" & x1& """ y2=""" & y1 & """/>"
|
||||
end sub
|
||||
|
||||
private sub disply()
|
||||
dim shell
|
||||
svg.WriteLine "</svg></body></html>"
|
||||
svg.close
|
||||
Set shell = CreateObject("Shell.Application")
|
||||
shell.ShellExecute fn,1,False
|
||||
end sub
|
||||
|
||||
private sub initsvg()
|
||||
dim scriptpath
|
||||
Set fso = CreateObject ("Scripting.Filesystemobject")
|
||||
ScriptPath= Left(WScript.ScriptFullName, InStrRev(WScript.ScriptFullName, "\"))
|
||||
fn=Scriptpath & "SIERP.HTML"
|
||||
Set svg = fso.CreateTextFile(fn,True)
|
||||
if SVG IS nothing then wscript.echo "Can't create svg file" :vscript.quit
|
||||
svg.WriteLine "<!DOCTYPE html>" &vbcrlf & "<html>" &vbcrlf & "<head>"
|
||||
svg.writeline "<style>" & vbcrlf & "line {stroke:rgb(255,0,0);stroke-width:.5}" &vbcrlf &"</style>"
|
||||
svg.writeline "</head>"&vbcrlf & "<body>"
|
||||
svg.WriteLine "<svg xmlns=""http://www.w3.org/2000/svg"" width=""800"" height=""800"" viewBox=""0 0 800 800"">"
|
||||
end sub
|
||||
end class
|
||||
|
||||
|
||||
sub sier(lev,lgth)
|
||||
dim i
|
||||
'wscript.echo lev,lgth
|
||||
if lev=1 then
|
||||
for i=1 to 3
|
||||
x.fw lgth
|
||||
x.lt 2
|
||||
next
|
||||
else
|
||||
sier lev-1,lgth\2
|
||||
x.fw lgth\2
|
||||
sier lev-1,lgth\2
|
||||
x.bw lgth\2
|
||||
x.lt 1
|
||||
x.fw lgth\2
|
||||
x.rt 1
|
||||
sier lev-1,lgth\2
|
||||
x.lt 1
|
||||
x.bw lgth\2
|
||||
x.rt 1
|
||||
end if
|
||||
end sub
|
||||
|
||||
dim x
|
||||
set x=new turtle
|
||||
x.iangle=60
|
||||
x.orient=0
|
||||
x.incr=10
|
||||
x.x=100:x.y=100
|
||||
'star5
|
||||
sier 7,64
|
||||
set x=nothing 'outputs html file to browser
|
||||
Loading…
Add table
Add a link
Reference in a new issue