langs a-z

This commit is contained in:
Ingy döt Net 2013-04-10 22:43:41 -07:00
parent db842d013d
commit d066446780
11389 changed files with 98361 additions and 1020 deletions

View file

@ -0,0 +1,22 @@
let p x y =
let d = sqrt(x ** 2.0 +. y ** 2.0) in
10.0 <= d && d <= 15.0
let () =
Random.self_init();
let rec aux i acc =
if i >= 100 then acc else
let x = (Random.float 40.0) -. 20.0
and y = (Random.float 40.0) -. 20.0 in
if (p x y)
then aux (succ i) ((x,y)::acc)
else aux i acc
in
let points = aux 0 [] in
let g = Array.init 40 (fun _ -> String.make 40 ' ') in
List.iter (fun (x,y) ->
let x = (int_of_float x) + 20
and y = (int_of_float y) + 20 in
g.(y).[x] <- 'o'
) points;
Array.iter print_endline g

View file

@ -0,0 +1,24 @@
crpc()={
my(v=vector(404),t=0,i=0,vx=vy=vector(100));
for(x=1,14,for(y=1,14,
t=x^2+y^2;
if(t>99&t<226,
v[i++]=[x,y];
v[i++]=[x,-y];
v[i++]=[-x,y];
v[i++]=[-x,-y]
)
));
for(x=10,15,
v[i++]=[x,0];
v[i++]=[-x,0];
v[i++]=[0,x];
v[i++]=[0,-x]
);
for(i=1,#vx,
t=v[random(#v)+1];
vx[i]=t[1];
vy[i]=t[2];
);
plothraw(vx,vy)
};

View file

@ -0,0 +1,27 @@
constrain: procedure options (main);
declare 1 point (100),
2 x fixed binary,
2 y fixed binary;
declare (i, j, a, b, c) fixed binary;
j = 0;
do i = 1 to 100;
a = 30*random()-15; b = 30*random()-15;
c = sqrt(a**2 + b**2);
if abs(c) >= 10 & abs(c) <= 15 then
do; j = j + 1; x(j) = a; y(j) = b; end;
end;
/* PLOT */
declare table(-15:15, -15:15) character (1);
table = ' ';
do i = 1 to j;
table(x(i), y(i)) = '*';
end;
do i = -15 to 15;
put skip;
do j = -15 to 15;
put edit (table(i,j)) (a);
end;
end;
end constrain;

View file

@ -0,0 +1,12 @@
my @range = -15..16;
my @points = gather for @range X @range -> $x, $y {
take [$x,$y] if 10 <= sqrt($x*$x+$y*$y) <= 15
}
my @samples = @points.roll(100); # or .pick(100) to get distinct points
# format and print
my %matrix;
for @range X @range -> $x, $y { %matrix{$y}{$x} = ' ' }
%matrix{$_[1]}{$_[0]} = '*' for @samples;
%matrix{$_}{@range}.join(' ').say for @range;

View file

@ -0,0 +1,5 @@
(say ~.map: { $_ // ' ' } for my @matrix) given do
-> [$x, $y] { @matrix[$x][$y] = '*' } for pick 100, do
for ^32 X ^32 -> $x, $y {
[$x,$y] when 100..225 given [+] ($x,$y X- 15) X** 2;
}

View file

@ -0,0 +1,17 @@
CreateImage(0,31,31)
StartDrawing(ImageOutput(0))
For i=1 To 100
Repeat
x=Random(30)-15
y=Random(30)-15
R.f=Sqr(x*x+y*y)
Until 10<=R And R<=15
Plot(x+15,y+15,#Red)
Next
StopDrawing()
Title$="PureBasic Plot"
Flags=#PB_Window_SystemMenu
OpenWindow(0,#PB_Ignore,#PB_Ignore,ImageWidth(0),ImageHeight(0),Title$,Flags)
ImageGadget(0,0,0,ImageWidth(0),ImageHeight(0),ImageID(0))
Repeat: Until WaitWindowEvent()=#PB_Event_CloseWindow

View file

@ -0,0 +1,25 @@
w = 320
h = 320
dim canvas(w,h)
for pts = 1 to 1000
x = (rnd(1) * 31) - 15
y = (rnd(1) * 31) - 15
r = x * x + y * y
if (r > 100) and (r < 225) then
x = int(x * 10 + w/2)
y = int(y * 10 + h/2)
canvas(x,y) = 1
end if
next pts
' -----------------------------
' display the graphic
' -----------------------------
graphic #g, w,h
for x = 1 to w
for y = 1 to h
if canvas(x,y) = 1 then #g "color green ; set "; x; " "; y else #g "color blue ; set "; x; " "; y
next y
next x
render #g
#g "flush"

View file

@ -0,0 +1,26 @@
program main;
bit [39:0] bitmap [40];
class Point;
rand bit signed [4:0] x;
rand bit signed [4:0] y;
constraint on_circle_edge {
(10*10) <= (x*x + y*y);
(x*x + y*y) <= (15*15);
};
function void do_point();
randomize;
bitmap[x+20][y+20] = 1;
endfunction
endclass
initial begin
Point p = new;
repeat (100) p.do_point;
foreach (bitmap[row]) $display( "%b", bitmap[row]);
end
endprogram

View file

@ -0,0 +1,13 @@
include c:\cxpl\codes; \intrinsic 'code' declarations
int X, Y, C, R2;
[SetVid($13); \set 320x200x8 graphics mode
C:= 0; \initialize point counter
repeat X:= Ran(31)-15; \range -15..+15
Y:= Ran(31)-15;
R2:= X*X + Y*Y;
if R2>=10*10 & R2<=15*15 then
[Point(X+160, Y+100, $F); C:= C+1];
until C >= 100;
C:= ChIn(1); \wait for keystroke
SetVid(3); \restore normal text mode
]