March 2014 update

This commit is contained in:
Ingy döt Net 2014-04-02 16:56:35 +00:00
parent 09687c4926
commit a25938f123
1846 changed files with 21876 additions and 5203 deletions

View file

@ -0,0 +1,12 @@
with Display; use Display;
with Display.Basic; use Display.Basic;
procedure Main is
Ball : Shape_Id := New_Circle
(X => 0.0,
Y => 0.0,
Radius => 20.0,
Color => Blue);
begin
null;
end Main;

View file

@ -0,0 +1,57 @@
#NoEnv
SetBatchLines, -1
#SingleInstance, Force
; Uncomment if Gdip.ahk is not in your standard library
#Include, Gdip.ahk
; Settings
X := 200, Y := 200, Width := 200, Height := 200 ; Location and size of sphere
rotation := -30 ; degrees
ARGB := 0xFFFF0000 ; Color=Solid Red
If !pToken := Gdip_Startup() ; Start gdi+
{
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
ExitApp
}
OnExit, Exit
Gui, -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs ; Create GUI
Gui, Show, NA ; Show GUI
hwnd1 := WinExist() ; Get a handle to this window we have created in order to update it later
hbm := CreateDIBSection(A_ScreenWidth, A_ScreenHeight) ; Create a gdi bitmap drawing area
hdc := CreateCompatibleDC() ; Get a device context compatible with the screen
obm := SelectObject(hdc, hbm) ; Select the bitmap into the device context
pGraphics := Gdip_GraphicsFromHDC(hdc) ; Get a pointer to the graphics of the bitmap, for use with drawing functions
Gdip_SetSmoothingMode(pGraphics, 4) ; Set the smoothing mode to antialias = 4 to make shapes appear smother
Gdip_TranslateWorldTransform(pGraphics, X, Y)
Gdip_RotateWorldTransform(pGraphics, rotation)
; Base ellipse
pBrush := Gdip_CreateLineBrushFromRect(0, 0, Width, Height, ARGB, 0xFF000000)
Gdip_FillEllipse(pGraphics, pBrush, 0, 0, Width, Height)
; First highlight ellipse
pBrush := Gdip_CreateLineBrushFromRect(Width*0.1, Height*0.01, Width*0.8, Height*0.6, 0x33FFFFFF, 0x00FFFFFF)
Gdip_FillEllipse(pGraphics, pBrush, Width*0.1, Height*0.01, Width*0.8, Height*0.6)
; Second highlight ellipse
pBrush := Gdip_CreateLineBrushFromRect(Width*0.3, Height*0.02, Width*0.3, Height*0.2, 0xBBFFFFFF, 0x00FFFFFF)
Gdip_FillEllipse(pGraphics, pBrush, Width*0.3, Height*0.02, Width*0.3, Height*0.2)
UpdateLayeredWindow(hwnd1, hdc, 0, 0, A_ScreenWidth, A_ScreenHeight)
SelectObject(hdc, obm) ; Select the object back into the hdc
Gdip_DeletePath(Path)
Gdip_DeleteBrush(pBrush)
DeleteObject(hbm) ; Now the bitmap may be deleted
DeleteDC(hdc) ; Also the device context related to the bitmap may be deleted
Gdip_DeleteGraphics(G) ; The graphics may now be deleted
Return
Exit:
; gdi+ may now be shutdown on exiting the program
Gdip_Shutdown(pToken)
ExitApp

View file

@ -0,0 +1,51 @@
use strict;
use warnings;
my $x = my $y = 255;
$x |= 1; # must be odd
my $depth = 255;
my $light = Vector->new(rand, rand, rand)->normalized;
print "P2\n$x $y\n$depth\n";
my ($r, $ambient) = (($x - 1)/2, 0);
my ($r2) = $r ** 2;
{
for my $x (-$r .. $r) {
my $x2 = $x**2;
for my $y (-$r .. $r) {
my $y2 = $y**2;
my $pixel = 0;
if ($x2 + $y2 < $r2) {
my $v = Vector->new($x, $y, sqrt($r2 - $x2 - $y2))->normalized;
my $I = $light . $v + $ambient;
$I = $I < 0 ? 0 : $I > 1 ? 1 : $I;
$pixel = int($I * $depth);
}
print $pixel;
print $y == $r ? "\n" : " ";
}
}
}
package Vector {
sub new {
my $class = shift;
bless ref($_[0]) eq 'Array' ? $_[0] : [ @_ ], $class;
}
sub normalized {
my $this = shift;
my $norm = sqrt($this . $this);
ref($this)->new( map $_/$norm, @$this );
}
use overload q{.} => sub {
my ($a, $b) = @_;
my $sum = 0;
for (0 .. @$a - 1) {
$sum += $a->[$_] * $b->[$_]
}
return $sum;
},
q{""} => sub { sprintf "Vector:[%s]", join ' ', @{shift()} };
}