text stringlengths 12 786k |
|---|
let create_zmq_client data = if Unix . fork ( ) = 0 then begin try let socket = Zmq . Socket . create ctx Zmq . Socket . req in Zmq . Socket . connect socket " tcp :// 127 . 0 . 0 . 1 : 5555 " ; Zmq . Socket . send_all socket data ; let _ = Zmq . Socket . recv socket... |
let test_recv_send ctxt = let expected = [ " This " ; " is " ; " ZeroMQ " ] in create_zmq_client expected ; Lwt_main . run begin let socket = Zmq_channel . create ~ ctx ~ kind : Zmq . Socket . rep " tcp :// 0 . 0 . 0 . 0 : 5555 " in Zmq_channel . recv socket >>= f... |
let suite = " Zmq_channel " >:: test_recv_send |
let test ? cr zone = require_does_not_raise [ % here ] ? cr ( fun ( ) -> print_s [ % sexp ( Time . utc_offset Time . epoch ~ zone : Time . Span . t ) ] ) in test Time . Zone . utc ; [ % expect { | 0s } ] ; | let zone = Time . Zone . utc |> Binable . to_str... |
type falling_block = { mutable pattern : int array list ; mutable bcolor : int ; mutable x : int ; mutable y : int ; mutable d : int ; mutable alive : bool } |
let colors = [ | ` Color " red " ; ` Color " yellow " ; ` Color " blue " ; ` Color " orange " ; ` Color " magenta " ; ` Color " green " ; ` Color " cyan " ] | |
let backgrounds = [ " Lambda2 . back . gif " ] |
let blocks = [ [ [ " | 0000 " ; " 0000 " ; " 1111 " ; " 0000 " ] ; | [ " | 0010 " ; " 0010 " ; " 0010 " ; " 0010 " ] ; | [ " | 0000 " ; " 0000 " ; " 1111 " ; " 0000 " ] ; | [ " | 0010 " ; " 0010 " ;... |
let line_empty = int_of_string " 0b1110000000000111 " |
let line_full = int_of_string " 0b1111111111111111 " |
let decode_block dvec = let btoi d = int_of_string ( " 0b " ^ d ) in Array . map ~ f : btoi dvec val mutable color = 0 method get = color method set ~ color : col = if color = col then ( ) else if color <> 0 && col = 0 then begin Canvas . move canvas t1 ~ x ( :- block_size * ( x... |
let cell_get ( c , cf ) x y = cf . ( y ) . ( x ) # get |
let cell_set ( c , cf ) ~ x ~ y ~ color = if x >= 0 && y >= 0 && Array . length cf > y && Array . length cf . ( y ) > x then let cur = cf . ( y ) . ( x ) in if cur # get = color then ( ) else cur # set ~ color |
let create_base_matrix ~ cols ~ rows = let m = Array . create_matrix ~ dimx : rows ~ dimy : cols ( 0 , 0 ) in for x = 0 to cols - 1 do for y = 0 to rows - 1 do m . ( y ) . ( x ) <- ( x , y ) done done ; m |
let init fw = let scorev = Textvariable . create ( ) and linev = Textvariable . create ( ) and levv = Textvariable . create ( ) and namev = Textvariable . create ( ) in let f = Frame . create fw ~ borderwidth : 2 in let c = Canvas . create f ~ width : ( block_size * 10 ) ~... |
let draw_block field ~ color ~ block ~ x ~ y = for iy = 0 to 3 do let base = ref 1 in let xd = block . ( iy ) in for ix = 0 to 3 do if xd land ! base <> 0 then cell_set field ~ x ( : ix + x ) ~ y ( : iy + y ) ~ color ; base := ! base lsl 1 done done |
let timer_ref = ( ref None : Timer . t option ref ) |
let remove_timer ( ) = match ! timer_ref with None -> ( ) | Some t -> Timer . remove t |
let do_after ~ ms ~ callback = timer_ref := Some ( Timer . add ~ ms ~ callback ) |
let copy_block c = { pattern = ! c . pattern ; bcolor = ! c . bcolor ; x = ! c . x ; y = ! c . y ; d = ! c . d ; alive = ! c . alive } |
let _ = let top = openTk ( ) in let lb = Label . create top and fw = Frame . create top in let set_message s = Label . configure lb ~ text : s in pack [ coe lb ; coe fw ] ~ side : ` Top ; let score = ref 0 in let line = ref 0 in let level = ref 0 in let time = ref 1000 in let block... |
let _ = Printexc . print mainLoop ( ) |
let brand_points = ba2_glefloat_of_array [ | [ | 0 . 0 ; 0 . 0 ; 0 . 1 ] ; | [ | 0 . 0 ; 0 . 0 ; 0 . 0 ] ; | [ | 0 . 0 ; 0 . 0 ; - 5 . 0 ] ; | [ | 0 . 0 ; 0 . 0 ; - 5 . 1 ] ; | ] | |
let brand_colors = ba2_float32_of_array [ | [ | 1 . 0 ; 0 . 3 ; 0 . 0 ] ; | [ | 1 . 0 ; 0 . 3 ; 0 . 0 ] ; | [ | 1 . 0 ; 0 . 3 ; 0 . 0 ] ; | [ | 1 . 0 ; 0 . 3 ; 0 . 0 ] ; | ] | |
let tnum , tspine = let tcoords = [ | ( - 1 . 5 , 2 . 0 ) ; ( - 0 . 75 , 2 . 0 ) ; ( - 0 . 75 , 1 . 38 ) ; ( - 0 . 5 , 1 . 25 ) ; ( 0 . 88 , 1 . 12 ) ; ( 1 . 0 , 0 . 62 ) ; ( 1 . 12 , 0 . 1 ) ; ( ... |
let tcolors = ( ba2_float32_create tnum 3 ) |
let ( += ) a b = ( a := ! a + b ) |
let ( %= ) a b = ( a := ! a mod b ) |
let init_spine ( ) = let ir = ref 0 and ig = ref 0 and ib = ref 0 in for i = 0 to pred tnum do ir += 33 ; ig += 47 ; ib += 89 ; ir %= 255 ; ig %= 255 ; ib %= 255 ; let r = ( float ! ir ) . / 255 . 0 and g = ( float ! ig ) . / 255 . 0 and b = ( float ! i... |
let coords = [ ( - 0 . 75 , 2 . 0 ) ; ( - 0 . 75 , 1 . 38 ) ; ( - 0 . 5 , 1 . 25 ) ; ( 0 . 88 , 1 . 12 ) ; ( 1 . 0 , 0 . 62 ) ; ( 1 . 12 , 0 . 1 ) ; ( 0 . 5 , - 0 . 5 ) ; ( 0 . 2 , - 1 . 12... |
let ncoords = List . length coords |
let texas_xsection = ( ba2_glefloat_create ncoords 2 ) |
let texas_normal = ( ba2_glefloat_create ncoords 2 ) |
let border i ( x , y ) = texas_xsection . { i , 0 } <- scale . * ( x ) ; texas_xsection . { i , 1 } <- scale . * ( y ) ; if i <> 0 then begin let ax = texas_xsection . { i , 0 } . - texas_xsection . { i - 1 , 0 } and ay = texas_xsection . { i ,... |
let init_xsection ( ) = ignore ( List . fold_left border 0 coords ) ; ; ; |
let init_stuff ( ) = init_spine ( ) ; init_xsection ( ) ; gleSetJoinStyle [ TUBE_JN_CAP ; TUBE_CONTOUR_CLOSED ; TUBE_NORM_FACET ; TUBE_JN_ANGLE ] ; ; ; |
let draw_stuff ( ) = glClear [ GL_COLOR_BUFFER_BIT ; GL_DEPTH_BUFFER_BIT ] ; glPushMatrix ( ) ; glTranslatev ( 0 . 0 , 0 . 0 , - 80 . 0 ) ; glRotate ( float ! lastx ) 0 . 0 1 . 0 0 . 0 ; glRotate ( float ! lasty ) 1 . 0 0 . 0 0 . 0 ; gleExt... |
let makeStripeImage ( ) = let stripeImage = Bigarray . Array1 . create Bigarray . int8_unsigned Bigarray . c_layout ( 4 * stripeImageWidth ) in for j = 0 to pred stripeImageWidth do stripeImage . { 4 * j } <- ( if j <= 4 then 255 else 0 ) ; stripeImage . { 4 * j + 1 } ... |
let xequalzero = ( 1 . 0 , 0 . 0 , 0 . 0 , 0 . 0 ) |
let slanted = ( 1 . 0 , 1 . 0 , 1 . 0 , 0 . 0 ) |
let currentCoeff = ref xequalzero |
let currentPlane = ref GL_OBJECT_PLANE |
let currentGenMode = ref GL_OBJECT_LINEAR |
let init ( ) = glClearColor 0 . 0 0 . 0 0 . 0 0 . 0 ; glEnable GL_DEPTH_TEST ; glShadeModel GL_SMOOTH ; let stripeImage = makeStripeImage ( ) in glPixelStorei GL_UNPACK_ALIGNMENT 1 ; let texName = glGenTexture ( ) in glBindTexture BindTex . GL_TEXTURE_1D texName ; glTexParame... |
let display texName ( ) = glClear [ GL_COLOR_BUFFER_BIT ; GL_DEPTH_BUFFER_BIT ] ; glPushMatrix ( ) ; glRotate 45 . 0 0 . 0 0 . 0 1 . 0 ; glBindTexture BindTex . GL_TEXTURE_1D texName ; glutSolidTeapot 2 . 0 ; glPopMatrix ( ) ; glFlush ( ) ; ; ; |
let reshape ~ width : w ~ height : h = glViewport 0 0 w h ; glMatrixMode GL_PROJECTION ; glLoadIdentity ( ) ; let w = float w and h = float h in if w <= h then glOrtho ( - 3 . 5 ) ( 3 . 5 ) ( - 3 . 5 . * h . / w ) ( 3 . 5 . * h . / w ) ( - 3 . 5 )... |
let keyboard ~ key ~ x ~ y = match key with | ' e ' | ' E ' -> currentGenMode := GL_EYE_LINEAR ; currentPlane := GL_EYE_PLANE ; glTexGen GL_S GL_TEXTURE_GEN_MODE ! currentGenMode ; glTexGenv GL_S ! currentPlane ! currentCoeff ; glutPostRedisplay ( ) ; | ' o ' | ' O ' -> curr... |
let ( ) = let _ = glutInit Sys . argv in glutInitDisplayMode [ GLUT_SINGLE ; GLUT_RGB ; GLUT_DEPTH ] ; glutInitWindowSize 256 256 ; glutInitWindowPosition 100 100 ; let _ = glutCreateWindow Sys . argv . ( 0 ) in let texName = init ( ) in glutDisplayFunc ~ display ( : displ... |
unsigned short imagic ; unsigned short type ; unsigned short dim ; unsigned short xsize , ysize , zsize ; unsigned int min , max ; unsigned int wasteBytes ; char name [ 80 ] ; unsigned long colorMap ; FILE * file ; unsigned char * tmp ; unsigned long rleEnd ; unsigned int * rowStart ... |
type environment = | Normal | Caml | Verbatim of string * string | Verbatim_like |
let in_quotes = ref false |
let is_alpha c = ( ' A ' <= c && c <= ' Z ' ) || ( ' a ' <= c && c <= ' z ' ) |
let is_prefix prefix str = let length_prefix = String . length prefix in let length_str = String . length str in if length_prefix > length_str then false else ( String . sub str 0 length_prefix ) = prefix |
let escape = function | ' ' | ' \ n ' -> " \\ " | ' { ' -> " { \\ char123 } " | ' } ' -> " { \\ char125 } " | ' ' ^ -> " { \\ char94 } " | ' _ ' -> " { \\ char95 } " | ' ' \\ -> " { \\ char92 } " | ' ' ~ -> " { ... |
let process_normal_line line = let ( verb_mark : char option ref ) = ref None in let l = String . length line in let i = ref 0 in while ! i < l do match ! verb_mark with | None -> ( match line . [ ! i ] with | ' " ' -> let r = if ! in_quotes then " } } " else " { \\ mach... |
let process_line line = function | Normal -> if is_prefix " \\ begin { caml_ " line || is_prefix " \\ begin { rawhtml } " line then ( print_string line ; Verbatim_like ) else if is_prefix " \\ begin { camlexample } " line then ( print_endline line ; Caml ) else if is_prefix " ... |
let rec process_input env = match input_line stdin with | exception End_of_file -> ( ) | line -> let env = process_line line env in process_input env |
let main ( ) = print_endline " % THIS FILE IS GENERATED . " ; print_newline ( ) ; process_input Normal |
let top = opentk ( ) |
let scroll_link sb tx = Text . configure tx [ YScrollCommand ( Scrollbar . set sb ) ] ; Scrollbar . configure sb [ ScrollCommand ( Text . yview tx ) ] |
let f = Frame . create top [ ] |
let text = Text . create f [ ] |
let scrollbar = Scrollbar . create f [ ] |
let buffer = ref " " |
let kill ( ) = buffer := Text . get text ( TextIndex ( Insert , [ ] ) ) ( TextIndex ( Insert , [ LineEnd ] ) ) ; Text . delete text ( TextIndex ( Insert , [ ] ) ) ( TextIndex ( Insert , [ LineEnd ] ) ) ; ; |
let yank ( ) = Text . insert text ( TextIndex ( Insert , [ ] ) ) ! buffer [ ] |
let _ = bind text [ [ Control ] , KeyPressDetail " y " ] ( BindSet ( [ ] , fun _ -> yank ( ) ) ) ; ; |
let _ = bind text [ [ Control ] , KeyPressDetail " k " ] ( BindSet ( [ ] , fun _ -> kill ( ) ) ) ; ; |
let _ = scroll_link scrollbar text ; pack [ text ; f ] [ ] ; pack [ f ] [ ] ; mainLoop ( ) ; ; |
let ( ) = let text = " joy " in let surface = Cairo . Image . create Cairo . Image . ARGB32 ~ w : 600 ~ h : 600 in let cr = Cairo . create surface in Cairo . scale cr 600 . 600 . ; Cairo . set_font_size cr 0 . 5 ; Cairo . set_source_rgb cr 0 . 0 0 . 0 0 . 0 ; ... |
type stats = int * int * int * int * int array |
let lines ( l , _ , _ , _ , _ ) = l |
let characters ( _ , c , _ , _ , _ ) = c |
let words ( _ , _ , w , _ , _ ) = w |
let sentences ( _ , _ , _ , s , _ ) = s |
let frequency ( _ , _ , _ , _ , h ) x = h . ( int_of_char x ) |
let stats_from_channel in_channel = let lines = ref 0 and characters = ref 0 and words = ref 0 and sentences = ref 0 and histogram = Array . make 256 0 in try while true do let line = input_line in_channel in lines := ! lines + 1 ; characters := ! characters + String . length line ; String .... |
let stats_from_file filename = let channel = open_in filename in let result = stats_from_channel channel in close_in channel ; result |
let texpts = [ [ || 0 . 0 ; 0 . 0 ; 0 . 0 ; 1 . 0 ] ; | [ | 1 . 0 ; 0 . 0 ; 1 . 0 ; 1 . 0 ] ] || |
let ctrlpoints = [ [ ||- 1 . 5 ; - 1 . 5 ; 4 . 9 ; - 0 . 5 ; - 1 . 5 ; 2 . 0 ; 0 . 5 ; - 1 . 5 ; - 1 . 0 ; 1 . 5 ; - 1 . 5 ; 2 . 0 ] ; | [ |- 1 . 5 ; - 0 . 5 ; 1 . 0 ; - 0 . 5 ; - 0 . 5 ; 3 . 0 ... |
let pi = acos ( - 1 . 0 ) |
let display togl = GlClear . clear [ ` color ; ` depth ] ; GlDraw . color ( 1 . 0 , 1 . 0 , 1 . 0 ) ; GlMap . eval_mesh2 ~ mode ` : fill ~ range1 ( : 0 , 20 ) ~ range2 ( : 0 , 20 ) ; Gl . flush ( ) ; Togl . swap_buffers togl |
let make_image ( ) = let image = GlPix . create ` ubyte ~ height : image_height ~ width : image_width ~ format ` : rgb in let raw = GlPix . to_raw image and pos = GlPix . raw_pos image in for i = 0 to image_width - 1 do let ti = 2 . 0 . * pi . * float i . / float image_width in... |
let myinit ( ) = let ctrlpoints = Raw . of_matrix ~ kind ` : double ctrlpoints and texpts = Raw . of_matrix ~ kind ` : double texpts in GlMap . map2 ~ target ` : vertex_3 ( 0 . 0 , 1 . 0 ) ~ order : 4 ( 0 . 0 , 1 . 0 ) ~ order : 4 ctrlpoints ; GlMap . map2 ... |
let my_reshape togl = let h = Togl . height togl and w = Togl . width togl in GlDraw . viewport ~ x : 0 ~ y : 0 ~ w ~ h ; GlMat . mode ` projection ; GlMat . load_identity ( ) ; let r = float h . / float w in if w <= h then GlMat . ortho ~ x ( :- 4 . 0 , 4 . 0 ) ... |
let main ( ) = let top = openTk ( ) in let togl = Togl . create top ~ rgba : true ~ depth : true ~ width : 300 ~ height : 300 ~ double : true in Wm . title_set top " Texture Surf " ; myinit ( ) ; Togl . reshape_func togl ~ cb ( : fun ( ) -> my_reshape togl ) ; Togl ... |
let _ = main ( ) |
type bunny = { position : Raylib . Vector2 . t ; speed : Raylib . Vector2 . t ; color : Raylib . Color . t ; } |
let setup ( ) = let open Raylib in init_window width height " raylib [ textures ] example - bunnymark " ; let tex_bunny = load_texture " resources / wabbit_alpha . png " in set_target_fps 60 ; tex_bunny |
let rec loop bunnies bunnies_count tex_bunny = match Raylib . window_should_close ( ) with | true -> Raylib . close_window ( ) | false -> let open Raylib in let bunnies , bunnies_count = if is_mouse_button_down MouseButton . Left then let rec inner bunnies bunnies_count = function | 0 -> ( b... |
let ( ) = setup ( ) |> loop [ ] || 0 |
type vec2 = { x : float ; y : float } |
type bunny = { position : vec2 ; speed : vec2 ; color : Raylib . Color . t } |
let setup ( ) = let open Raylib in init_window width height " raylib [ textures ] example - bunnymark " ; let tex_bunny = load_texture " resources / wabbit_alpha . png " in set_target_fps 60 ; tex_bunny |
let rec loop bunnies bunnies_count tex_bunny = match Raylib . window_should_close ( ) with | true -> Raylib . close_window ( ) | false -> let open Raylib in let bunnies , bunnies_count = if is_mouse_button_down MouseButton . Left then let rec inner bunnies bunnies_count = function | 0 -> ( b... |
let ( ) = setup ( ) |> loop [ ] || 0 |
let position = Raylib . Vector2 . create 350 . 0 280 . 0 |
let setup ( ) = let open Raylib in init_window width height " raylib [ textures ] example - texture rectangle " ; let scarfy = load_texture " resources / scarfy . png " in let frame_rec = Rectangle . create 0 . 0 0 . 0 ( Float . of_int ( Texture . width scarfy ) . / 6 . ... |
let rec loop scarfy frame_rec counter frame frames_speed = match Raylib . window_should_close ( ) with | true -> Raylib . close_window ( ) | false -> let open Raylib in let module R = Raylib . Rectangle in let counter = succ counter in let counter , frame , frame_rec = if counter >= 60 / fr... |
let ( ) = let scarfy , frame_rec = setup ( ) in loop scarfy frame_rec 0 0 8 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.