-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathScript_Grant_Random_Shapes.fsx
More file actions
54 lines (44 loc) · 1.65 KB
/
Script_Grant_Random_Shapes.fsx
File metadata and controls
54 lines (44 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#r "references/OpenTK.dll"
#r "references/OpenTK.GLControl.dll"
#r "references/FSharp.Data.dll"
#load "functional3d.fs"
#load "TryFsharpUtilities.fs"
open Functional3D
open TryFsharpUtilities
open System.Drawing
open FSharp.Data
open TryFs
type Shape =
| Cube of float
| Cuboid of float * float * float
| Cone of float * float
| Cylinder of float * float
type Object3D = { shape:Shape; coords:float * float * float; colour:Color }
let draw objects =
objects
|> List.map(fun object3D ->
let x,y,z = object3D.coords
let colour = object3D.colour
match object3D.shape with
| Cube(size) -> TryFs.cube x y z size colour
| Cuboid(length, height, depth) -> TryFs.cuboid x y z length height depth colour
| Cylinder(height, radius) -> TryFs.cylinder x y z height radius colour
| Cone(height, radius) -> TryFs.cone x y z height radius colour)
|> showEm
let rand = System.Random()
let nextRand(limit) = rand.Next(limit)
let randomColour() =
Color.FromArgb(nextRand(255), nextRand(255), nextRand(255))
let randomShape() =
match nextRand(4) with
| 0 -> {shape=Cone(0.3,0.3); coords=0.,0.,0.; colour = Color.Purple }
| 1 -> {shape=Cylinder(0.4,0.3); coords=0.,0.,0.; colour = Color.Purple }
| 2 -> {shape=Cube(0.2); coords=0.,0.,0.; colour = Color.Purple }
| _ -> {shape=Cuboid(0.2,0.1,0.3); coords=0.,0.,0.; colour = Color.Purple }
let randomShapes scope =
[for x = -scope to scope do
for y = -scope to scope do
for z = -scope to scope do
yield {randomShape() with coords = x,y,z; colour=randomColour() }]
|> draw
randomShapes 6.0