Browse Source

Gauß-Kurve mit Qt-Go funktioniert endlich

master
Klaus Wendel 5 years ago
parent
commit
fdc2251270
  1. BIN
      go2lgl_l01/go2lgl_l01
  2. BIN
      go2lgl_l02/go2lgl_l02
  3. BIN
      go2lgl_l03/go2lgl_l03
  4. BIN
      go2lgl_l04/go2lgl_l04
  5. BIN
      go2lgl_l05/go2lgl_l05
  6. BIN
      go2lgl_l06/go2lgl_l06
  7. BIN
      go2lgl_l07/go2lgl_l07
  8. 113
      go2lgl_l09/go2lgl_l09.go
  9. 28
      go2lgl_l09/myGui/myGui.go
  10. 42
      go2lgl_l09/myGui/qml/formular.ui
  11. 33
      go2lgl_l10/go2lgl_l10.go

BIN
go2lgl_l01/go2lgl_l01

Binary file not shown.

BIN
go2lgl_l02/go2lgl_l02

Binary file not shown.

BIN
go2lgl_l03/go2lgl_l03

Binary file not shown.

BIN
go2lgl_l04/go2lgl_l04

Binary file not shown.

BIN
go2lgl_l05/go2lgl_l05

Binary file not shown.

BIN
go2lgl_l06/go2lgl_l06

Binary file not shown.

BIN
go2lgl_l07/go2lgl_l07

Binary file not shown.

113
go2lgl_l09/go2lgl_l09.go

@ -11,6 +11,7 @@ import (
"math/rand"
"os"
"runtime"
"strconv"
"sync"
"time"
@ -24,15 +25,17 @@ import (
)
const (
anzahlTöpfchen int8 = 35
anzahlKugeln int32 = 80000
anzahlTöpfchen uint8 = 35
anzahlKugeln uint32 = 1000000
intervallWartezeitSec uint8 = 1
höhenFaktor uint8 = 7
)
var timestamp [2]int64
var notify *notificator.Notificator
var wg, wgcli, wggui sync.WaitGroup // !
var wg, wgcli, wggui sync.WaitGroup
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
@ -50,64 +53,25 @@ func main() {
widgets.NewQApplication(len(os.Args), os.Args)
var c_widget = widgets.NewQWidget(nil, 0)
var ui_widget = myGui.LeseUIFile(c_widget)
var ui_textBrowser, ui_lcdNummer, ui_progressBar, ui_graphicsView = myGui.ErzeugeLayout(c_widget, ui_widget, &töpfchenAlle, c) // Beispiel für Parameterrückgabe als Tupel
var c_scene = widgets.NewQGraphicsScene(nil)
ui_textBrowser.ConnectAppend(func(s string) {
ui_textBrowser.Append(s)
})
ui_lcdNummer.ConnectDisplay2(func(i int) {
ui_lcdNummer.Display2(i)
})
ui_progressBar.ConnectSetValue(func(i int) {
ui_progressBar.SetValue(i)
})
/*
ui_graphicsView.ConnectPaintEvent(func(e *gui.QPaintEvent) {
//ui_graphicsView.DrawBackground(gui.QPainter.SetBrush(gui.NewQBrush()), rect)
img := gui.NewQImage3(32, 32, gui.QImage__Format_ARGB32)
for i := 0; i < 32; i++ {
for j := 0; j < 32; j++ {
//img.SetPixelColor2(i, j, gui.NewQColor3(j*8, i*2, i*2, 255))
img.SetPixelColor2(i, j, gui.NewQColor3(255, 255, 0, 255))
}
var ui_textBrowser, ui_lcdNummer, ui_progressBar, ui_sliderArea = myGui.ErzeugeLayout(c_widget, ui_widget, &töpfchenAlle, c) // Beispiel für Parameterrückgabe als Tupel
ui_lcdNummer.SetDigitCount(len(strconv.Itoa((int)(anzahlKugeln))))
var c_slider [anzahlTöpfchen]*widgets.QSlider
for i := uint8(0); i < anzahlTöpfchen; i++ {
c_slider[i] = widgets.NewQSlider2(core.Qt__Vertical, nil)
c_slider[i].SetMinimum(0)
c_slider[i].SetMaximum(int(anzahlKugeln) / int(höhenFaktor))
c_slider[i].SetValue(0) // c_slider[i].Maximum() / 4
c_slider[i].SetSizePolicy2(widgets.QSizePolicy__MinimumExpanding, widgets.QSizePolicy__MinimumExpanding)
c_slider[i].ConnectResizeEvent(func(*gui.QResizeEvent) {
for j := uint8(0); j < anzahlTöpfchen; j++ {
c_slider[j].SetFixedHeight(c_widget.Height() * 93 / 100)
}
})
})*/
ui_graphicsView.ConnectResizeEvent(func(e *gui.QResizeEvent) {
ui_graphicsView.FitInView(c_scene.ItemsBoundingRect(), core.Qt__KeepAspectRatio)
fmt.Println("Hallo")
})
//pinsel := ui_graphicsView.ForegroundBrush()
// paintengine := ui_graphicsView.PaintEngine()
dx, dy := int(anzahlTöpfchen), int(anzahlTöpfchen)
//c_img := gui.NewQImage()
c_img := gui.NewQPainter() // NewQImage3(dx, dy, gui.QImage__Format_ARGB32)
/*for i := 0; i < dx; i++ {
for j := 0; j < dy; j++ {
//c_img.SetPixelColor2(i, j, gui.NewQColor3(j*8, i*2, i*2, 255))
c_img.SetPixelColor2(i, j, gui.NewQColor3(232, 232, 232, 255))
}
}*/
//c_img = c_img.Scaled2(ui_graphicsView.Height(), ui_graphicsView.Width(), core.Qt__IgnoreAspectRatio, core.Qt__FastTransformation)
c_item := widgets.NewQGrap //NewQGraphicsPixmapItem2(gui.NewQPixmap().FromImage(c_img, 0), nil)
c_scene.AddItem(c_item)
c_img = c_img.Scaled2(ui_graphicsView.Height(), ui_graphicsView.Width(), core.Qt__IgnoreAspectRatio, core.Qt__FastTransformation)
ui_graphicsView.SetScene(c_scene)
ui_graphicsView.Show()
//item := ui_graphicsView.
ui_sliderArea.AddWidget(c_slider[i], 0, core.Qt__AlignBottom)
}
wgcli.Add(1)
go func(t *[]int, ch chan bool) {
@ -119,42 +83,33 @@ func main() {
}
return amount
}
for i := 0; true; i = sum(t) {
for i := int(0); true; i = sum(t) {
select {
case <-ch:
ui_textBrowser.Append(fmt.Sprint("\u2690", *t))
ui_lcdNummer.Display2(int(anzahlKugeln))
ui_progressBar.SetValue(100)
for j, v := range *t {
c_slider[j].SetValue(v)
//fmt.Println(j, v)
}
return
default:
ui_textBrowser.Append(fmt.Sprint("\u231B ", *t, runtime.NumGoroutine()))
ui_lcdNummer.Display2(i)
ui_progressBar.SetValue(int(math.Floor((float64(i) / float64(anzahlKugeln) * 100) + .5)))
/* for i, v := range *t {
c_img.SetPixelColor2(i+1*(ui_graphicsView.Width()/int(anzahlTöpfchen)), (ui_graphicsView.Height()/int(anzahlKugeln)*20)*v, gui.NewQColor3(255, 0, 0, 255))
fmt.Println(i, v)
}
c_img.SetPixelColor2(100, 100, gui.NewQColor3(255, 0, 255, 255))
c_img.SetPixelColor2(100, 101, gui.NewQColor3(255, 0, 255, 255))
c_img.SetPixelColor2(100, 102, gui.NewQColor3(255, 0, 255, 255))
c_img.SetPixelColor2(100, 103, gui.NewQColor3(255, 0, 255, 255))
c_img.SetPixelColor2(101, 100, gui.NewQColor3(255, 0, 255, 255))
c_img.SetPixelColor2(101, 101, gui.NewQColor3(255, 0, 255, 255))
c_img.SetPixelColor2(101, 102, gui.NewQColor3(255, 0, 255, 255))
c_img.SetPixelColor2(101, 103, gui.NewQColor3(255, 0, 255, 255))
c_img = c_img.Scaled2(ui_graphicsView.Height(), ui_graphicsView.Width(), core.Qt__IgnoreAspectRatio, core.Qt__FastTransformation)
c_item2 := widgets.NewQGraphicsPixmapItem2(gui.NewQPixmap().FromImage(c_img, 0), nil)
c_scene.AddItem(c_item2)
*/
time.Sleep(time.Second * 1)
for j, v := range *t {
c_slider[j].SetValue(v)
//fmt.Println(j, v)
}
time.Sleep(time.Second * time.Duration(intervallWartezeitSec))
}
}
}(&töpfchenAlle, c)
go func(wg *sync.WaitGroup, töpfchenAlle *[]int, c chan bool) {
for k := (int32)(1); k <= anzahlKugeln; k++ {
for k := (uint32)(1); k <= anzahlKugeln; k++ {
wg.Add(1)
go zeigeMirDenGauß(int(anzahlKugeln), int(anzahlTöpfchen), töpfchenAlle)

28
go2lgl_l09/myGui/myGui.go

@ -6,37 +6,23 @@ import (
"github.com/therecipe/qt/widgets"
)
func ErzeugeLayout(widget *widgets.QWidget, formWidget *widgets.QWidget, t *[]int, ch chan bool) (*widgets.QTextBrowser, *widgets.QLCDNumber, *widgets.QProgressBar, *widgets.QGraphicsView) { //Beispiel für Rückgabeparameter als Tupel
/*
var (
ui_textinputEingabefeld = widgets.NewQTextEditFromPointer(widget.FindChild("textinputEingabefeld", core.Qt__FindChildrenRecursively).Pointer())
ui_buttonAusloeser = widgets.NewQPushButtonFromPointer(widget.FindChild("buttonAusloeser", core.Qt__FindChildrenRecursively).Pointer())
)
ui_buttonAusloeser.ConnectClicked(func(checked bool) {
widgets.QMessageBox_Information(nil, "Titel des Infofensters", ui_textinputEingabefeld.ToPlainText(), widgets.QMessageBox__Ok, widgets.QMessageBox__Ok)
})
*/
func ErzeugeLayout(widget *widgets.QWidget, formWidget *widgets.QWidget, t *[]int, ch chan bool) (*widgets.QTextBrowser, *widgets.QLCDNumber, *widgets.QProgressBar, *widgets.QHBoxLayout) { //Beispiel für Rückgabeparameter als Tupel
var (
ui_textBrowser = widgets.NewQTextBrowserFromPointer(widget.FindChild("textAusgabefeld", core.Qt__FindChildrenRecursively).Pointer())
ui_lcdNummer = widgets.NewQLCDNumberFromPointer(widget.FindChild("lcdNumber", core.Qt__FindChildrenRecursively).Pointer())
ui_progressBar = widgets.NewQProgressBarFromPointer(widget.FindChild("progressBar", core.Qt__FindChildrenRecursively).Pointer())
ui_graphicsView = widgets.NewQGraphicsViewFromPointer(widget.FindChild("graphicsView", core.Qt__FindChildrenRecursively).Pointer())
ui_textBrowser = widgets.NewQTextBrowserFromPointer(widget.FindChild("textAusgabefeld", core.Qt__FindChildrenRecursively).Pointer())
ui_lcdNummer = widgets.NewQLCDNumberFromPointer(widget.FindChild("lcdNumber", core.Qt__FindChildrenRecursively).Pointer())
ui_progressBar = widgets.NewQProgressBarFromPointer(widget.FindChild("progressBar", core.Qt__FindChildrenRecursively).Pointer())
ui_sliderArea = widgets.NewQHBoxLayoutFromPointer(widget.FindChild("sliderArea", core.Qt__FindChildrenRecursively).Pointer())
)
var layout = widgets.NewQVBoxLayout()
widget.SetLayout(layout)
layout.AddWidget(formWidget, 0, 0)
widget.SetWindowTitle("go LGL")
widget.SetWindowTitle("LGL, go4go!")
widget.ShowMaximized()
//ui_graphicsView.SetBackgroundBrush(gui.NewQBrush2(core.Qt__Dense4Pattern))
//ui_graphicsView.SetHorizontalScrollBarPolicy(core.Qt__ScrollBarAlwaysOff)
//ui_graphicsView.SetVerticalScrollBarPolicy(core.Qt__ScrollBarAlwaysOff)
return ui_textBrowser, ui_lcdNummer, ui_progressBar, ui_graphicsView
return ui_textBrowser, ui_lcdNummer, ui_progressBar, ui_sliderArea
}
func LeseUIFile(widget *widgets.QWidget) *widgets.QWidget {

42
go2lgl_l09/myGui/qml/formular.ui

@ -32,45 +32,6 @@
<item row="0" column="4">
<widget class="QTextBrowser" name="textAusgabefeld"/>
</item>
<item row="0" column="3">
<widget class="QGraphicsView" name="graphicsView">
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustIgnored</enum>
</property>
<property name="backgroundBrush">
<brush brushstyle="NoBrush">
<color alpha="255">
<red>253</red>
<green>255</green>
<blue>185</blue>
</color>
</brush>
</property>
<property name="foregroundBrush">
<brush brushstyle="NoBrush">
<color alpha="255">
<red>204</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</property>
<property name="interactive">
<bool>true</bool>
</property>
<property name="sceneRect">
<rectf>
<x>0.000000000000000</x>
<y>0.000000000000000</y>
<width>0.000000000000000</width>
<height>0.000000000000000</height>
</rectf>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QProgressBar" name="progressBar">
<property name="sizePolicy">
@ -87,6 +48,9 @@
<item row="1" column="4">
<widget class="QLCDNumber" name="lcdNumber"/>
</item>
<item row="0" column="3">
<layout class="QHBoxLayout" name="sliderArea"/>
</item>
</layout>
</widget>
<resources/>

33
go2lgl_l10/go2lgl_l10.go

@ -17,7 +17,7 @@ import (
var (
maxThreads, maxRoutines int8
gesuchteZahl int = 8978793242417717171
gesuchteZahl int = 8978793242417717171 //5769977777
timestamp [2]int64
)
@ -31,13 +31,14 @@ func is_prime(n *int) bool {
} else if *n < 2 || *n&1 == 0 { // falls zahl < 2 oder gerade Zahl -> keine Primzahl (1 keine Primzahl)
return false
} else {
var reportChannel, stopChannel chan bool = make(chan bool, maxRoutines), make(chan bool, maxRoutines-1)
var reportChannel chan int = make(chan int, maxRoutines)
var stopChannel chan bool = make(chan bool, maxRoutines-1)
maxSchleife := int(math.Sqrt(float64(*n)))
for start := int8(3); start <= 3+(maxRoutines-1)*2; start += 2 {
wg.Add(1)
go func(s int8, e, g *int, mf *int8, cr, cs chan bool) {
go func(s int8, e, g *int, mf *int8, cr chan int, cs chan bool) {
defer wg.Done()
select {
case <-cs: // Heh, Ihr könnt aufhören
@ -47,7 +48,7 @@ func is_prime(n *int) bool {
//fmt.Println(i)
if *g%i == 0 {
select {
case cr <- true:
case cr <- i:
default:
fmt.Println("Channel voll!")
}
@ -55,20 +56,24 @@ func is_prime(n *int) bool {
}
}
}
cr <- false
cr <- -1
}(start, &maxSchleife, n, &maxRoutines, reportChannel, stopChannel)
}
select {
case cvalue, cstatus := <-reportChannel:
if cstatus && cvalue == true {
for i := int8(1); i < maxRoutines; i++ { // 1 to < maxThreads ist effizienter als 0 to < maxThreads-1
stopChannel <- true
for j := int8(0); j < maxRoutines; j++ {
select {
case cvalue, cstatus := <-reportChannel:
if cstatus && cvalue > 0 {
fmt.Println("Teiler gefunden", cvalue)
for i := int8(1); i < maxRoutines; i++ { // 1 to < maxThreads ist effizienter als 0 to < maxThreads-1
stopChannel <- true
}
wg.Wait()
close(reportChannel)
close(stopChannel)
return false
}
wg.Wait()
close(reportChannel)
close(stopChannel)
return false
}
}
return true

Loading…
Cancel
Save