Last active
November 30, 2022 06:54
-
-
Save owulveryck/3c48bd15d1bbc146e5d70ff8e5f5c39e to your computer and use it in GitHub Desktop.
Article Wardley sources
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Stages of evolution | |
package main | |
import ( | |
"image/color" | |
"log" | |
"math" | |
"os" | |
"golang.org/x/image/font/opentype" | |
"gonum.org/v1/plot" | |
"gonum.org/v1/plot/font" | |
"gonum.org/v1/plot/plotter" | |
) | |
func main() { | |
ttf, err := os.ReadFile("CenturyGothic.ttf") | |
if err != nil { | |
panic(err) | |
} | |
fontTTF, err := opentype.Parse(ttf) | |
if err != nil { | |
log.Fatal(err) | |
} | |
centuryGothic := font.Font{Typeface: "Century Gothic"} | |
font.DefaultCache.Add([]font.Face{ | |
{ | |
Font: centuryGothic, | |
Face: fontTTF, | |
}, | |
}) | |
plot.DefaultFont = centuryGothic | |
sigmoid := func(x float64) float64 { | |
return (1.0 / (1.0 + 0.2*math.Exp(-x))) | |
} | |
line := plotter.NewFunction(sigmoid) | |
line.Width = 4 | |
line.Samples = 5000 | |
line.Color = color.RGBA{R: 47, G: 175, B: 200, A: 255} | |
p := plot.New() | |
// p.Add(line2) | |
p.Y.Max = 1.1 | |
p.Y.Min = 0 | |
p.X.Max = 5 | |
p.X.Min = -5 | |
steps := []stage{ | |
{name: "", evolution: 0}, | |
{name: "Genesis", evolution: 20, color: color.RGBA{R: 43, G: 162, B: 188, A: 255}}, | |
{name: "Custom Built", evolution: 40, color: color.RGBA{R: 100, G: 194, B: 211, A: 255}}, | |
{name: "Product + Rental", evolution: 70, color: color.RGBA{R: 135, G: 208, B: 221, A: 255}}, | |
{name: "Commodity", evolution: 100, color: color.RGBA{R: 219, G: 241, B: 245, A: 255}}, | |
} | |
for i, s := range steps { | |
if i == 0 { | |
continue | |
} | |
var x0, x1, y0, y1 float64 | |
x0 = (p.X.Max-p.X.Min)*steps[i-1].evolution/100 + p.X.Min - (p.X.Max-p.X.Min)*0.03 | |
x1 = (p.X.Max-p.X.Min)*steps[i].evolution/100 + p.X.Min + (p.X.Max-p.X.Min)*0.03 | |
y0 = sigmoid(x0) - 0.03*(p.Y.Max+p.Y.Min) | |
y1 = sigmoid(x1) + 0.03*(p.Y.Max+p.Y.Min) | |
stage, err := plotter.NewLine(plotter.XYs{ | |
{X: x0, Y: y0}, {X: x0, Y: y1}, {X: x1, Y: y1}, {X: x1, Y: y0}, {X: x0, Y: y0}, | |
}) | |
if err != nil { | |
log.Panic(err) | |
} | |
stage.FillColor = s.color | |
stage.Color = s.color | |
p.Add(stage) | |
p.Legend.Add(s.name, stage) | |
} | |
for _, s := range steps { | |
x := (p.X.Max-p.X.Min)*s.evolution/100 + p.X.Min | |
stage, err := plotter.NewLine(plotter.XYs{ | |
{X: x, Y: p.Y.Min}, | |
{X: x, Y: p.Y.Max}, | |
}) | |
if err != nil { | |
log.Panic(err) | |
} | |
if s.evolution != 100 { | |
p.Add(stage) | |
} | |
} | |
p.X.Label.Text = "Certitude" | |
p.X.Label.TextStyle.Color = color.RGBA{R: 33, G: 44, B: 93, A: 255} | |
p.X.Tick.Marker = &ticker{} | |
p.Y.Tick.Marker = &ticker{} | |
p.Y.Label.TextStyle.Color = color.RGBA{R: 33, G: 44, B: 93, A: 255} | |
p.Y.Label.Text = "Présence" | |
p.Title.Text = "Activités" | |
p.Add(line) | |
w, err := p.WriterTo(600, 400, "png") | |
if err != nil { | |
log.Panic(err) | |
} | |
_, err = w.WriteTo(os.Stdout) | |
if err != nil { | |
log.Panic(err) | |
} | |
} | |
type ticker struct{} | |
// Ticks returns Ticks in a specified range | |
func (ticker *ticker) Ticks(min float64, max float64) []plot.Tick { | |
return []plot.Tick{} | |
} | |
type stage struct { | |
name string | |
evolution float64 | |
color color.Color | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
title Salon de thé | |
anchor Business [0.95, 0.63] | |
anchor Public [0.95, 0.78] | |
component Tasse de thé [0.79, 0.61] label [19, -4] | |
component Tasse [0.73, 0.78] | |
component Thé [0.63, 0.81] | |
component Eau Chaude [0.52, 0.80] | |
component Eau [0.38, 0.82] | |
component Bouilloire [0.38, 0.65] label [-66, -33] | |
component Power [0.1, 0.7] label [-27, 20] | |
Business->Tasse de thé | |
Public->Tasse de thé | |
Tasse de thé->Tasse | |
Tasse de thé->Thé | |
Tasse de thé->Eau Chaude | |
Eau Chaude->Eau | |
Eau Chaude->Bouilloire | |
Bouilloire->Power |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
title Salon de thé | |
anchor Business [0.95, 0.06] | |
anchor Public [0.95, 0.14] | |
component Tasse de thé [0.78, 0.09] label [19, -4] | |
component Tasse [0.73, 0.12] label [6, 30] | |
component Thé [0.58, 0.05] | |
component Eau Chaude [0.44, 0.10] | |
component Eau [0.38, 0.14] label [-22, 23] | |
component Bouilloire [0.30, 0.10] label [-66, -33] | |
component Power [0.12, 0.10] label [-27, 20] | |
Business->Tasse de thé | |
Public->Tasse de thé | |
Tasse de thé->Tasse | |
Tasse de thé->Thé | |
Tasse de thé->Eau Chaude | |
Eau Chaude->Eau | |
Eau Chaude->Bouilloire | |
Bouilloire->Power |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment