A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
5
Task/Image-noise/0DESCRIPTION
Normal file
5
Task/Image-noise/0DESCRIPTION
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
Generate a random black and white 320x240 image continuously, showing FPS (frames per second).
|
||||
|
||||
Sample image:
|
||||
|
||||
[[Image:NoiseOutput.png]]
|
||||
7
Task/Image-noise/Ada/image-noise-1.ada
Normal file
7
Task/Image-noise/Ada/image-noise-1.ada
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.ada
Normal file
28
Task/Image-noise/Ada/image-noise-2.ada
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.ada
Normal file
179
Task/Image-noise/Ada/image-noise-3.ada
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;
|
||||
36
Task/Image-noise/BBC-BASIC/image-noise.bbc
Normal file
36
Task/Image-noise/BBC-BASIC/image-noise.bbc
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
dx% = 320
|
||||
dy% = 240
|
||||
images% = 100000
|
||||
VDU 23,22,dx%;dy%;8,8,16,0
|
||||
|
||||
REM Create a block of random data in memory:
|
||||
DIM random% dx%*dy%+images%
|
||||
FOR R% = random% TO random%+dx%*dy%+images%
|
||||
?R% = RND(256)-1
|
||||
NEXT
|
||||
|
||||
REM Create a BMP file structure:
|
||||
DIM bmpfile{bfType{l&,h&}, bfSize%, bfReserved%, bfOffBits%, \
|
||||
\ biSize%, biWidth%, biHeight%, biPlanes{l&,h&}, biBitCount{l&,h&}, \
|
||||
\ biCompression%, biSizeImage%, biXPelsPerMeter%, biYPelsPerMeter%, \
|
||||
\ biClrUsed%, biClrImportant%, biPalette%(255)}
|
||||
bmpfile.biSize% = 40
|
||||
bmpfile.biWidth% = dx%
|
||||
bmpfile.biHeight% = dy%
|
||||
bmpfile.biPlanes.l& = 1
|
||||
bmpfile.biBitCount.l& = 8
|
||||
FOR C% = 0 TO 255
|
||||
bmpfile.biPalette%(C%) = C% OR C%<<8 OR C%<<16
|
||||
NEXT
|
||||
|
||||
REM Display image at a random offset into the data:
|
||||
frame% = 0
|
||||
TIME = 0
|
||||
REPEAT
|
||||
bmpfile.bfOffBits% = random% - bmpfile{} + RND(images%)
|
||||
OSCLI "MDISPLAY " + STR$~bmpfile{}
|
||||
frame% += 1
|
||||
IF TIME>10 THEN
|
||||
SYS "SetWindowText", @hwnd%, "BBC BASIC: " + STR$(frame%*100 DIV TIME) + " fps"
|
||||
ENDIF
|
||||
UNTIL FALSE
|
||||
50
Task/Image-noise/C/image-noise-1.c
Normal file
50
Task/Image-noise/C/image-noise-1.c
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <SDL/SDL.h>
|
||||
|
||||
unsigned int frames = 0;
|
||||
unsigned int t_acc = 0;
|
||||
|
||||
void print_fps ()
|
||||
{
|
||||
static Uint32 last_t = 0;
|
||||
Uint32 t = SDL_GetTicks();
|
||||
Uint32 dt = t - last_t;
|
||||
t_acc += dt;
|
||||
if (t_acc > 1000)
|
||||
{
|
||||
unsigned int el_time = t_acc / 1000;
|
||||
printf("- fps: %g\n",
|
||||
(float) frames / (float) el_time);
|
||||
t_acc = 0;
|
||||
frames = 0;
|
||||
}
|
||||
last_t = t;
|
||||
}
|
||||
|
||||
void blit_noise(SDL_Surface *surf)
|
||||
{
|
||||
unsigned int i;
|
||||
long dim = surf->w * surf->h;
|
||||
while (1)
|
||||
{
|
||||
SDL_LockSurface(surf);
|
||||
for (i=0; i < dim; ++i) {
|
||||
((unsigned char *)surf->pixels)[i] = ((rand() & 1) ? 255 : 0);
|
||||
}
|
||||
SDL_UnlockSurface(surf);
|
||||
SDL_Flip(surf);
|
||||
++frames;
|
||||
print_fps();
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
SDL_Surface *surf = NULL;
|
||||
srand((unsigned int)time(NULL));
|
||||
SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO);
|
||||
surf = SDL_SetVideoMode(320, 240, 8, SDL_DOUBLEBUF | SDL_HWSURFACE);
|
||||
blit_noise(surf);
|
||||
}
|
||||
47
Task/Image-noise/C/image-noise-2.c
Normal file
47
Task/Image-noise/C/image-noise-2.c
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
#include <GL/glut.h>
|
||||
#include <GL/gl.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#define W 320
|
||||
#define H 240
|
||||
#define slen W * H / sizeof(int)
|
||||
|
||||
time_t start, last;
|
||||
|
||||
void render()
|
||||
{
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
glutInit(&argc, argv);
|
||||
glutInitDisplayMode(GLUT_INDEX);
|
||||
glutInitWindowSize(W, H);
|
||||
glutCreateWindow("noise");
|
||||
glutDisplayFunc(render);
|
||||
glutIdleFunc(render);
|
||||
|
||||
last = start = time(0);
|
||||
|
||||
glutMainLoop();
|
||||
return 0;
|
||||
}
|
||||
24
Task/Image-noise/D/image-noise.d
Normal file
24
Task/Image-noise/D/image-noise.d
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import std.stdio, std.random, sdl.SDL;
|
||||
|
||||
void main() {
|
||||
SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO);
|
||||
auto surface = SDL_SetVideoMode(320,240,8, SDL_DOUBLEBUF|SDL_HWSURFACE);
|
||||
|
||||
uint frameNumber, totalTime, lastTime;
|
||||
while (true) {
|
||||
SDL_LockSurface(surface);
|
||||
foreach (i; 0 .. surface.w * surface.h)
|
||||
(cast(ubyte*)surface.pixels)[i] = (uniform(0, 2) ? 255 : 0);
|
||||
SDL_UnlockSurface(surface);
|
||||
SDL_Flip(surface);
|
||||
frameNumber++;
|
||||
|
||||
uint time = SDL_GetTicks();
|
||||
totalTime += time - lastTime;
|
||||
if (totalTime > 1000) {
|
||||
writeln("FPS: ", frameNumber / (totalTime / 1000.0));
|
||||
totalTime = frameNumber = 0;
|
||||
}
|
||||
lastTime = time;
|
||||
}
|
||||
}
|
||||
13
Task/Image-noise/Euler-Math-Toolbox/image-noise.euler
Normal file
13
Task/Image-noise/Euler-Math-Toolbox/image-noise.euler
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
>function noiseimg () ...
|
||||
$aspect(320,240); clg;
|
||||
$count=0; now=time;
|
||||
$repeat
|
||||
$ plotrgb(intrandom(240,420,2)-1,[0,0,1024,1024]);
|
||||
$ wait(0);
|
||||
$ count=count+1;
|
||||
$ until testkey();
|
||||
$end;
|
||||
$return count/(time-now);
|
||||
$endfunction
|
||||
>noiseimg
|
||||
2.73544353263
|
||||
54
Task/Image-noise/Factor/image-noise.factor
Normal file
54
Task/Image-noise/Factor/image-noise.factor
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
USING: accessors calendar images images.viewer kernel math
|
||||
math.parser models models.arrow random sequences threads timers
|
||||
ui.gadgets ui.gadgets.labels ui.gadgets.packs ;
|
||||
IN: bw-noise
|
||||
|
||||
CONSTANT: pixels { B{ 0 0 0 } B{ 255 255 255 } }
|
||||
|
||||
: <random-images-bytes> ( dim -- bytes )
|
||||
product [ pixels random ] { } replicate-as concat ;
|
||||
|
||||
: <random-bw-image> ( -- image )
|
||||
<image>
|
||||
{ 320 240 } [ >>dim ] [ <random-images-bytes> >>bitmap ] bi
|
||||
RGB >>component-order
|
||||
ubyte-components >>component-type ;
|
||||
|
||||
TUPLE: bw-noise-gadget < image-control timers cnt old-cnt fps-model ;
|
||||
|
||||
: animate-image ( control -- )
|
||||
[ 1 + ] change-cnt
|
||||
model>> <random-bw-image> swap set-model ;
|
||||
|
||||
: update-cnt ( gadget -- )
|
||||
[ cnt>> ] [ old-cnt<< ] bi ;
|
||||
: fps ( gadget -- fps )
|
||||
[ cnt>> ] [ old-cnt>> ] bi - ;
|
||||
: fps-monitor ( gadget -- )
|
||||
[ fps ] [ update-cnt ] [ fps-model>> set-model ] tri ;
|
||||
|
||||
: start-animation ( gadget -- )
|
||||
[ [ animate-image ] curry 1 nanoseconds every ] [ timers>> push ] bi ;
|
||||
: start-fps ( gadget -- )
|
||||
[ [ fps-monitor ] curry 1 seconds every ] [ timers>> push ] bi ;
|
||||
: setup-timers ( gadget -- )
|
||||
[ start-animation ] [ start-fps ] bi ;
|
||||
: stop-animation ( gadget -- )
|
||||
timers>> [ [ stop-timer ] each ] [ 0 swap set-length ] bi ;
|
||||
|
||||
M: bw-noise-gadget graft* [ call-next-method ] [ setup-timers ] bi ;
|
||||
M: bw-noise-gadget ungraft* [ stop-animation ] [ call-next-method ] bi ;
|
||||
|
||||
: <bw-noise-gadget> ( -- gadget )
|
||||
<random-bw-image> <model> bw-noise-gadget new-image-gadget*
|
||||
0 >>cnt 0 >>old-cnt 0 <model> >>fps-model V{ } clone >>timers ;
|
||||
: fps-gadget ( model -- gadget )
|
||||
[ number>string ] <arrow> <label-control>
|
||||
"FPS: " <label>
|
||||
<shelf> swap add-gadget swap add-gadget ;
|
||||
|
||||
: with-fps ( gadget -- gadget' )
|
||||
[ fps-model>> fps-gadget ]
|
||||
[ <pile> swap add-gadget swap add-gadget ] bi ;
|
||||
|
||||
: open-noise-window ( -- ) [ <bw-noise-gadget> with-fps "Black and White noise" open-window ] with-ui ;
|
||||
87
Task/Image-noise/Go/image-noise-1.go
Normal file
87
Task/Image-noise/Go/image-noise-1.go
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"code.google.com/p/x-go-binding/ui/x11"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
var randcol = genrandcol()
|
||||
|
||||
func genrandcol() <-chan color.Color {
|
||||
c := make(chan color.Color)
|
||||
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case c <- image.Black:
|
||||
case c <- image.White:
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
func gennoise(screen draw.Image) {
|
||||
for y := 0; y < 240; y++ {
|
||||
for x := 0; x < 320; x++ {
|
||||
screen.Set(x, y, <-randcol)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func fps() chan<- bool {
|
||||
up := make(chan bool)
|
||||
|
||||
go func() {
|
||||
var frames int64
|
||||
var lasttime time.Time
|
||||
var totaltime time.Duration
|
||||
|
||||
for {
|
||||
<-up
|
||||
frames++
|
||||
now := time.Now()
|
||||
totaltime += now.Sub(lasttime)
|
||||
if totaltime > time.Second {
|
||||
fmt.Printf("FPS: %v\n", float64(frames)/totaltime.Seconds())
|
||||
frames = 0
|
||||
totaltime = 0
|
||||
}
|
||||
lasttime = now
|
||||
}
|
||||
}()
|
||||
|
||||
return up
|
||||
}
|
||||
|
||||
func main() {
|
||||
win, err := x11.NewWindow()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer win.Close()
|
||||
|
||||
go func() {
|
||||
upfps := fps()
|
||||
screen := win.Screen()
|
||||
|
||||
for {
|
||||
gennoise(screen)
|
||||
|
||||
win.FlushImage()
|
||||
|
||||
upfps <- true
|
||||
}
|
||||
}()
|
||||
|
||||
for _ = range win.EventChan() {
|
||||
}
|
||||
}
|
||||
98
Task/Image-noise/Go/image-noise-2.go
Normal file
98
Task/Image-noise/Go/image-noise-2.go
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
package main
|
||||
|
||||
/* Note, the x-go-binding/ui/x11 lib is under development and has as a temp solution
|
||||
set the x window to a static hight and with, you have to manualy set these
|
||||
to 240 x 320 in code.google.com/p/x-go-binding/ui/x11/conn.go */
|
||||
|
||||
import "code.google.com/p/x-go-binding/ui"
|
||||
import "code.google.com/p/x-go-binding/ui/x11"
|
||||
import "fmt"
|
||||
import "image"
|
||||
import "image/draw"
|
||||
import "log"
|
||||
import "math/rand"
|
||||
import "runtime"
|
||||
import "time"
|
||||
|
||||
var bw[65536][64]byte
|
||||
var frameCount = make(chan uint)
|
||||
|
||||
func main() {
|
||||
tc := runtime.NumCPU()
|
||||
runtime.GOMAXPROCS(tc)
|
||||
|
||||
// Initiate a new x11 screen to print images onto
|
||||
win, err := x11.NewWindow()
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
defer win.Close()
|
||||
screen := win.Screen()
|
||||
_, ok := screen.(*image.RGBA)
|
||||
if !ok {
|
||||
log.Fatalln("screen isn't an RGBA image.")
|
||||
}
|
||||
|
||||
//Create lookup table for every combination of 16 black/white pixels
|
||||
var i, j uint
|
||||
for i = 0; i< 65536; i++ {
|
||||
for j = 0; j < 16; j++ {
|
||||
if i & (1 << j) > 0 {
|
||||
bw[i][j*4 + 0] = 0xFF
|
||||
bw[i][j*4 + 1] = 0xFF
|
||||
bw[i][j*4 + 2] = 0xFF
|
||||
}
|
||||
}
|
||||
}
|
||||
// Start fps counter in a new goroutin
|
||||
go fps()
|
||||
// Start goroutines
|
||||
for i := 0; i < tc; i++ {
|
||||
go createNoise(win, screen)
|
||||
}
|
||||
createNoise(win, screen)
|
||||
}
|
||||
|
||||
func createNoise(win ui.Window, screen draw.Image) {
|
||||
var rnd, rnd2 uint64
|
||||
var rnd16a, rnd16b, rnd16c, rnd16d uint16
|
||||
var img [240 * 320 * 4]byte
|
||||
// Populate the image with pixel data
|
||||
for {
|
||||
for i := 0; i < len(img); i += 256 {
|
||||
rnd = uint64(rand.Int63())
|
||||
if (i % 63) == 0 {
|
||||
rnd2 = uint64(rand.Int63())
|
||||
}
|
||||
rnd |= rnd2 & 1 << 63 // we have to set the 64'th bit from the rand.Int63() manualy
|
||||
rnd16a = uint16( rnd & 0x000000000000FFFF)
|
||||
rnd16b = uint16((rnd >> 16) & 0x000000000000FFFF)
|
||||
rnd16c = uint16((rnd >> 32) & 0x000000000000FFFF)
|
||||
rnd16d = uint16((rnd >> 48) & 0x000000000000FFFF)
|
||||
copy(img[i :i+ 64], bw[rnd16a][:])
|
||||
copy(img[i+ 64:i+128], bw[rnd16b][:])
|
||||
copy(img[i+128:i+192], bw[rnd16c][:])
|
||||
copy(img[i+192:i+256], bw[rnd16d][:])
|
||||
rnd2 = rnd2 >> 1 // rotate to next random bit
|
||||
}
|
||||
// Copy pixel data to the screen
|
||||
copy(screen.(*image.RGBA).Pix, img[:])
|
||||
frameCount <- 1
|
||||
win.FlushImage()
|
||||
}
|
||||
}
|
||||
|
||||
func fps() {
|
||||
last := time.Now()
|
||||
var fps uint
|
||||
for {
|
||||
// wait for a frameCount update
|
||||
<-frameCount
|
||||
fps++
|
||||
if time.Since(last) >= time.Second {
|
||||
fmt.Println("fps:", fps)
|
||||
fps = 0
|
||||
last = time.Now()
|
||||
}
|
||||
}
|
||||
}
|
||||
19
Task/Image-noise/Icon/image-noise.icon
Normal file
19
Task/Image-noise/Icon/image-noise.icon
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
link printf
|
||||
|
||||
procedure main()
|
||||
&window := open("B&W noise 320x240","g","size=320,240","bg=white","fg=black") |
|
||||
stop("Open window failed ")
|
||||
runtime := 10 # seconds to run
|
||||
sec := &now
|
||||
frames := 0
|
||||
until (&now - sec) >= runtime do {
|
||||
s := "320,#"
|
||||
every 1 to 240 & 1 to 320/4 do s ||:= ?"0123456789ABCDEF"
|
||||
DrawImage(0,0,s)
|
||||
frames +:= 1
|
||||
}
|
||||
sec := &now - sec
|
||||
printf("frames=%d, elapsed time=%r, fps=%r\n",frames,sec, frames/real(sec))
|
||||
Event() # wait for any window event
|
||||
close(&window)
|
||||
end
|
||||
48
Task/Image-noise/J/image-noise.j
Normal file
48
Task/Image-noise/J/image-noise.j
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
coclass'example'
|
||||
(coinsert[require)'jzopengl'
|
||||
|
||||
P=: 0 : 0
|
||||
pc p nosize;
|
||||
xywh 0 0 160 120;cc c isigraph opengl;
|
||||
pas 0 0;pcenter;
|
||||
rem form end;
|
||||
pshow;
|
||||
timer 1;
|
||||
)
|
||||
|
||||
timestamp=: (6!:8'') %~ 6!:9
|
||||
|
||||
create=:3 :0
|
||||
ogl=:''conew'jzopengl'
|
||||
frames=:0
|
||||
start=: timestamp''
|
||||
sys_timer_base_=: ''1 :('p_c_paint_',(;coname''),'_')
|
||||
wd P
|
||||
)
|
||||
|
||||
p_run=: 3 : 0
|
||||
''conew'example'
|
||||
)
|
||||
|
||||
destroy=:3 :0
|
||||
end=:timestamp''
|
||||
smoutput 'frames per second: ',":frames%end-start
|
||||
wd 'timer 0'
|
||||
destroy__ogl''
|
||||
wd'pclose'
|
||||
codestroy''
|
||||
)
|
||||
|
||||
p_close=: destroy
|
||||
|
||||
p_c_paint=: 3 : 0
|
||||
rc__ogl''
|
||||
glClear GL_COLOR_BUFFER_BIT
|
||||
glBegin GL_POINTS
|
||||
glVertex _1+2*53050 2?@$ 0
|
||||
glEnd''
|
||||
show__ogl''
|
||||
frames=:frames+1
|
||||
)
|
||||
|
||||
p_run''
|
||||
120
Task/Image-noise/Java/image-noise.java
Normal file
120
Task/Image-noise/Java/image-noise.java
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.image.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
import javax.swing.*;
|
||||
|
||||
public class ImageNoise {
|
||||
int framecount = 0;
|
||||
int fps = 0;
|
||||
BufferedImage image;
|
||||
Kernel kernel;
|
||||
ConvolveOp cop;
|
||||
JFrame frame = new JFrame("Java Image Noise");
|
||||
|
||||
JPanel panel = new JPanel() {
|
||||
private int show_fps = 0; // 0 = blur + FPS; 1 = FPS only; 2 = neither
|
||||
private MouseAdapter ma = new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
show_fps = (show_fps + 1) % 3;
|
||||
}
|
||||
};
|
||||
{addMouseListener(ma);}
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(320, 240);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("fallthrough")
|
||||
public void paintComponent(Graphics g1) {
|
||||
Graphics2D g = (Graphics2D) g1;
|
||||
drawNoise();
|
||||
g.drawImage(image, 0, 0, null);
|
||||
|
||||
switch (show_fps) {
|
||||
case 0:
|
||||
// add blur behind FPS
|
||||
int xblur = getWidth() - 130, yblur = getHeight() - 32;
|
||||
BufferedImage bc = image.getSubimage(xblur, yblur, 115, 32);
|
||||
BufferedImage bs = new BufferedImage(bc.getWidth(), bc.getHeight(),
|
||||
BufferedImage.TYPE_BYTE_GRAY);
|
||||
cop.filter(bc, bs);
|
||||
g.drawImage(bs, xblur, yblur , null);
|
||||
case 1:
|
||||
// add FPS text; case fallthough is deliberate
|
||||
g.setColor(Color.RED);
|
||||
g.setFont(new Font("Monospaced", Font.BOLD, 20));
|
||||
g.drawString("FPS: " + fps, getWidth() - 120, getHeight() - 10);
|
||||
}
|
||||
framecount++;
|
||||
}
|
||||
};
|
||||
|
||||
// Timer to trigger update display, with 1 ms delay
|
||||
Timer repainter = new Timer(1, new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
panel.repaint();
|
||||
}
|
||||
});
|
||||
|
||||
// Timer to check FPS, once per second
|
||||
Timer framerateChecker = new Timer(1000, new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
fps = framecount;
|
||||
framecount = 0;
|
||||
}
|
||||
});
|
||||
|
||||
public ImageNoise() {
|
||||
// Intitalize kernel describing blur, and convolve operation based on this
|
||||
float[] vals = new float[121];
|
||||
Arrays.fill(vals, 1/121f);
|
||||
kernel = new Kernel(11, 11, vals);
|
||||
cop = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
|
||||
|
||||
// Initialize frame and timers
|
||||
frame.add(panel);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
repainter.start();
|
||||
framerateChecker.start();
|
||||
}
|
||||
|
||||
void drawNoise() {
|
||||
int w = panel.getWidth(), h = panel.getHeight();
|
||||
|
||||
// Check if our image is null or window has been resized, requiring new image
|
||||
if (null == image || image.getWidth() != w || image.getHeight() != h) {
|
||||
image = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_GRAY);
|
||||
}
|
||||
Random rand = new Random();
|
||||
int[] data = new int[w * h];
|
||||
// Each int has 32 bits so we can use each bit for a different pixel - much faster
|
||||
for (int x = 0; x < w * h / 32; x++) {
|
||||
int r = rand.nextInt();
|
||||
for (int i = 0; i < 32; i++) {
|
||||
data[x * 32 + i] = (r & 1) * Integer.MAX_VALUE;
|
||||
r >>>= 1;
|
||||
}
|
||||
}
|
||||
// Copy raw data to the image's raster
|
||||
image.getRaster().setPixels(0, 0, w, h, data);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Invoke GUI on the Event Dispatching Thread
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ImageNoise i = new ImageNoise();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
49
Task/Image-noise/JavaScript/image-noise.js
Normal file
49
Task/Image-noise/JavaScript/image-noise.js
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
<body>
|
||||
<canvas id='c'></canvas>
|
||||
|
||||
<script>
|
||||
var canvas = document.getElementById('c');
|
||||
var ctx = canvas.getContext('2d');
|
||||
|
||||
var w = canvas.width = 320;
|
||||
var h = canvas.height = 240;
|
||||
var t1 = new Date().getTime();
|
||||
var frame_count = 0;
|
||||
ctx.font = 'normal 400 24px/2 Unknown Font, sans-serif';
|
||||
var img = ctx.createImageData(w, h);
|
||||
|
||||
var index_init = 0;
|
||||
for (var x = 0; x < w; x++) {
|
||||
for (var y = 0; y < h; y++) {
|
||||
img.data[index_init + 3] = 255; // alpha
|
||||
index_init += 4;
|
||||
}
|
||||
}
|
||||
|
||||
function animate() {
|
||||
var index = 0;
|
||||
for (var x = 0; x < w; x++) {
|
||||
for (var y = 0; y < h; y++) {
|
||||
var value = (Math.random() > 0.5) ? 255 : 0;
|
||||
img.data[index ] = value;
|
||||
img.data[index + 1] = value;
|
||||
img.data[index + 2] = value;
|
||||
// alpha channel is constant
|
||||
index += 4;
|
||||
}
|
||||
}
|
||||
|
||||
ctx.putImageData(img, 0, 0);
|
||||
|
||||
frame_count++;
|
||||
if (frame_count % 50 == 0) {
|
||||
var fps = frame_count / (new Date().getTime() - t1) * 1000;
|
||||
window.status = fps.toFixed(2) + " fps";
|
||||
}
|
||||
|
||||
setTimeout(animate, 0);
|
||||
}
|
||||
|
||||
animate();
|
||||
</script>
|
||||
</body>
|
||||
72
Task/Image-noise/Liberty-BASIC/image-noise.liberty
Normal file
72
Task/Image-noise/Liberty-BASIC/image-noise.liberty
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
WindowWidth =411
|
||||
w =320
|
||||
WindowHeight =356
|
||||
h =240
|
||||
|
||||
|
||||
open "Noise" for graphics_nsb as #w
|
||||
|
||||
#w "trapclose [quit]"
|
||||
#w "down"
|
||||
|
||||
print "Creating BMP header"
|
||||
|
||||
'bitmap header, 320x240 pixels 256 colors
|
||||
data 66,77,54,48,1,0,0,0,0,0,54,4,0,0,40,0,0,0,64,1
|
||||
data 0,0,240,0,0,0,1,0,8,0,0,0,0,0,0,44,1,0,0,0
|
||||
data 0,0,0,0,0,0,0,1,0,0,0,1,0,0
|
||||
|
||||
head$=""
|
||||
for i = 1 to 54
|
||||
read c
|
||||
head$=head$+chr$(c)
|
||||
next
|
||||
|
||||
print "Creating BMP grayscale palette"
|
||||
pal$=""
|
||||
for i = 0 to 255
|
||||
pal$ = pal$ _
|
||||
+ chr$(i) _
|
||||
+ chr$(i) _
|
||||
+ chr$(i) _
|
||||
+ chr$(0)
|
||||
next
|
||||
|
||||
print "Creating BMP random body"
|
||||
'create bitmap body
|
||||
body$=""
|
||||
for x =1 To w
|
||||
l$=""
|
||||
for y =1 To h
|
||||
l$=l$+chr$((rnd(1)>0.5)*255)
|
||||
next
|
||||
body$=body$+l$
|
||||
next
|
||||
|
||||
[main]
|
||||
scan
|
||||
ts =time$( "ms")
|
||||
'randomly "splice" the body: 1111222222-> 2222221111
|
||||
splice=int(len(body$)*rnd(1))+1
|
||||
body$= mid$(body$,splice+1)+left$(body$,splice)
|
||||
'write BMP
|
||||
open "noise.bmp" for output as #1
|
||||
#1 head$;pal$;
|
||||
#1 body$;
|
||||
close #1
|
||||
'load bmp
|
||||
loadbmp "noise", "noise.bmp"
|
||||
#w "cls"
|
||||
'drawbmp
|
||||
#w "drawbmp noise 0 0"
|
||||
|
||||
tf =time$( "ms")
|
||||
dt =tf -ts
|
||||
if dt = 0 then dt = 1
|
||||
print "Framerate per second ="; using( "#.###", 1/(dt/1000)), "Ms per frame =";dt
|
||||
goto [main]
|
||||
|
||||
[quit]
|
||||
unloadbmp "noise"
|
||||
close #w
|
||||
end
|
||||
3
Task/Image-noise/Mathematica/image-noise.mathematica
Normal file
3
Task/Image-noise/Mathematica/image-noise.mathematica
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
time = AbsoluteTime[]; Animate[
|
||||
Column[{Row[{"FPS: ", Round[n/(AbsoluteTime[] - time)]}],
|
||||
RandomImage[1, {320, 240}]}], {n, 1, Infinity, 1}]
|
||||
51
Task/Image-noise/PicoLisp/image-noise.l
Normal file
51
Task/Image-noise/PicoLisp/image-noise.l
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
(javac "ImageNoise" "JPanel" NIL
|
||||
"java.util.*"
|
||||
"java.awt.*" "java.awt.image.*" "javax.swing.*" )
|
||||
|
||||
int DX, DY;
|
||||
int[] Pixels;
|
||||
MemoryImageSource Source;
|
||||
Image Img;
|
||||
Random Rnd;
|
||||
|
||||
public ImageNoise(int dx, int dy) {
|
||||
DX = dx;
|
||||
DY = dy;
|
||||
Pixels = new int[DX * DY];
|
||||
Source = new MemoryImageSource(DX, DY, Pixels, 0, DX);
|
||||
Source.setAnimated(true);
|
||||
Img = createImage(Source);
|
||||
Rnd = new Random();
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {update(g);}
|
||||
public void update(Graphics g) {g.drawImage(Img, 0, 0, this);}
|
||||
|
||||
public void draw() {
|
||||
for (int i = 0; i < Pixels.length; ++i) {
|
||||
int c = Rnd.nextInt(255);
|
||||
Pixels[i] = 0xFF000000 | c<<16 | c<<8 | c;
|
||||
}
|
||||
Source.newPixels();
|
||||
paint(getGraphics());
|
||||
}
|
||||
/**/
|
||||
|
||||
(de imageNoise (DX DY Fps)
|
||||
(let
|
||||
(Frame (java "javax.swing.JFrame" T "Image Noise")
|
||||
Noise (java "ImageNoise" T DX DY)
|
||||
Button (java "javax.swing.JButton" T "OK") )
|
||||
(java Frame "add" Noise)
|
||||
(java Frame "add" "South" Button)
|
||||
(java Button "addActionListener"
|
||||
(interface "java.awt.event.ActionListener"
|
||||
'actionPerformed '((Ev) (bye)) ) )
|
||||
(java Frame "setSize" DX DY)
|
||||
(java Frame "setVisible" T)
|
||||
(task (/ -1000 Fps) 0
|
||||
Image Noise
|
||||
(java Image "draw") ) ) )
|
||||
|
||||
# Start with 25 frames per second
|
||||
(imageNoise 320 240 25)
|
||||
53
Task/Image-noise/Python/image-noise.py
Normal file
53
Task/Image-noise/Python/image-noise.py
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import time
|
||||
import random
|
||||
import Tkinter
|
||||
import Image, ImageTk # PIL libray
|
||||
|
||||
class App(object):
|
||||
def __init__(self, size, root):
|
||||
self.root = root
|
||||
self.root.title("Image Noise Test")
|
||||
|
||||
self.img = Image.new("RGB", size)
|
||||
self.label = Tkinter.Label(root)
|
||||
self.label.pack()
|
||||
|
||||
self.time = 0.0
|
||||
self.frames = 0
|
||||
self.size = size
|
||||
self.loop()
|
||||
|
||||
def loop(self):
|
||||
self.ta = time.time()
|
||||
# 13 FPS boost. half integer idea from C#.
|
||||
rnd = random.random
|
||||
white = (255, 255, 255)
|
||||
black = (0, 0, 0)
|
||||
npixels = self.size[0] * self.size[1]
|
||||
data = [white if rnd() > 0.5 else black for i in xrange(npixels)]
|
||||
self.img.putdata(data)
|
||||
self.pimg = ImageTk.PhotoImage(self.img)
|
||||
self.label["image"] = self.pimg
|
||||
self.tb = time.time()
|
||||
|
||||
self.time += (self.tb - self.ta)
|
||||
self.frames += 1
|
||||
|
||||
if self.frames == 30:
|
||||
try:
|
||||
self.fps = self.frames / self.time
|
||||
except:
|
||||
self.fps = "INSTANT"
|
||||
print ("%d frames in %3.2f seconds (%s FPS)" %
|
||||
(self.frames, self.time, self.fps))
|
||||
self.time = 0
|
||||
self.frames = 0
|
||||
|
||||
self.root.after(1, self.loop)
|
||||
|
||||
def main():
|
||||
root = Tkinter.Tk()
|
||||
app = App((320, 240), root)
|
||||
root.mainloop()
|
||||
|
||||
main()
|
||||
23
Task/Image-noise/Ruby/image-noise.rb
Normal file
23
Task/Image-noise/Ruby/image-noise.rb
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
require 'rubygems'
|
||||
require 'gl'
|
||||
require 'glut'
|
||||
|
||||
W, H = 320, 240
|
||||
SIZE = W * H
|
||||
|
||||
Glut.glutInit ARGV
|
||||
Glut.glutInitWindowSize W, H
|
||||
|
||||
Glut.glutIdleFunc lambda {
|
||||
i = Time.now
|
||||
noise = (1..SIZE).map { rand > 0.5 ? 0xFFFFFFFF : 0xFF000000 }.pack("I*")
|
||||
|
||||
Gl.glClear Gl::GL_COLOR_BUFFER_BIT
|
||||
Gl.glDrawPixels W, H, Gl::GL_RGBA, Gl::GL_UNSIGNED_BYTE, noise
|
||||
Gl.glFlush
|
||||
|
||||
puts 1.0 / (Time.now - i)
|
||||
}
|
||||
|
||||
Glut.glutCreateWindow "noise"
|
||||
Glut.glutMainLoop
|
||||
46
Task/Image-noise/Scala/image-noise.scala
Normal file
46
Task/Image-noise/Scala/image-noise.scala
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import java.awt.event.{ActionEvent, ActionListener}
|
||||
import swing.{Panel, MainFrame, SimpleSwingApplication}
|
||||
import javax.swing.Timer
|
||||
import java.awt.{Font, Color, Graphics2D, Dimension}
|
||||
|
||||
object ImageNoise extends SimpleSwingApplication {
|
||||
var delay_ms = 2
|
||||
var framecount = 0
|
||||
var fps = 0
|
||||
|
||||
def top = new MainFrame {
|
||||
contents = panel
|
||||
}
|
||||
|
||||
val panel = new Panel {
|
||||
preferredSize = new Dimension(320, 240)
|
||||
|
||||
override def paintComponent(g: Graphics2D) {
|
||||
for (x <- 0 to size.width; y <- 0 to size.height) {
|
||||
val c = if (math.random > 0.5) Color.BLACK else Color.WHITE
|
||||
g.setColor(c)
|
||||
g.fillRect(x, y, 1, 1)
|
||||
}
|
||||
g.setColor(Color.RED)
|
||||
g.setFont(new Font("Monospaced", Font.BOLD, 20))
|
||||
g.drawString("FPS: " + fps, size.width - 100, size.height - 10)
|
||||
framecount += 1
|
||||
}
|
||||
}
|
||||
|
||||
val repainter = new Timer(delay_ms, new ActionListener {
|
||||
def actionPerformed(e: ActionEvent) {
|
||||
panel.repaint
|
||||
}
|
||||
})
|
||||
|
||||
val framerateChecker = new Timer(1000, new ActionListener {
|
||||
def actionPerformed(e: ActionEvent) {
|
||||
fps = framecount
|
||||
framecount = 0
|
||||
}
|
||||
})
|
||||
|
||||
repainter.start()
|
||||
framerateChecker.start()
|
||||
}
|
||||
35
Task/Image-noise/Tcl/image-noise.tcl
Normal file
35
Task/Image-noise/Tcl/image-noise.tcl
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
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
|
||||
}
|
||||
$img put $data
|
||||
}
|
||||
|
||||
set time 0.0
|
||||
set count 0
|
||||
|
||||
proc looper {} {
|
||||
global time count
|
||||
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
|
||||
}
|
||||
after 1 looper
|
||||
}
|
||||
|
||||
image create photo noise -width 320 -height 240
|
||||
pack [label .l -image noise]
|
||||
update
|
||||
looper
|
||||
Loading…
Add table
Add a link
Reference in a new issue