Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
7
Task/Image-noise/Ada/image-noise-1.adb
Normal file
7
Task/Image-noise/Ada/image-noise-1.adb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
with Lumen.Image;
|
||||
|
||||
package Noise is
|
||||
|
||||
function Create_Image (Width, Height : Natural) return Lumen.Image.Descriptor;
|
||||
|
||||
end Noise;
|
||||
28
Task/Image-noise/Ada/image-noise-2.adb
Normal file
28
Task/Image-noise/Ada/image-noise-2.adb
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
with Ada.Numerics.Discrete_Random;
|
||||
|
||||
package body Noise is
|
||||
type Color is (Black, White);
|
||||
package Color_Random is new Ada.Numerics.Discrete_Random (Color);
|
||||
Color_Gen : Color_Random.Generator;
|
||||
|
||||
function Create_Image (Width, Height : Natural) return Lumen.Image.Descriptor is
|
||||
Result : Lumen.Image.Descriptor;
|
||||
begin
|
||||
Color_Random.Reset (Color_Gen);
|
||||
Result.Width := Width;
|
||||
Result.Height := Height;
|
||||
Result.Complete := True;
|
||||
Result.Values := new Lumen.Image.Pixel_Matrix (1 .. Width, 1 .. Height);
|
||||
for X in 1 .. Width loop
|
||||
for Y in 1 .. Height loop
|
||||
if Color_Random.Random (Color_Gen) = Black then
|
||||
Result.Values (X, Y) := (R => 0, G => 0, B => 0, A => 0);
|
||||
else
|
||||
Result.Values (X, Y) := (R => 255, G => 255, B => 255, A => 0);
|
||||
end if;
|
||||
end loop;
|
||||
end loop;
|
||||
return Result;
|
||||
end Create_Image;
|
||||
|
||||
end Noise;
|
||||
179
Task/Image-noise/Ada/image-noise-3.adb
Normal file
179
Task/Image-noise/Ada/image-noise-3.adb
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
with Ada.Calendar;
|
||||
with Ada.Text_IO;
|
||||
with System.Address_To_Access_Conversions;
|
||||
with Lumen.Window;
|
||||
with Lumen.Image;
|
||||
with Lumen.Events.Animate;
|
||||
with GL;
|
||||
with Noise;
|
||||
|
||||
procedure Test_Noise is
|
||||
package Float_IO is new Ada.Text_IO.Float_IO (Float);
|
||||
|
||||
Program_End : exception;
|
||||
|
||||
Win : Lumen.Window.Handle;
|
||||
Image : Lumen.Image.Descriptor;
|
||||
Tx_Name : aliased GL.GLuint;
|
||||
Wide : Natural := 320;
|
||||
High : Natural := 240;
|
||||
First_Frame : Ada.Calendar.Time;
|
||||
Frame_Count : Natural := 0;
|
||||
|
||||
-- Create a texture and bind a 2D image to it
|
||||
procedure Create_Texture is
|
||||
use GL;
|
||||
|
||||
package GLB is new System.Address_To_Access_Conversions (GLubyte);
|
||||
|
||||
IP : GLpointer;
|
||||
begin -- Create_Texture
|
||||
-- Allocate a texture name
|
||||
glGenTextures (1, Tx_Name'Unchecked_Access);
|
||||
|
||||
-- Bind texture operations to the newly-created texture name
|
||||
glBindTexture (GL_TEXTURE_2D, Tx_Name);
|
||||
|
||||
-- Select modulate to mix texture with color for shading
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
|
||||
-- Wrap textures at both edges
|
||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
|
||||
-- How the texture behaves when minified and magnified
|
||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
|
||||
-- Create a pointer to the image. This sort of horror show is going to
|
||||
-- be disappearing once Lumen includes its own OpenGL bindings.
|
||||
IP := GLB.To_Pointer (Image.Values.all'Address).all'Unchecked_Access;
|
||||
|
||||
-- Build our texture from the image we loaded earlier
|
||||
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, GLsizei (Image.Width), GLsizei (Image.Height), 0,
|
||||
GL_RGBA, GL_UNSIGNED_BYTE, IP);
|
||||
end Create_Texture;
|
||||
|
||||
-- Set or reset the window view parameters
|
||||
procedure Set_View (W, H : in Natural) is
|
||||
use GL;
|
||||
begin -- Set_View
|
||||
GL.glEnable (GL.GL_TEXTURE_2D);
|
||||
glClearColor (0.8, 0.8, 0.8, 1.0);
|
||||
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glLoadIdentity;
|
||||
glViewport (0, 0, GLsizei (W), GLsizei (H));
|
||||
glOrtho (0.0, GLdouble (W), GLdouble (H), 0.0, -1.0, 1.0);
|
||||
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
glLoadIdentity;
|
||||
end Set_View;
|
||||
|
||||
-- Draw our scene
|
||||
procedure Draw is
|
||||
use GL;
|
||||
begin -- Draw
|
||||
-- clear the screen
|
||||
glClear (GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
|
||||
GL.glBindTexture (GL.GL_TEXTURE_2D, Tx_Name);
|
||||
|
||||
-- fill with a single textured quad
|
||||
glBegin (GL_QUADS);
|
||||
begin
|
||||
glTexCoord2f (1.0, 0.0);
|
||||
glVertex2i (GLint (Wide), 0);
|
||||
|
||||
glTexCoord2f (0.0, 0.0);
|
||||
glVertex2i (0, 0);
|
||||
|
||||
glTexCoord2f (0.0, 1.0);
|
||||
glVertex2i (0, GLint (High));
|
||||
|
||||
glTexCoord2f (1.0, 1.0);
|
||||
glVertex2i (GLint (Wide), GLint (High));
|
||||
end;
|
||||
glEnd;
|
||||
|
||||
-- flush rendering pipeline
|
||||
glFlush;
|
||||
|
||||
-- Now show it
|
||||
Lumen.Window.Swap (Win);
|
||||
end Draw;
|
||||
|
||||
-- Simple event handler routine for keypresses and close-window events
|
||||
procedure Quit_Handler (Event : in Lumen.Events.Event_Data) is
|
||||
begin -- Quit_Handler
|
||||
raise Program_End;
|
||||
end Quit_Handler;
|
||||
|
||||
-- Simple event handler routine for Exposed events
|
||||
procedure Expose_Handler (Event : in Lumen.Events.Event_Data) is
|
||||
pragma Unreferenced (Event);
|
||||
begin -- Expose_Handler
|
||||
Draw;
|
||||
end Expose_Handler;
|
||||
|
||||
-- Simple event handler routine for Resized events
|
||||
procedure Resize_Handler (Event : in Lumen.Events.Event_Data) is
|
||||
begin -- Resize_Handler
|
||||
Wide := Event.Resize_Data.Width;
|
||||
High := Event.Resize_Data.Height;
|
||||
Set_View (Wide, High);
|
||||
Draw;
|
||||
end Resize_Handler;
|
||||
|
||||
procedure Next_Frame (Frame_Delta : in Duration) is
|
||||
pragma Unreferenced (Frame_Delta);
|
||||
use type Ada.Calendar.Time;
|
||||
begin
|
||||
Frame_Count := Frame_Count + 1;
|
||||
if Ada.Calendar.Clock >= First_Frame + 1.0 then
|
||||
Ada.Text_IO.Put ("FPS: ");
|
||||
Float_IO.Put (Float (Frame_Count), 5, 1, 0);
|
||||
Ada.Text_IO.New_Line;
|
||||
First_Frame := Ada.Calendar.Clock;
|
||||
Frame_Count := 0;
|
||||
end if;
|
||||
Image := Noise.Create_Image (Width => Wide, Height => High);
|
||||
Create_Texture;
|
||||
Draw;
|
||||
end Next_Frame;
|
||||
begin
|
||||
-- Create Lumen window, accepting most defaults; turn double buffering off
|
||||
-- for simplicity
|
||||
Lumen.Window.Create (Win => Win,
|
||||
Name => "Noise fractal",
|
||||
Width => Wide,
|
||||
Height => High,
|
||||
Events => (Lumen.Window.Want_Exposure => True,
|
||||
Lumen.Window.Want_Key_Press => True,
|
||||
others => False));
|
||||
|
||||
-- Set up the viewport and scene parameters
|
||||
Set_View (Wide, High);
|
||||
|
||||
-- Now create the texture and set up to use it
|
||||
Image := Noise.Create_Image (Width => Wide, Height => High);
|
||||
Create_Texture;
|
||||
|
||||
First_Frame := Ada.Calendar.Clock;
|
||||
|
||||
-- Enter the event loop
|
||||
declare
|
||||
use Lumen.Events;
|
||||
begin
|
||||
Animate.Select_Events (Win => Win,
|
||||
Calls => (Key_Press => Quit_Handler'Unrestricted_Access,
|
||||
Exposed => Expose_Handler'Unrestricted_Access,
|
||||
Resized => Resize_Handler'Unrestricted_Access,
|
||||
Close_Window => Quit_Handler'Unrestricted_Access,
|
||||
others => No_Callback),
|
||||
FPS => Animate.Flat_Out,
|
||||
Frame => Next_Frame'Unrestricted_Access);
|
||||
end;
|
||||
exception
|
||||
when Program_End =>
|
||||
null;
|
||||
end Test_Noise;
|
||||
|
|
@ -14,40 +14,40 @@ public:
|
|||
myBitmap() : pen( NULL ), brush( NULL ), clr( 0 ), wid( 1 ) {}
|
||||
~myBitmap()
|
||||
{
|
||||
DeleteObject( pen ); DeleteObject( brush );
|
||||
DeleteDC( hdc ); DeleteObject( bmp );
|
||||
DeleteObject( pen ); DeleteObject( brush );
|
||||
DeleteDC( hdc ); DeleteObject( bmp );
|
||||
}
|
||||
|
||||
bool create( int w, int h )
|
||||
{
|
||||
BITMAPINFO bi;
|
||||
ZeroMemory( &bi, sizeof( bi ) );
|
||||
bi.bmiHeader.biSize = sizeof( bi.bmiHeader );
|
||||
bi.bmiHeader.biBitCount = sizeof( DWORD ) * 8;
|
||||
bi.bmiHeader.biCompression = BI_RGB;
|
||||
bi.bmiHeader.biPlanes = 1;
|
||||
bi.bmiHeader.biWidth = w;
|
||||
bi.bmiHeader.biHeight = -h;
|
||||
HDC dc = GetDC( GetConsoleWindow() );
|
||||
bmp = CreateDIBSection( dc, &bi, DIB_RGB_COLORS, &pBits, NULL, 0 );
|
||||
if( !bmp ) return false;
|
||||
hdc = CreateCompatibleDC( dc );
|
||||
SelectObject( hdc, bmp );
|
||||
ReleaseDC( GetConsoleWindow(), dc );
|
||||
width = w; height = h;
|
||||
return true;
|
||||
BITMAPINFO bi;
|
||||
ZeroMemory( &bi, sizeof( bi ) );
|
||||
bi.bmiHeader.biSize = sizeof( bi.bmiHeader );
|
||||
bi.bmiHeader.biBitCount = sizeof( DWORD ) * 8;
|
||||
bi.bmiHeader.biCompression = BI_RGB;
|
||||
bi.bmiHeader.biPlanes = 1;
|
||||
bi.bmiHeader.biWidth = w;
|
||||
bi.bmiHeader.biHeight = -h;
|
||||
HDC dc = GetDC( GetConsoleWindow() );
|
||||
bmp = CreateDIBSection( dc, &bi, DIB_RGB_COLORS, &pBits, NULL, 0 );
|
||||
if( !bmp ) return false;
|
||||
hdc = CreateCompatibleDC( dc );
|
||||
SelectObject( hdc, bmp );
|
||||
ReleaseDC( GetConsoleWindow(), dc );
|
||||
width = w; height = h;
|
||||
return true;
|
||||
}
|
||||
|
||||
void clear( BYTE clr = 0 )
|
||||
{
|
||||
memset( pBits, clr, width * height * sizeof( DWORD ) );
|
||||
memset( pBits, clr, width * height * sizeof( DWORD ) );
|
||||
}
|
||||
|
||||
void setBrushColor( DWORD bClr )
|
||||
{
|
||||
if( brush ) DeleteObject( brush );
|
||||
brush = CreateSolidBrush( bClr );
|
||||
SelectObject( hdc, brush );
|
||||
if( brush ) DeleteObject( brush );
|
||||
brush = CreateSolidBrush( bClr );
|
||||
SelectObject( hdc, brush );
|
||||
}
|
||||
|
||||
void setPenColor( DWORD c ) { clr = c; createPen(); }
|
||||
|
|
@ -55,34 +55,34 @@ public:
|
|||
|
||||
void saveBitmap( string path )
|
||||
{
|
||||
BITMAPFILEHEADER fileheader;
|
||||
BITMAPINFO infoheader;
|
||||
BITMAP bitmap;
|
||||
DWORD wb;
|
||||
BITMAPFILEHEADER fileheader;
|
||||
BITMAPINFO infoheader;
|
||||
BITMAP bitmap;
|
||||
DWORD wb;
|
||||
|
||||
GetObject( bmp, sizeof( bitmap ), &bitmap );
|
||||
DWORD* dwpBits = new DWORD[bitmap.bmWidth * bitmap.bmHeight];
|
||||
ZeroMemory( dwpBits, bitmap.bmWidth * bitmap.bmHeight * sizeof( DWORD ) );
|
||||
ZeroMemory( &infoheader, sizeof( BITMAPINFO ) );
|
||||
ZeroMemory( &fileheader, sizeof( BITMAPFILEHEADER ) );
|
||||
infoheader.bmiHeader.biBitCount = sizeof( DWORD ) * 8;
|
||||
infoheader.bmiHeader.biCompression = BI_RGB;
|
||||
infoheader.bmiHeader.biPlanes = 1;
|
||||
infoheader.bmiHeader.biSize = sizeof( infoheader.bmiHeader );
|
||||
infoheader.bmiHeader.biHeight = bitmap.bmHeight;
|
||||
infoheader.bmiHeader.biWidth = bitmap.bmWidth;
|
||||
infoheader.bmiHeader.biSizeImage = bitmap.bmWidth * bitmap.bmHeight * sizeof( DWORD );
|
||||
fileheader.bfType = 0x4D42;
|
||||
fileheader.bfOffBits = sizeof( infoheader.bmiHeader ) + sizeof( BITMAPFILEHEADER );
|
||||
fileheader.bfSize = fileheader.bfOffBits + infoheader.bmiHeader.biSizeImage;
|
||||
GetDIBits( hdc, bmp, 0, height, ( LPVOID )dwpBits, &infoheader, DIB_RGB_COLORS );
|
||||
HANDLE file = CreateFile( path.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
|
||||
WriteFile( file, &fileheader, sizeof( BITMAPFILEHEADER ), &wb, NULL );
|
||||
WriteFile( file, &infoheader.bmiHeader, sizeof( infoheader.bmiHeader ), &wb, NULL );
|
||||
WriteFile( file, dwpBits, bitmap.bmWidth * bitmap.bmHeight * 4, &wb, NULL );
|
||||
CloseHandle( file );
|
||||
GetObject( bmp, sizeof( bitmap ), &bitmap );
|
||||
DWORD* dwpBits = new DWORD[bitmap.bmWidth * bitmap.bmHeight];
|
||||
ZeroMemory( dwpBits, bitmap.bmWidth * bitmap.bmHeight * sizeof( DWORD ) );
|
||||
ZeroMemory( &infoheader, sizeof( BITMAPINFO ) );
|
||||
ZeroMemory( &fileheader, sizeof( BITMAPFILEHEADER ) );
|
||||
infoheader.bmiHeader.biBitCount = sizeof( DWORD ) * 8;
|
||||
infoheader.bmiHeader.biCompression = BI_RGB;
|
||||
infoheader.bmiHeader.biPlanes = 1;
|
||||
infoheader.bmiHeader.biSize = sizeof( infoheader.bmiHeader );
|
||||
infoheader.bmiHeader.biHeight = bitmap.bmHeight;
|
||||
infoheader.bmiHeader.biWidth = bitmap.bmWidth;
|
||||
infoheader.bmiHeader.biSizeImage = bitmap.bmWidth * bitmap.bmHeight * sizeof( DWORD );
|
||||
fileheader.bfType = 0x4D42;
|
||||
fileheader.bfOffBits = sizeof( infoheader.bmiHeader ) + sizeof( BITMAPFILEHEADER );
|
||||
fileheader.bfSize = fileheader.bfOffBits + infoheader.bmiHeader.biSizeImage;
|
||||
GetDIBits( hdc, bmp, 0, height, ( LPVOID )dwpBits, &infoheader, DIB_RGB_COLORS );
|
||||
HANDLE file = CreateFile( path.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
|
||||
WriteFile( file, &fileheader, sizeof( BITMAPFILEHEADER ), &wb, NULL );
|
||||
WriteFile( file, &infoheader.bmiHeader, sizeof( infoheader.bmiHeader ), &wb, NULL );
|
||||
WriteFile( file, dwpBits, bitmap.bmWidth * bitmap.bmHeight * 4, &wb, NULL );
|
||||
CloseHandle( file );
|
||||
|
||||
delete [] dwpBits;
|
||||
delete [] dwpBits;
|
||||
}
|
||||
|
||||
void* getBits( void ) const { return pBits; }
|
||||
|
|
@ -93,9 +93,9 @@ public:
|
|||
private:
|
||||
void createPen()
|
||||
{
|
||||
if( pen ) DeleteObject( pen );
|
||||
pen = CreatePen( PS_SOLID, wid, clr );
|
||||
SelectObject( hdc, pen );
|
||||
if( pen ) DeleteObject( pen );
|
||||
pen = CreatePen( PS_SOLID, wid, clr );
|
||||
SelectObject( hdc, pen );
|
||||
}
|
||||
|
||||
HBITMAP bmp;
|
||||
|
|
@ -112,43 +112,43 @@ class bmpNoise
|
|||
public:
|
||||
bmpNoise()
|
||||
{
|
||||
QueryPerformanceFrequency( &_frequency );
|
||||
_bmp.create( BMP_WID, BMP_HEI );
|
||||
_frameTime = _fps = 0; _start = getTime(); _frames = 0;
|
||||
QueryPerformanceFrequency( &_frequency );
|
||||
_bmp.create( BMP_WID, BMP_HEI );
|
||||
_frameTime = _fps = 0; _start = getTime(); _frames = 0;
|
||||
}
|
||||
|
||||
void mainLoop()
|
||||
{
|
||||
float now = getTime();
|
||||
if( now - _start > 1.0f ) { _fps = static_cast<float>( _frames ) / ( now - _start ); _start = now; _frames = 0; }
|
||||
HDC wdc, dc = _bmp.getDC();
|
||||
unsigned int* bits = reinterpret_cast<unsigned int*>( _bmp.getBits() );
|
||||
float now = getTime();
|
||||
if( now - _start > 1.0f ) { _fps = static_cast<float>( _frames ) / ( now - _start ); _start = now; _frames = 0; }
|
||||
HDC wdc, dc = _bmp.getDC();
|
||||
unsigned int* bits = reinterpret_cast<unsigned int*>( _bmp.getBits() );
|
||||
|
||||
for( int y = 0; y < BMP_HEI; y++ )
|
||||
{
|
||||
for( int x = 0; x < BMP_WID; x++ )
|
||||
{
|
||||
if( rand() % 10 < 5 ) memset( bits, 255, 3 );
|
||||
else memset( bits, 0, 3 );
|
||||
bits++;
|
||||
}
|
||||
}
|
||||
ostringstream o; o << _fps; TextOut( dc, 0, 0, o.str().c_str(), o.str().size() );
|
||||
for( int y = 0; y < BMP_HEI; y++ )
|
||||
{
|
||||
for( int x = 0; x < BMP_WID; x++ )
|
||||
{
|
||||
if( rand() % 10 < 5 ) memset( bits, 255, 3 );
|
||||
else memset( bits, 0, 3 );
|
||||
bits++;
|
||||
}
|
||||
}
|
||||
ostringstream o; o << _fps; TextOut( dc, 0, 0, o.str().c_str(), o.str().size() );
|
||||
|
||||
wdc = GetDC( _hwnd );
|
||||
BitBlt( wdc, 0, 0, BMP_WID, BMP_HEI, dc, 0, 0, SRCCOPY );
|
||||
ReleaseDC( _hwnd, wdc );
|
||||
_frames++; _frameTime = getTime() - now;
|
||||
if( _frameTime > 1.0f ) _frameTime = 1.0f;
|
||||
wdc = GetDC( _hwnd );
|
||||
BitBlt( wdc, 0, 0, BMP_WID, BMP_HEI, dc, 0, 0, SRCCOPY );
|
||||
ReleaseDC( _hwnd, wdc );
|
||||
_frames++; _frameTime = getTime() - now;
|
||||
if( _frameTime > 1.0f ) _frameTime = 1.0f;
|
||||
}
|
||||
|
||||
|
||||
void setHWND( HWND hwnd ) { _hwnd = hwnd; }
|
||||
|
||||
private:
|
||||
float getTime()
|
||||
{
|
||||
LARGE_INTEGER liTime; QueryPerformanceCounter( &liTime );
|
||||
return liTime.QuadPart / ( float )_frequency.QuadPart;
|
||||
LARGE_INTEGER liTime; QueryPerformanceCounter( &liTime );
|
||||
return liTime.QuadPart / ( float )_frequency.QuadPart;
|
||||
}
|
||||
myBitmap _bmp;
|
||||
HWND _hwnd;
|
||||
|
|
@ -163,57 +163,57 @@ public:
|
|||
wnd() { _inst = this; }
|
||||
int wnd::Run( HINSTANCE hInst )
|
||||
{
|
||||
_hInst = hInst; _hwnd = InitAll();
|
||||
_hInst = hInst; _hwnd = InitAll();
|
||||
_noise.setHWND( _hwnd );
|
||||
ShowWindow( _hwnd, SW_SHOW );
|
||||
UpdateWindow( _hwnd );
|
||||
ShowWindow( _hwnd, SW_SHOW );
|
||||
UpdateWindow( _hwnd );
|
||||
|
||||
MSG msg;
|
||||
ZeroMemory( &msg, sizeof( msg ) );
|
||||
while( msg.message != WM_QUIT )
|
||||
{
|
||||
if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) != 0 )
|
||||
{
|
||||
TranslateMessage( &msg );
|
||||
DispatchMessage( &msg );
|
||||
}
|
||||
else
|
||||
{
|
||||
_noise.mainLoop();
|
||||
}
|
||||
}
|
||||
return UnregisterClass( "_MY_NOISE_", _hInst );
|
||||
MSG msg;
|
||||
ZeroMemory( &msg, sizeof( msg ) );
|
||||
while( msg.message != WM_QUIT )
|
||||
{
|
||||
if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) != 0 )
|
||||
{
|
||||
TranslateMessage( &msg );
|
||||
DispatchMessage( &msg );
|
||||
}
|
||||
else
|
||||
{
|
||||
_noise.mainLoop();
|
||||
}
|
||||
}
|
||||
return UnregisterClass( "_MY_NOISE_", _hInst );
|
||||
}
|
||||
private:
|
||||
static int WINAPI wnd::WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
|
||||
{
|
||||
switch( msg )
|
||||
{
|
||||
case WM_DESTROY: PostQuitMessage( 0 ); break;
|
||||
default:
|
||||
return DefWindowProc( hWnd, msg, wParam, lParam );
|
||||
}
|
||||
return 0;
|
||||
switch( msg )
|
||||
{
|
||||
case WM_DESTROY: PostQuitMessage( 0 ); break;
|
||||
default:
|
||||
return DefWindowProc( hWnd, msg, wParam, lParam );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
HWND InitAll()
|
||||
{
|
||||
WNDCLASSEX wcex;
|
||||
ZeroMemory( &wcex, sizeof( wcex ) );
|
||||
wcex.cbSize = sizeof( WNDCLASSEX );
|
||||
wcex.style = CS_HREDRAW | CS_VREDRAW;
|
||||
wcex.lpfnWndProc = ( WNDPROC )WndProc;
|
||||
wcex.hInstance = _hInst;
|
||||
wcex.hCursor = LoadCursor( NULL, IDC_ARROW );
|
||||
wcex.hbrBackground = ( HBRUSH )( COLOR_WINDOW + 1 );
|
||||
wcex.lpszClassName = "_MY_NOISE_";
|
||||
WNDCLASSEX wcex;
|
||||
ZeroMemory( &wcex, sizeof( wcex ) );
|
||||
wcex.cbSize = sizeof( WNDCLASSEX );
|
||||
wcex.style = CS_HREDRAW | CS_VREDRAW;
|
||||
wcex.lpfnWndProc = ( WNDPROC )WndProc;
|
||||
wcex.hInstance = _hInst;
|
||||
wcex.hCursor = LoadCursor( NULL, IDC_ARROW );
|
||||
wcex.hbrBackground = ( HBRUSH )( COLOR_WINDOW + 1 );
|
||||
wcex.lpszClassName = "_MY_NOISE_";
|
||||
|
||||
RegisterClassEx( &wcex );
|
||||
RegisterClassEx( &wcex );
|
||||
|
||||
RECT rc = { 0, 0, BMP_WID, BMP_HEI };
|
||||
AdjustWindowRect( &rc, WS_SYSMENU | WS_CAPTION, FALSE );
|
||||
int w = rc.right - rc.left, h = rc.bottom - rc.top;
|
||||
return CreateWindow( "_MY_NOISE_", ".: Noise image -- PJorente :.", WS_SYSMENU, CW_USEDEFAULT, 0, w, h, NULL, NULL, _hInst, NULL );
|
||||
RECT rc = { 0, 0, BMP_WID, BMP_HEI };
|
||||
AdjustWindowRect( &rc, WS_SYSMENU | WS_CAPTION, FALSE );
|
||||
int w = rc.right - rc.left, h = rc.bottom - rc.top;
|
||||
return CreateWindow( "_MY_NOISE_", ".: Noise image -- PJorente :.", WS_SYSMENU, CW_USEDEFAULT, 0, w, h, NULL, NULL, _hInst, NULL );
|
||||
}
|
||||
|
||||
static wnd* _inst;
|
||||
|
|
|
|||
|
|
@ -11,37 +11,37 @@ time_t start, last;
|
|||
|
||||
void render()
|
||||
{
|
||||
static int frame = 0, bits[slen];
|
||||
register int i = slen, r;
|
||||
time_t t;
|
||||
static int frame = 0, bits[slen];
|
||||
register int i = slen, r;
|
||||
time_t t;
|
||||
|
||||
r = bits[0] + 1;
|
||||
while (i--) r *= 1103515245, bits[i] = r ^ (bits[i] >> 16);
|
||||
r = bits[0] + 1;
|
||||
while (i--) r *= 1103515245, bits[i] = r ^ (bits[i] >> 16);
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glBitmap(W, H, 0, 0, 0, 0, (void*)bits);
|
||||
glFlush();
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glBitmap(W, H, 0, 0, 0, 0, (void*)bits);
|
||||
glFlush();
|
||||
|
||||
if (!(++frame & 15)) {
|
||||
if ((t = time(0)) > last) {
|
||||
last = t;
|
||||
printf("\rfps: %ld ", frame / (t - start));
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
if (!(++frame & 15)) {
|
||||
if ((t = time(0)) > last) {
|
||||
last = t;
|
||||
printf("\rfps: %ld ", frame / (t - start));
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
glutInit(&argc, argv);
|
||||
glutInitDisplayMode(GLUT_INDEX);
|
||||
glutInitWindowSize(W, H);
|
||||
glutCreateWindow("noise");
|
||||
glutDisplayFunc(render);
|
||||
glutIdleFunc(render);
|
||||
glutInit(&argc, argv);
|
||||
glutInitDisplayMode(GLUT_INDEX);
|
||||
glutInitWindowSize(W, H);
|
||||
glutCreateWindow("noise");
|
||||
glutDisplayFunc(render);
|
||||
glutIdleFunc(render);
|
||||
|
||||
last = start = time(0);
|
||||
last = start = time(0);
|
||||
|
||||
glutMainLoop();
|
||||
return 0;
|
||||
glutMainLoop();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,37 +3,37 @@
|
|||
(defun draw-noise (surface)
|
||||
"draws noise on the surface. Returns the surface"
|
||||
(let ((width (sdl:width surface))
|
||||
(height (sdl:height surface))
|
||||
(i-white (sdl:map-color sdl:*white* surface))
|
||||
(i-black (sdl:map-color sdl:*black* surface)))
|
||||
(height (sdl:height surface))
|
||||
(i-white (sdl:map-color sdl:*white* surface))
|
||||
(i-black (sdl:map-color sdl:*black* surface)))
|
||||
(sdl-base::with-pixel (s (sdl:fp surface))
|
||||
(dotimes (h height)
|
||||
(dotimes (w width)
|
||||
(sdl-base::write-pixel s w h (if (zerop (random 2))
|
||||
i-white i-black ))))))
|
||||
(dotimes (w width)
|
||||
(sdl-base::write-pixel s w h (if (zerop (random 2))
|
||||
i-white i-black ))))))
|
||||
surface)
|
||||
|
||||
(defun draw-fps (surface)
|
||||
"draws fps text-info on surface. Returns surface"
|
||||
(sdl:with-surface (s surface)
|
||||
(sdl:draw-string-solid-* (format nil "FPS: ~,3f" (sdl:average-fps))
|
||||
20 20 :surface s :color sdl:*magenta*)))
|
||||
20 20 :surface s :color sdl:*magenta*)))
|
||||
|
||||
(defun main ()
|
||||
"main function, initializes the library and creates de display window"
|
||||
(setf *random-state* (make-random-state))
|
||||
(sdl:with-init (SDL:SDL-INIT-VIDEO SDL:SDL-INIT-TIMER)
|
||||
(let ((main-window (sdl:window 320 240
|
||||
:title-caption "noise_sdl.lisp"
|
||||
:bpp 8
|
||||
:flags (logior SDL:SDL-DOUBLEBUF SDL:SDL-HW-SURFACE)
|
||||
:fps (make-instance 'sdl:fps-unlocked))))
|
||||
:title-caption "noise_sdl.lisp"
|
||||
:bpp 8
|
||||
:flags (logior SDL:SDL-DOUBLEBUF SDL:SDL-HW-SURFACE)
|
||||
:fps (make-instance 'sdl:fps-unlocked))))
|
||||
(sdl:initialise-default-font)
|
||||
(sdl:with-events ()
|
||||
(:idle ()
|
||||
(sdl:update-display (draw-fps (draw-noise main-window))))
|
||||
(:video-expose-event ()
|
||||
(sdl:update-display))
|
||||
(:quit-event () T)))))
|
||||
(:idle ()
|
||||
(sdl:update-display (draw-fps (draw-noise main-window))))
|
||||
(:video-expose-event ()
|
||||
(sdl:update-display))
|
||||
(:quit-event () T)))))
|
||||
|
||||
(main)
|
||||
|
|
|
|||
|
|
@ -14,6 +14,6 @@ on animate
|
|||
.
|
||||
col[] = [ 000 999 ]
|
||||
for x = 0 to 319 : for y = 0 to 199
|
||||
pset x y col[random 2]
|
||||
pset x y col[random 1 2]
|
||||
.
|
||||
.
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
\ Bindings to SDL2 functions
|
||||
s" SDL2" add-lib
|
||||
\c #include <SDL2/SDL.h>
|
||||
c-function sdl-init SDL_Init n -- n
|
||||
c-function sdl-quit SDL_Quit -- void
|
||||
c-function sdl-init SDL_Init n -- n
|
||||
c-function sdl-quit SDL_Quit -- void
|
||||
c-function sdl-createwindow SDL_CreateWindow a n n n n n -- a
|
||||
c-function sdl-createrenderer SDL_CreateRenderer a n n -- a
|
||||
c-function sdl-setdrawcolor SDL_SetRenderDrawColor a n n n n -- n
|
||||
|
|
|
|||
|
|
@ -2,32 +2,32 @@ try destroydialog testRollout catch ()
|
|||
|
||||
fn randomBitmap width height =
|
||||
(
|
||||
local newBmp = bitmap width height
|
||||
local newBmp = bitmap width height
|
||||
|
||||
for row = 0 to (height-1) do
|
||||
(
|
||||
local pixels = for i in 1 to width collect (white*random 0 1)
|
||||
setpixels newBmp [0,row] pixels
|
||||
)
|
||||
for row = 0 to (height-1) do
|
||||
(
|
||||
local pixels = for i in 1 to width collect (white*random 0 1)
|
||||
setpixels newBmp [0,row] pixels
|
||||
)
|
||||
|
||||
return newBmp
|
||||
return newBmp
|
||||
)
|
||||
|
||||
rollout testRollout "Test" width:320 height:240
|
||||
(
|
||||
bitmap image width:320 height:240 pos:[0,0]
|
||||
timer updateTimer interval:1 active:true
|
||||
bitmap image width:320 height:240 pos:[0,0]
|
||||
timer updateTimer interval:1 active:true
|
||||
|
||||
on updateTimer tick do
|
||||
(
|
||||
local startTime = timestamp()
|
||||
image.bitmap = randomBitmap 320 240
|
||||
local endTime = timestamp()
|
||||
local fps = ((endTime-startTime)/1000.0)*60.0
|
||||
on updateTimer tick do
|
||||
(
|
||||
local startTime = timestamp()
|
||||
image.bitmap = randomBitmap 320 240
|
||||
local endTime = timestamp()
|
||||
local fps = ((endTime-startTime)/1000.0)*60.0
|
||||
|
||||
if mod updatetimer.ticks 10 == 0 do (testRollout.title = ("Test (FPS: "+fps as string+")"))
|
||||
if mod updatetimer.ticks 10 == 0 do (testRollout.title = ("Test (FPS: "+fps as string+")"))
|
||||
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
createdialog testrollout
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@ cellSize = [960/width, 600/height]
|
|||
colors = [color.black, color.white]
|
||||
|
||||
newImg = function
|
||||
img = Image.create(tileSetLength, 1)
|
||||
for i in range(0, tileSetLength - 1)
|
||||
img.setPixel i, 0, colors[rnd * 2]
|
||||
end for
|
||||
return img
|
||||
img = Image.create(tileSetLength, 1)
|
||||
for i in range(0, tileSetLength - 1)
|
||||
img.setPixel i, 0, colors[rnd * 2]
|
||||
end for
|
||||
return img
|
||||
end function
|
||||
|
||||
display(5).mode = displayMode.tile
|
||||
|
|
@ -19,19 +19,19 @@ td.cellSize = cellSize
|
|||
td.extent = [width, height]
|
||||
td.tileSetTileSize = 1
|
||||
for x in range(0, width - 1)
|
||||
for y in range(0, height - 1)
|
||||
td.setCell x, y, rnd * tileSetLength
|
||||
end for
|
||||
for y in range(0, height - 1)
|
||||
td.setCell x, y, rnd * tileSetLength
|
||||
end for
|
||||
end for
|
||||
frames = 0
|
||||
startTime = time
|
||||
while true
|
||||
td.tileSet = newImg
|
||||
frames += 1
|
||||
dt = time - startTime
|
||||
if dt >= 1 then
|
||||
text.row = 25; print "FPS: " + round(frames / dt, 2)
|
||||
frames = 0
|
||||
startTime = time
|
||||
end if
|
||||
td.tileSet = newImg
|
||||
frames += 1
|
||||
dt = time - startTime
|
||||
if dt >= 1 then
|
||||
text.row = 25; print "FPS: " + round(frames / dt, 2)
|
||||
frames = 0
|
||||
startTime = time
|
||||
end if
|
||||
end while
|
||||
|
|
|
|||
26
Task/Image-noise/Odin/image-noise.odin
Normal file
26
Task/Image-noise/Odin/image-noise.odin
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
package main
|
||||
|
||||
import rl "vendor:raylib"
|
||||
|
||||
main :: proc() {
|
||||
rl.InitWindow(320, 240, "Rosetta Code - Image noise")
|
||||
|
||||
for !rl.WindowShouldClose() {
|
||||
img := rl.GenImageWhiteNoise(320, 240, .25)
|
||||
|
||||
tex := rl.LoadTextureFromImage(img)
|
||||
|
||||
rl.UnloadImage(img)
|
||||
|
||||
rl.BeginDrawing()
|
||||
|
||||
rl.DrawTextureV(tex, {}, rl.WHITE)
|
||||
rl.DrawFPS(4, 4)
|
||||
|
||||
rl.EndDrawing()
|
||||
|
||||
rl.UnloadTexture(tex)
|
||||
}
|
||||
|
||||
rl.CloseWindow()
|
||||
}
|
||||
72
Task/Image-noise/Rebol/image-noise.rebol
Normal file
72
Task/Image-noise/Rebol/image-noise.rebol
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
Rebol [
|
||||
title: "Rosetta code: Image noise"
|
||||
file: %Image_noise.r3
|
||||
url: https://rosettacode.org/wiki/Image_noise
|
||||
needs: 3.15.0 ; or something like that
|
||||
note: {
|
||||
This script so far works only on Windows.
|
||||
GUI is still under development.
|
||||
}
|
||||
]
|
||||
|
||||
img: make image! 320x240
|
||||
|
||||
;; Naive pixel randomization.
|
||||
draw-frame: does [
|
||||
forall img [
|
||||
img/1: random/only [0.0.0 255.255.255]
|
||||
]
|
||||
]
|
||||
;; Show FPS in the console.
|
||||
update-fps: function/with [][
|
||||
frame-count: frame-count + 1
|
||||
current-time: now/time/precise
|
||||
elapsed: to decimal! current-time - last-time
|
||||
if elapsed >= 1 [
|
||||
fps: round/to frame-count / elapsed 1
|
||||
last-time: current-time
|
||||
frame-count: 0
|
||||
prin ["^MFPS:" fps ""]
|
||||
]
|
||||
][
|
||||
fps: frame-count: 0
|
||||
last-time: now/time/precise
|
||||
]
|
||||
|
||||
gui?: on
|
||||
either all [function? :view gui?] [
|
||||
;; Open the window and register an event handler to detect closing it.
|
||||
gob: make gob! [image: img]
|
||||
win: view/no-wait gob
|
||||
handle-events [
|
||||
name: 'view-test
|
||||
priority: 100
|
||||
handler: func [event] [
|
||||
if switch event/type [
|
||||
close [true]
|
||||
key [event/key = escape]
|
||||
][
|
||||
unhandle-events self
|
||||
unview event/window
|
||||
visible?: false
|
||||
]
|
||||
none
|
||||
]
|
||||
]
|
||||
visible?: true
|
||||
print "Press ESC to exit."
|
||||
while [visible?][
|
||||
draw-frame
|
||||
show win
|
||||
update-fps
|
||||
wait 0.001
|
||||
]
|
||||
unview win
|
||||
][
|
||||
;; When GUI is not available, just update the image a few times.
|
||||
loop 500 [
|
||||
draw-frame
|
||||
update-fps
|
||||
]
|
||||
]
|
||||
print ""
|
||||
|
|
@ -3,11 +3,11 @@ package require Tk
|
|||
proc generate {img width height} {
|
||||
set data {}
|
||||
for {set i 0} {$i<$height} {incr i} {
|
||||
set line {}
|
||||
for {set j 0} {$j<$width} {incr j} {
|
||||
lappend line [lindex "#000000 #FFFFFF" [expr {rand() < 0.5}]]
|
||||
}
|
||||
lappend data $line
|
||||
set line {}
|
||||
for {set j 0} {$j<$width} {incr j} {
|
||||
lappend line [lindex "#000000 #FFFFFF" [expr {rand() < 0.5}]]
|
||||
}
|
||||
lappend data $line
|
||||
}
|
||||
$img put $data
|
||||
}
|
||||
|
|
@ -20,11 +20,11 @@ proc looper {} {
|
|||
set t [lindex [time {generate noise 320 240}] 0]
|
||||
set time [expr {$time + $t}]
|
||||
if {[incr count] >= 30} {
|
||||
set time [expr {$time / 1000000.0}]
|
||||
set fps [expr {$count / $time}]
|
||||
puts [format "%d frames in %3.2f seconds (%f FPS)" $count $time $fps]
|
||||
set time 0.0
|
||||
set count 0
|
||||
set time [expr {$time / 1000000.0}]
|
||||
set fps [expr {$count / $time}]
|
||||
puts [format "%d frames in %3.2f seconds (%f FPS)" $count $time $fps]
|
||||
set time 0.0
|
||||
set count 0
|
||||
}
|
||||
after 1 looper
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,29 @@
|
|||
forever:
|
||||
ld hl,frametimer
|
||||
ld a,(hl)
|
||||
rrca
|
||||
rrca
|
||||
rrca
|
||||
xor (hl) ;crude xorshift rng used to select a "random" location to draw to.
|
||||
ld hl,frametimer
|
||||
ld a,(hl)
|
||||
rrca
|
||||
rrca
|
||||
rrca
|
||||
xor (hl) ;crude xorshift rng used to select a "random" location to draw to.
|
||||
|
||||
ld h,0
|
||||
ld L,a ;this random value becomes the low byte of HL
|
||||
ld h,0
|
||||
ld L,a ;this random value becomes the low byte of HL
|
||||
|
||||
rlc L
|
||||
rl h ;reduce the RNG's bias towards the top of the screen by shifting one bit into H.
|
||||
ld a,&98 ;high byte of gb vram
|
||||
add h ;h will equal either 0 or 1.
|
||||
ld H,a ;now H will either equal &98 or &99
|
||||
|
||||
ld a,(frametimer) ;it's possible that this value is different from before since every vblank it increments.
|
||||
rlc L
|
||||
rl h ;reduce the RNG's bias towards the top of the screen by shifting one bit into H.
|
||||
ld a,&98 ;high byte of gb vram
|
||||
add h ;h will equal either 0 or 1.
|
||||
ld H,a ;now H will either equal &98 or &99
|
||||
|
||||
ld a,(frametimer) ;it's possible that this value is different from before since every vblank it increments.
|
||||
;the vblank code was omitted because it's mostly irrelevant to the task.
|
||||
and &0f ;select one of sixteen tiles to draw to the screen at the randomly chosen VRAM location.
|
||||
call LCDWait ;disable interrupts, and wait until the Game Boy is ready to update the tilemap
|
||||
ei ;enable interrupts again.
|
||||
ld (hl),a ;now we can store the frame timer AND &0F into video ram.
|
||||
|
||||
and &0f ;select one of sixteen tiles to draw to the screen at the randomly chosen VRAM location.
|
||||
call LCDWait ;disable interrupts, and wait until the Game Boy is ready to update the tilemap
|
||||
ei ;enable interrupts again.
|
||||
ld (hl),a ;now we can store the frame timer AND &0F into video ram.
|
||||
|
||||
ld hl,vblankflag ;set to 1 by the vblank routine.
|
||||
|
||||
ld hl,vblankflag ;set to 1 by the vblank routine.
|
||||
xor a
|
||||
wait:
|
||||
halt ;waits for an interrupt.
|
||||
|
|
@ -32,27 +32,27 @@ wait:
|
|||
ld (hl),a ;clear vblank flag.
|
||||
|
||||
|
||||
ld hl,&FFFF ;master interrupt register
|
||||
res 1,(hl) ;disable hblank interrupt.
|
||||
ld hl,&FFFF ;master interrupt register
|
||||
res 1,(hl) ;disable hblank interrupt.
|
||||
|
||||
ld bc,2
|
||||
ld a,(frametimer)
|
||||
bit 4,a ;check bit 4 of frametimer, if zero, we'll do sine instead of cosine. Bit 4 was chosen arbitrarily.
|
||||
jr nz,doSine
|
||||
ld hl,cos
|
||||
jr nowStore
|
||||
ld bc,2
|
||||
ld a,(frametimer)
|
||||
bit 4,a ;check bit 4 of frametimer, if zero, we'll do sine instead of cosine. Bit 4 was chosen arbitrarily.
|
||||
jr nz,doSine
|
||||
ld hl,cos
|
||||
jr nowStore
|
||||
doSine:
|
||||
ld hl,sin
|
||||
nowStore: ;store desired routine as the CALL address
|
||||
ld a,L
|
||||
LD (&A000+(callpoint-TV_Static_FX+1)),a
|
||||
ld hl,sin
|
||||
nowStore: ;store desired routine as the CALL address
|
||||
ld a,L
|
||||
LD (&A000+(callpoint-TV_Static_FX+1)),a
|
||||
;using label arithmetic we can work out the place to modify the code.
|
||||
;hblank interrupt immediately jumps to cartridge RAM at &A000
|
||||
ld a,H
|
||||
LD (&A000+(callpoint-TV_Static_FX+2)),a ;store the high byte.
|
||||
ld a,H
|
||||
LD (&A000+(callpoint-TV_Static_FX+2)),a ;store the high byte.
|
||||
|
||||
ld hl,&FFFF
|
||||
set 1,(hl) ;re-enable hblank interrupt
|
||||
ld hl,&FFFF
|
||||
set 1,(hl) ;re-enable hblank interrupt
|
||||
|
||||
|
||||
jp forever
|
||||
|
||||
jp forever
|
||||
|
|
|
|||
|
|
@ -1,19 +1,19 @@
|
|||
TV_Static_FX:
|
||||
;this code runs every time the game boy finishes drawing one row of pixels, unless the interrupt is disabled as described above.
|
||||
push hl
|
||||
push af
|
||||
push hl
|
||||
push af
|
||||
ld hl,(COSINE_INDEX)
|
||||
inc (hl)
|
||||
ld a,(hl)
|
||||
ld a,(hl)
|
||||
|
||||
callpoint:
|
||||
call cos ;<--- SMC, gets changed to "CALL SIN" by main game loop when bit 4 of frametimer equals 0, and back to
|
||||
call cos ;<--- SMC, gets changed to "CALL SIN" by main game loop when bit 4 of frametimer equals 0, and back to
|
||||
;"CALL COS" when bit 4 of frametimer equals 1.
|
||||
; returns cos(A) into A
|
||||
; returns cos(A) into A
|
||||
|
||||
LD (&FF43),A ;output cos(frametimer) to horizontal scroll register
|
||||
done_TV_Static_FX:
|
||||
pop af
|
||||
pop hl
|
||||
reti ;return to main program
|
||||
LD (&FF43),A ;output cos(frametimer) to horizontal scroll register
|
||||
done_TV_Static_FX:
|
||||
pop af
|
||||
pop hl
|
||||
reti ;return to main program
|
||||
TV_Static_FX_End:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue