Skip to content

Commit a511d5b

Browse files
author
Jan Van Bruggen
authored
Merge pull request #2 from JanCVanB/add_examples
Add more examples
2 parents 4a12599 + 4ee6adb commit a511d5b

File tree

12 files changed

+368
-261
lines changed

12 files changed

+368
-261
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[Plotters](https://github.com/38/plotters)
66
= <3
77

8-
![hello world example image](./examples/hello_world.svg)
8+
![example image](./examples/math.svg)
99

1010
## How to example
1111

examples/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
# built executables
22
hello_world
3+
math
4+
shapes

examples/hello_world.jpg

-73.5 KB
Binary file not shown.

examples/hello_world.png

-16.3 KB
Loading

examples/hello_world.roc

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,37 @@
11
app "hello_world"
22
packages { pf: "../platform" }
3-
imports [ pf.Config.{blue, green, red, cyan} ]
3+
imports [ pf.Config ]
44
provides [ config ] to pf
55

66
config =
77
{
8-
outputFilePath: "./examples/hello_world.svg",
8+
outputFilePath: "./examples/hello_world.png",
99
title: "Hello, World!",
1010
subtitle: "",
11-
width: 1024,
12-
height: 768,
11+
width: 800,
12+
height: 600,
1313
lines: [
14-
{ name: "cosine", color: green, points: cos },
15-
{ name: "cosine x 2", color: cyan, points: cosX2 },
16-
{ name: "sine", color: blue, points: sin },
17-
{ name: "sine x 2", color: red, points: sinX2 },
14+
{ name: "up", color: Config.green, points: [P2 -1 -1, P2 1 1] },
15+
{ name: "down", color: Config.red, points: [P2 -1 1, P2 1 -1] },
1816
],
1917
bounds: {
20-
xMin: -3.2,
21-
xMax: 3.2,
22-
yMin: -2.1,
23-
yMax: 2.1,
24-
},
25-
fonts: {
26-
titleFamily: "sans-serif",
27-
titleSize: 60,
28-
subtitleFamily: "sans-serif",
29-
subtitleSize: 40,
18+
xMin: -1.1,
19+
xMax: 1.1,
20+
yMin: -1.1,
21+
yMax: 1.1,
3022
},
3123
labels: {
32-
xCount: 20,
33-
yCount: 10,
24+
xCount: 3,
25+
yCount: 3,
3426
},
3527
layout: {
3628
chartMargin: 5,
3729
labelArea: 50,
3830
},
31+
fonts: {
32+
titleFamily: "sans-serif",
33+
titleSize: 60,
34+
subtitleFamily: "sans-serif",
35+
subtitleSize: 40,
36+
},
3937
}
40-
41-
pi = 3.141592653589793
42-
ok = \r -> Result.withDefault r 0
43-
domain = List.range -100 101 |> List.map (\i -> pi * (Num.toFloat i) / 100 |> ok)
44-
cos = domain |> List.map (\x -> P2 x (Num.cos x))
45-
sin = domain |> List.map (\x -> P2 x (Num.sin x))
46-
cosX2 = domain |> List.map (\x -> P2 x (2 * Num.cos x))
47-
sinX2 = domain |> List.map (\x -> P2 x (2 * Num.sin x))

examples/hello_world.svg

Lines changed: 0 additions & 207 deletions
This file was deleted.

examples/math.roc

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
app "math"
2+
packages { pf: "../platform" }
3+
imports [ pf.Config ]
4+
provides [ config ] to pf
5+
6+
config =
7+
{
8+
outputFilePath: "./examples/math.svg",
9+
title: "Math",
10+
subtitle: "This is what math looks like.",
11+
width: 800,
12+
height: 600,
13+
lines: [
14+
{ name: "cosine", color: Config.green, points: cos },
15+
{ name: "cosine x 2", color: Config.cyan, points: cosX2 },
16+
{ name: "sine", color: Config.blue, points: sin },
17+
{ name: "- sine", color: Config.red, points: sinNeg },
18+
],
19+
bounds: {
20+
xMin: -3.2,
21+
xMax: 3.2,
22+
yMin: -2.1,
23+
yMax: 2.1,
24+
},
25+
labels: {
26+
xCount: 20,
27+
yCount: 10,
28+
},
29+
layout: {
30+
chartMargin: 5,
31+
labelArea: 50,
32+
},
33+
fonts: {
34+
titleFamily: "sans-serif",
35+
titleSize: 60,
36+
subtitleFamily: "sans-serif",
37+
subtitleSize: 40,
38+
},
39+
}
40+
41+
pi = 3.141592653589793
42+
ok = \r -> Result.withDefault r 0
43+
domain = List.range -100 101 |> List.map (\i -> pi * (Num.toFloat i) / 100 |> ok)
44+
cos = domain |> List.map (\x -> P2 x (Num.cos x))
45+
sin = domain |> List.map (\x -> P2 x (Num.sin x))
46+
cosX2 = domain |> List.map (\x -> P2 x (2 * Num.cos x))
47+
sinNeg = domain |> List.map (\x -> P2 x (0 - Num.sin x))

examples/math.svg

Lines changed: 210 additions & 0 deletions
Loading

examples/shapes.jpg

29.5 KB
Loading

examples/shapes.roc

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
app "shapes"
2+
packages { pf: "../platform" }
3+
imports [ pf.Config ]
4+
provides [ config ] to pf
5+
6+
config =
7+
{
8+
outputFilePath: "./examples/shapes.jpg",
9+
title: "Shapes",
10+
subtitle: "",
11+
width: 800,
12+
height: 600,
13+
lines: [
14+
{
15+
name: "rectangle",
16+
color: Config.red,
17+
points: [
18+
P2 0.1 0.3,
19+
P2 0.2 0.3,
20+
P2 0.2 0.2,
21+
P2 0.1 0.2,
22+
P2 0.1 0.3,
23+
],
24+
},
25+
{
26+
name: "triangle",
27+
color: Config.green,
28+
points: [
29+
P2 0.4 0.6,
30+
P2 0.5 1.0,
31+
P2 0.6 0.6,
32+
P2 0.4 0.6,
33+
],
34+
},
35+
{
36+
name: "plus",
37+
color: Config.blue,
38+
points: [
39+
P2 0.6 0.3, P2 0.8 0.3,
40+
P2 0.7 0.3,
41+
P2 0.7 0.4, P2 0.7 0.2,
42+
],
43+
},
44+
],
45+
bounds: {
46+
xMin: 0,
47+
xMax: 1,
48+
yMin: 0,
49+
yMax: 1,
50+
},
51+
labels: {
52+
xCount: 5,
53+
yCount: 5,
54+
},
55+
layout: {
56+
chartMargin: 5,
57+
labelArea: 50,
58+
},
59+
fonts: {
60+
titleFamily: "sans-serif",
61+
titleSize: 60,
62+
subtitleFamily: "sans-serif",
63+
subtitleSize: 40,
64+
},
65+
}

0 commit comments

Comments
 (0)