Boids/Wren: Difference between revisions

m
→‎Code: Capitalize Wren file name.
(Added code page.)
 
m (→‎Code: Capitalize Wren file name.)
 
(6 intermediate revisions by the same user not shown)
Line 2:
 
==Code==
 
=={{header|Wren}}==
{{trans|C}}
{{libheader|FreeGLUT}}
{{libheader|Wren-dynamic}}
{{libheader|Wren-fmt}}
<br>
As it's not currently possible for Wren-cli to access OpenGL directly, we embed a Wren script in a C application to complete this task. See the [[OpenGL#Wren]] task for some of the issues involved here.
<langsyntaxhighlight ecmascriptlang="wren">/* boidsBoids.wren */
 
import "random" for Random
Line 556:
Boids[i].speed = (0.98 + 0.04 * Rand.float()) * MOVE_SPEED
}
InitGL.call()</langsyntaxhighlight>
<br>
We now embed this Wren script in the following C program, compile and run it.
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Line 960:
vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "boidsBoids.wren";
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
Line 977:
free(script);
return 0;
}</langsyntaxhighlight>
 
{{out}}
9,482

edits