Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,4 +1,14 @@
|
|||
Generate a random black and white 320x240 image continuously, showing FPS (frames per second).
|
||||
{{omit from|AWK}}
|
||||
{{omit from|Bc}}
|
||||
{{omit from|Blast}}
|
||||
{{omit from|Ed}}
|
||||
{{omit from|Lotus 123 Macro Scripting}}
|
||||
{{omit from|MIRC Scripting Language}}
|
||||
{{omit from|ML/I}}
|
||||
{{omit from|Sed}}
|
||||
[[Category:Raster graphics operations]]
|
||||
Generate a random black and white 320x240 image continuously,
|
||||
showing FPS (frames per second).
|
||||
|
||||
Sample image:
|
||||
|
||||
|
|
|
|||
2
Task/Image-noise/00META.yaml
Normal file
2
Task/Image-noise/00META.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
note: Graphics
|
||||
|
|
@ -9,7 +9,6 @@
|
|||
(sdl-base::with-pixel (s (sdl:fp surface))
|
||||
(dotimes (h height)
|
||||
(dotimes (w width)
|
||||
;;(sdl:draw-pixel-* w h :surface s :color (if (zerop (random 2)) sdl:*white* sdl:*black*)))))
|
||||
(sdl-base::write-pixel s w h (if (zerop (random 2))
|
||||
i-white i-black ))))))
|
||||
surface)
|
||||
|
|
@ -21,7 +20,7 @@
|
|||
20 20 :surface s :color sdl:*magenta*)))
|
||||
|
||||
(defun main ()
|
||||
"main function, creates initializes the library and creates de display window"
|
||||
"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
|
||||
|
|
|
|||
68
Task/Image-noise/Haskell/image-noise.hs
Normal file
68
Task/Image-noise/Haskell/image-noise.hs
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
import qualified Graphics.Rendering.OpenGL as GL
|
||||
import qualified Graphics.UI.GLFW as GLFW
|
||||
import qualified Foreign as F
|
||||
import qualified System.Random as R
|
||||
|
||||
height = 240
|
||||
width = 320
|
||||
numbytes = height * width
|
||||
imagesize = GL.Size (fromIntegral width) (fromIntegral height)
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
isInit <- GLFW.init
|
||||
if isInit
|
||||
then do
|
||||
m <- GLFW.createWindow width height "" Nothing Nothing
|
||||
case m of
|
||||
Just win -> do
|
||||
GLFW.makeContextCurrent m
|
||||
GLFW.swapInterval 1
|
||||
GLFW.setKeyCallback win $ Just keyCallback
|
||||
glLoop win
|
||||
GLFW.destroyWindow win
|
||||
Nothing -> return ()
|
||||
GLFW.terminate
|
||||
else return ()
|
||||
|
||||
glLoop :: GLFW.Window -> IO ()
|
||||
glLoop win = do
|
||||
foreignPixels <- F.mallocForeignPtrArray numbytes
|
||||
F.withForeignPtr foreignPixels
|
||||
(\pixels -> do
|
||||
let pixelData = GL.PixelData GL.Luminance GL.UnsignedByte pixels
|
||||
loop pixelData pixels 0)
|
||||
where
|
||||
loop pixelData pixels frames = do
|
||||
close <- GLFW.windowShouldClose win
|
||||
if close
|
||||
then return ()
|
||||
else do
|
||||
randomizePixels pixels
|
||||
GL.drawPixels imagesize pixelData
|
||||
GLFW.swapBuffers win
|
||||
GLFW.pollEvents
|
||||
time <- GLFW.getTime
|
||||
let fps =
|
||||
case time of
|
||||
Just t -> show $ (fromIntegral frames) / t
|
||||
Nothing -> "???"
|
||||
GLFW.setWindowTitle win $ "FPS: " ++ fps
|
||||
loop pixelData pixels $ frames + 1
|
||||
|
||||
randomizePixels :: F.Ptr GL.GLubyte -> IO ()
|
||||
randomizePixels ptr = iter 0 numbytes
|
||||
where
|
||||
iter index range
|
||||
| index == range = return ()
|
||||
| otherwise = do
|
||||
v <- R.randomRIO (0, 1)
|
||||
F.pokeElemOff ptr index $ v * 255
|
||||
iter (index + 1) range
|
||||
|
||||
keyCallback :: GLFW.Window -> GLFW.Key -> Int -> GLFW.KeyState ->
|
||||
GLFW.ModifierKeys -> IO ()
|
||||
keyCallback win key _ action _ =
|
||||
case key of
|
||||
GLFW.Key'Q -> GLFW.setWindowShouldClose win True
|
||||
_ -> return ()
|
||||
33
Task/Image-noise/MAXScript/image-noise.max
Normal file
33
Task/Image-noise/MAXScript/image-noise.max
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
try destroydialog testRollout catch ()
|
||||
|
||||
fn randomBitmap 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
|
||||
)
|
||||
|
||||
return newBmp
|
||||
)
|
||||
|
||||
rollout testRollout "Test" width:320 height:240
|
||||
(
|
||||
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
|
||||
|
||||
if mod updatetimer.ticks 10 == 0 do (testRollout.title = ("Test (FPS: "+fps as string+")"))
|
||||
|
||||
)
|
||||
)
|
||||
|
||||
createdialog testrollout
|
||||
48
Task/Image-noise/Perl-6/image-noise.pl6
Normal file
48
Task/Image-noise/Perl-6/image-noise.pl6
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
use NativeCall;
|
||||
|
||||
class SDL_Window is repr('CStruct') {}
|
||||
class SDL_Renderer is repr('CStruct') {}
|
||||
|
||||
my ($w, $h) = 320, 240;
|
||||
my SDL_Window $window;
|
||||
my SDL_Renderer $renderer;
|
||||
|
||||
constant $sdl-lib = 'libSDL2';
|
||||
constant SDL_INIT_VIDEO = 0x00000020;
|
||||
constant SDL_WINDOWPOS_UNDEFINED_MASK = 0x1FFF0000;
|
||||
constant SDL_WINDOW_SHOWN = 0x00000004;
|
||||
|
||||
sub SDL_Init(int32 $flag) returns int32 is native($sdl-lib) {*}
|
||||
sub SDL_Quit() is native($sdl-lib) {*}
|
||||
|
||||
sub SDL_CreateWindow(Str $title, int $x, int $y, int $w, int $h, int32 $flag) returns SDL_Window is native($sdl-lib) {*}
|
||||
sub SDL_CreateRenderer(SDL_Window $, int $, int $) returns SDL_Renderer is native($sdl-lib) {*}
|
||||
sub SDL_SetRenderDrawColor(SDL_Renderer $, int $r, int $g, int $b, int $a) returns Int is native($sdl-lib) {*}
|
||||
sub SDL_RenderClear(SDL_Renderer $) returns Int is native($sdl-lib) {*}
|
||||
sub SDL_RenderDrawPoint( SDL_Renderer $, int $x, int $y ) returns Int is native($sdl-lib) {*}
|
||||
sub SDL_RenderPresent(SDL_Renderer $) is native($sdl-lib) {*}
|
||||
|
||||
sub render {
|
||||
SDL_SetRenderDrawColor($renderer, 0, 0, 0, 0);
|
||||
SDL_RenderClear($renderer);
|
||||
SDL_SetRenderDrawColor($renderer, 255, 255, 255, 0);
|
||||
for ^$w X ^$h -> $i, $j {
|
||||
SDL_RenderDrawPoint( $renderer, $i, $j ) if rand < .5;
|
||||
}
|
||||
SDL_RenderPresent($renderer);
|
||||
}
|
||||
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
$window = SDL_CreateWindow(
|
||||
"some white noise",
|
||||
SDL_WINDOWPOS_UNDEFINED_MASK, SDL_WINDOWPOS_UNDEFINED_MASK,
|
||||
$w, $h,
|
||||
SDL_WINDOW_SHOWN
|
||||
);
|
||||
$renderer = SDL_CreateRenderer( $window, -1, 1 );
|
||||
loop {
|
||||
my $then = now;
|
||||
render();
|
||||
note "{1 / (now - $then)} fps";
|
||||
}
|
||||
END { SDL_Quit() }
|
||||
Loading…
Add table
Add a link
Reference in a new issue