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,49 @@
let frames =
{ contents = 0 }
let t_acc =
{ contents = 0 }
let last_t =
{ contents = Sdltimer.get_ticks () }
let print_fps () =
let t = Sdltimer.get_ticks () in
let dt = t - !last_t in
t_acc := !t_acc + dt;
if !t_acc > 1000 then begin
let el_time = !t_acc / 1000 in
Printf.printf
"- fps: %g\n%!"
(float !frames /. float el_time);
t_acc := 0;
frames := 0;
end;
last_t := t
let blit_noise surf =
let ba = Sdlvideo.pixel_data_8 surf in
let dim = Bigarray.Array1.dim ba in
while true do
for i = 0 to pred dim do
ba.{i} <- if Random.bool () then max_int else 0
done;
Sdlvideo.flip surf;
incr frames;
print_fps ()
done
let blit_noise surf =
try blit_noise surf
with _ -> Sdl.quit ()
let () =
Sdl.init [`VIDEO; `TIMER];
Random.self_init();
let surf =
Sdlvideo.set_video_mode
~w:320 ~h:240 ~bpp:8
[(*`HWSURFACE;*) `DOUBLEBUF]
in
Sys.catch_break true;
blit_noise surf

View file

@ -0,0 +1,27 @@
open Graphics
let white = (rgb 255 255 255)
let black = (rgb 0 0 0)
let t_last = ref (Unix.gettimeofday())
let () =
open_graph "";
let width = 320
and height = 240 in
resize_window width height;
try
while true do
for y = 0 to pred height do
for x = 0 to pred width do
set_color (if Random.bool() then white else black);
plot x y
done;
done;
let t = Unix.gettimeofday() in
Printf.printf "- fps: %f\n" (1.0 /. (t -. !t_last));
t_last := t
done
with _ ->
flush stdout;
close_graph ()

View file

@ -0,0 +1,42 @@
Program ImageNoise;
uses
SDL;
var
surface: PSDL_Surface;
pixel: ^byte;
frameNumber, totalTime, lastTime, time, i: longint;
begin
frameNumber := 0;
totalTime := 0;
lastTime := 0;
randomize;
SDL_Init(SDL_INIT_TIMER or SDL_INIT_VIDEO);
surface := SDL_SetVideoMode(320, 240, 8, SDL_DOUBLEBUF or SDL_HWSURFACE);
while (true) do
begin
pixel := surface^.pixels;
SDL_LockSurface(surface);
for i := 1 to (surface^.w * surface^.h) do
begin
pixel^ := random(2)*255;
inc(pixel);
end;
SDL_UnlockSurface(surface);
SDL_Flip(surface);
inc (frameNumber);
time := SDL_GetTicks();
totalTime := totalTime + time - lastTime;
if (totalTime > 1000) then
begin
writeln('FPS: ', frameNumber / (totalTime / 1000.0):5:1);
frameNumber := 0;
totalTime := 0;
end;
lastTime := time;
end;
end.

View file

@ -0,0 +1,36 @@
#filter=0.2 ; Filter parameter for the FPS-calculation
#UpdateFreq=100 ; How often to update the FPS-display
OpenWindow(0,400,300,320,240,"PureBasic")
Define w=WindowWidth(0), h=WindowHeight(0)
Define x, y, T, TOld, FloatingMedium.f, cnt
InitSprite()
OpenWindowedScreen(WindowID(0),0,0,w,h,1,0,0,#PB_Screen_NoSynchronization)
Repeat
StartDrawing(ScreenOutput())
For y=0 To h-1
For x=0 To w-1
If Random(1)
Plot(x,y,#Black)
Else
Plot(x,y,#White)
EndIf
Next
Next
StopDrawing()
FlipBuffers()
cnt+1
If cnt>=#UpdateFreq
cnt =0
TOld=T
T =ElapsedMilliseconds()
FloatingMedium*(1-#filter)+1000*#filter/(T-TOld)
SetWindowTitle(0,"PureBasic: "+StrF(#UpdateFreq*FloatingMedium,2)+" FPS")
Repeat ; Handle all events
Event=WindowEvent()
If Event=#PB_Event_CloseWindow
End
EndIf
Until Not Event
EndIf
ForEver

View file

@ -0,0 +1,13 @@
begSec = time$("seconds")
graphic #g, 320,240
tics = 320 * 240
for i = 1 to tics
x = int((rnd(1) * 320) + 1)
y = int((rnd(1) * 240) + 1)
if int(x mod 2) then #g "color black ; set "; x; " "; y else #g "color white ; set "; x; " "; y
next i
endSec = time$("seconds")
totSec = endSec - begSec
print "Seconds;";totSec;" Count:";tics;" Tics / sec:";tics/totSec;" fps:";1/totSec
render #g
#g "flush"

View file

@ -0,0 +1,131 @@
Imports System.Drawing.Imaging
Public Class frmSnowExercise
Dim bRunning As Boolean = True
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Tell windows we want to handle all the painting and that we want it to double buffer
' the form's rectangle (Double Buffering removes/reduces flickering).
SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or ControlStyles.OptimizedDoubleBuffer, True)
UpdateStyles()
' Prevent the user from resizing the window. Our draw code is not
' setup to recalculate on the fly.
FormBorderStyle = Windows.Forms.FormBorderStyle.FixedSingle
MaximizeBox = False
' The window size and the client rectangle aren't the same.
' To get the proper dimensions for our exercise we need to
' figure out the difference and add it to our 320x240
' requirement.
Width = 320 + Size.Width - ClientSize.Width
Height = 240 + Size.Height - ClientSize.Height
' Pop the window, bring it to the front and give windows time to
' reflect the changes.
Show()
Activate()
Application.DoEvents()
' Hit the loop and keep going until we receive a close request.
RenderLoop()
' We're done. Exit the application.
Close()
End Sub
Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
' Close the application when the user hits escape.
If e.KeyChar = ChrW(Keys.Escape) Then bRunning = False
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
' We'll cancel the form close request if we're still running so we don't get an error during runtime and set the close request flag.
e.Cancel = bRunning
bRunning = False
End Sub
Private Sub RenderLoop()
Const cfPadding As Single = 5.0F
Dim b As New Bitmap(ClientSize.Width, ClientSize.Width, PixelFormat.Format32bppArgb)
Dim g As Graphics = Graphics.FromImage(b)
Dim r As New Random(Now.Millisecond)
Dim oBMPData As BitmapData = Nothing
Dim oPixels() As Integer = Nothing
Dim oBlackWhite() As Integer = {Color.White.ToArgb, Color.Black.ToArgb}
Dim oStopwatch As New Stopwatch
Dim fElapsed As Single = 0.0F
Dim iLoops As Integer = 0
Dim sFPS As String = "0.0 FPS"
Dim oFPSSize As SizeF = g.MeasureString(sFPS, Font)
Dim oFPSBG As RectangleF = New RectangleF(ClientSize.Width - cfPadding - oFPSSize.Width, cfPadding, oFPSSize.Width, oFPSSize.Height)
' Get ourselves a nice, clean, black canvas to work with.
g.Clear(Color.Black)
' Prep our bitmap for a read.
oBMPData = b.LockBits(New Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb)
' Allocate sufficient space for the pixel data and
' flash copy it to our array.
' We want an integer to hold the color for each pixel in the canvas.
Array.Resize(oPixels, b.Width * b.Height)
Runtime.InteropServices.Marshal.Copy(oBMPData.Scan0, oPixels, 0, oPixels.Length)
b.UnlockBits(oBMPData)
' Start looping.
Do
' Find our frame time and add it to the total amount of time
' elapsed since our last FPS update (once per second).
fElapsed += oStopwatch.ElapsedMilliseconds / 1000.0F
oStopwatch.Reset()
oStopwatch.Start()
' Adjust the number of loops since the last whole second has elapsed.
iLoops += 1
If fElapsed >= 1.0F Then
' Since we've now had a whole second elapse
' figure the Frames Per Second,
' measure our string,
' setup our backing rectangle for the FPS string (so it's clearly visible over the snow)
' reset our loop counter
' and our elapsed counter.
sFPS = (iLoops / fElapsed).ToString("0.0") & " FPS"
oFPSSize = g.MeasureString(sFPS, Font)
oFPSBG = New RectangleF(ClientSize.Width - cfPadding - oFPSSize.Width, cfPadding, oFPSSize.Width, oFPSSize.Height)
fElapsed -= 1.0F ' We don't set this to 0 incase our frame time has gone a bit over 1 second since last update.
iLoops = 0
End If
' Generate our snow.
For i As Integer = 0 To oPixels.GetUpperBound(0)
oPixels(i) = oBlackWhite(r.Next(oBlackWhite.Length))
Next
' Prep the bitmap for an update.
oBMPData = b.LockBits(New Rectangle(0, 0, b.Width, b.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb)
' Flash copy the new data into our bitmap.
Runtime.InteropServices.Marshal.Copy(oPixels, 0, oBMPData.Scan0, oPixels.Length)
b.UnlockBits(oBMPData)
' Draw the backing for our FPS display.
g.FillRectangle(Brushes.Black, oFPSBG)
' Draw our FPS.
g.DrawString(sFPS, Font, Brushes.Yellow, oFPSBG.Left, oFPSBG.Top)
' Update the form's background and draw.
BackgroundImage = b
Invalidate(ClientRectangle)
' Let windows handle some queued events.
Application.DoEvents()
Loop While bRunning
End Sub
End Class

View file

@ -0,0 +1,26 @@
include c:\cxpl\codes; \intrinsic 'code' declarations
int CpuReg, \address of CPU register array (from GetReg)
FPS, \frames per second, the display's update rate
Sec, \current second of time (from real-time clock)
SecOld, \previous second of time
X, Y;
[SetVid($101); \set 640x480 graphics
CpuReg:= GetReg; \get address of array to access CPU registers
FPS:= 0;
repeat CpuReg(0):= $0200; \get current time in seconds from BIOS
SoftInt($1A); \software interrupt
Sec:= CpuReg(3)>>8 & $FF; \register DH contains seconds
if Sec = SecOld then \if same as before then
FPS:= FPS+1 \ bump FPS counter
else [SecOld:= Sec; \otherwise save old seconds and
CrLf(6);
IntOut(6, FPS); \ display FPS counter (once per second)
Text(6, " FPS");
FPS:= 0; \ reset FPS counter
];
for Y:= 0, 240-1 do \fill image with random black and white pixels
for X:= 0, 320-1 do
Point(X, Y, if Ran(2) then $F\white\ else 0\black\);
until KeyHit;
SetVid(3); \restore normal text mode
]