Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Struct And Simulation Uebung 2 Monte Carlo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Torda, Prof. Dr. Andrew Ernest
Struct And Simulation Uebung 2 Monte Carlo
Commits
b39ba4c8
Commit
b39ba4c8
authored
4 years ago
by
Andrew E. Torda
Browse files
Options
Downloads
Patches
Plain Diff
Almost working version with vicious had to over-ride the default render function.
parent
58009410
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
screenplot.go
+50
-54
50 additions, 54 deletions
screenplot.go
with
50 additions
and
54 deletions
screenplot.go
+
50
−
54
View file @
b39ba4c8
...
@@ -4,79 +4,64 @@ package main
...
@@ -4,79 +4,64 @@ package main
import
(
import
(
"fmt"
"fmt"
"image"
"math"
"image/color"
"image/draw"
ui
"github.com/gizak/termui/v3"
ui
"github.com/gizak/termui/v3"
"github.com/gizak/termui/v3/widgets"
"github.com/gizak/termui/v3/widgets"
)
)
func
breaker
(
x
interface
{})
{}
func
breaker
(
x
interface
{})
{}
func
scrnPlt
(
pi
,
stdErr
[]
float32
)
error
{
func
copyToData
(
y
[]
float32
)
([][]
float64
){
nrmlStyle
:=
ui
.
NewStyle
(
ui
.
ColorBlack
,
ui
.
ColorClear
)
data
:=
make
([]
float64
,
len
(
y
))
// invisStyle := ui.NewStyle (ui.ColorClear, ui.ColorClear)
for
i
:=
range
y
{
thm
:=
ui
.
Theme
data
[
i
]
=
float64
(
y
[
i
])
thm
.
Block
.
Title
=
nrmlStyle
}
thm
.
Plot
.
Axes
=
ui
.
ColorBlack
data
[
0
]
=
data
[
1
]
return
[][]
float64
{
data
}
}
thm
.
Default
=
ui
.
NewStyle
(
ui
.
ColorBlack
,
ui
.
ColorClear
)
thm
.
Block
.
Border
=
nrmlStyle
ui
.
Theme
=
thm
func
scrnPlt
(
pi
,
stdErr
[]
float32
)
error
{
fmt
.
Println
()
marker
:=
widgets
.
MarkerDot
dotMarkerRune
:=
'.'
ptxt
:=
widgets
.
NewParagraph
()
for
i
:=
0
;
i
<
24
;
i
++
{
for
j
:=
0
;
j
<
800
;
j
++
{
ptxt
.
Text
+=
"."
}
ptxt
.
Text
+=
"
\n
"
}
ptxt
.
SetRect
(
0
,
0
,
80
,
24
)
ptxt
.
TextStyle
=
ui
.
NewStyle
(
ui
.
ColorWhite
,
ui
.
ColorWhite
)
p1
:=
widgets
.
NewPlot
()
p1
:=
widgets
.
NewPlot
()
p1
.
Title
=
"π"
p1
.
Title
=
"π"
{
p1
.
Data
=
copyToData
(
pi
)
data
:=
make
([][]
float64
,
2
)
p1
.
Marker
=
marker
data
[
0
]
=
make
([]
float64
,
len
(
pi
))
p1
.
DotMarkerRune
=
dotMarkerRune
data
[
1
]
=
make
([]
float64
,
len
(
pi
))
for
i
:=
range
pi
{
data
[
0
][
i
]
=
float64
(
i
+
1
)
data
[
1
][
i
]
=
float64
(
pi
[
i
])
}
p1
.
Data
=
data
}
p1
.
SetRect
(
2
,
2
,
80
,
24
)
p1
.
Block
.
TitleStyle
=
nrmlStyle
p1
.
AxesColor
=
ui
.
ColorBlack
// p1.LineColors = []ui.Color{ui.ColorBlack, ui.ColorBlack}
p1
.
SetRect
(
0
,
0
,
80
,
24
)
p1
.
Marker
=
widgets
.
MarkerBraille
p1
.
PlotType
=
widgets
.
ScatterPlot
p1
.
PlotType
=
widgets
.
ScatterPlot
p1
.
Border
=
fals
e
p1
.
Border
=
tru
e
breaker
(
thm
)
p2
:=
widgets
.
NewPlot
()
p2
.
Title
=
"standard error"
p2
.
Data
=
copyToData
(
stdErr
)
p2
.
DotMarkerRune
=
dotMarkerRune
p2
.
Marker
=
marker
m
:=
image
.
NewRGBA
(
image
.
Rect
(
0
,
0
,
80
,
24
))
p3
:=
widgets
.
NewPlot
()
p3
.
Title
=
"abs error"
{
d
:=
make
([]
float64
,
len
(
pi
))
for
i
,
piV
:=
range
pi
{
d
[
i
]
=
math
.
Pi
-
float64
(
piV
)
}
p3
.
Data
=
[][]
float64
{
d
}
}
// draw.Draw(m, m.Bounds(), &image.Uniform{color.White}, image.ZP, draw.Src)
draw
.
Draw
(
m
,
m
.
Bounds
(),
&
image
.
Uniform
{
color
.
White
},
image
.
ZP
,
draw
.
Src
)
img
:=
widgets
.
NewImage
(
m
)
img
.
SetRect
(
0
,
0
,
100
,
50
)
defer
fmt
.
Println
(
"m bounds"
,
m
.
Bounds
())
if
err
:=
ui
.
Init
();
err
!=
nil
{
if
err
:=
ui
.
Init
();
err
!=
nil
{
return
err
return
err
}
}
defer
ui
.
Close
()
defer
ui
.
Close
()
grid
:=
ui
.
NewGrid
()
termWidth
,
termHeight
:=
ui
.
TerminalDimensions
()
grid
.
SetRect
(
0
,
0
,
termWidth
,
termHeight
)
grid
.
Set
(
ui
.
NewRow
(
1.
/
3
,
p1
),
ui
.
NewRow
(
1.
/
3
,
p2
),
ui
.
NewRow
(
1.
/
3
,
p3
))
ui
.
R
ender
(
img
,
ptxt
,
p1
)
r
ender
(
grid
)
for
e
:=
range
ui
.
PollEvents
()
{
for
e
:=
range
ui
.
PollEvents
()
{
if
e
.
Type
==
ui
.
KeyboardEvent
{
if
e
.
Type
==
ui
.
KeyboardEvent
{
break
break
...
@@ -84,3 +69,14 @@ func scrnPlt(pi, stdErr []float32) error {
...
@@ -84,3 +69,14 @@ func scrnPlt(pi, stdErr []float32) error {
}
}
return
nil
return
nil
}
}
// This was how I wanted to do it, but the library does
// not seem to respect background colours.
// ui.Theme = thm
// nrmlStyle := ui.NewStyle (ui.ColorWhite, ui.ColorBlack)
// thm := ui.Theme
// thm.Block.Title = nrmlStyle
// thm.Plot.Axes = ui.ColorWhite
// thm.Plot.Lines = []ui.Color{ui.ColorWhite}
// thm.Default = ui.NewStyle(ui.ColorWhite, ui.ColorBlack)
// thm.Block.Border = nrmlStyle
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment