From 342812d16758fdb315888e9e1f75546e91a60481 Mon Sep 17 00:00:00 2001 From: esimov Date: Sat, 11 Nov 2023 15:40:25 +0200 Subject: [PATCH] Some adjustments --- cloth.go | 17 ++++++++--------- hud.go | 6 +++--- main.go | 18 ++++++++++++++---- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/cloth.go b/cloth.go index 0b95306..4042499 100644 --- a/cloth.go +++ b/cloth.go @@ -10,7 +10,7 @@ import ( "gioui.org/op/paint" ) -const lineWidth = 0.8 +const lineWidth = 0.6 type Cloth struct { constraints []*Constraint @@ -25,13 +25,12 @@ type Cloth struct { // NewCloth creates a new cloth which dimension is calculated based on // the application window width and height and the spacing between the sticks. -func NewCloth(width, height, spacing int, friction float64, col color.NRGBA) *Cloth { +func NewCloth(width, height, spacing int, col color.NRGBA) *Cloth { return &Cloth{ - width: width, - height: height, - spacing: spacing, - friction: friction, - color: col, + width: width, + height: height, + spacing: spacing, + color: col, } } @@ -67,7 +66,7 @@ func (c *Cloth) Init(posX, posY int, hud *Hud) { c.constraints = append(c.constraints, constraint) } - pinX := x % (clothX / 9) + pinX := x % (clothX / 10) if y == 0 && pinX == 0 { particle.pinX = true } @@ -81,7 +80,7 @@ func (c *Cloth) Init(posX, posY int, hud *Hud) { // Update updates the cloth particles invoked on each frame event of the Gio internal window calls. // The cloth contraints are solved by using the Verlet integration formulas. func (cloth *Cloth) Update(gtx layout.Context, mouse *Mouse, hud *Hud, dt float64) { - dragForce := float32(mouse.getForce() * 0.25) + dragForce := float32(mouse.getForce() * 0.1) clothColor := color.NRGBA{R: 0x55, A: 0xff} // Convert the RGB color to HSL based on the applied force over the mouse focus area. col := LinearFromSRGB(clothColor).HSLA().Lighten(dragForce).RGBA().SRGB() diff --git a/hud.go b/hud.go index 4e016f6..e2885c6 100644 --- a/hud.go +++ b/hud.go @@ -74,7 +74,7 @@ func NewHud() *Hud { sliders := []slider{ {title: "Drag force", min: 1.1, value: 2, max: 15}, - {title: "Gravity force", min: 100, value: 250, max: 500}, + {title: "Gravity", min: 100, value: 250, max: 500}, {title: "Elasticity", min: 10, value: 30, max: 50}, {title: "Stiffness", min: 0.95, value: 0.98, max: 0.99}, {title: "Tear distance", min: 5, value: 20, max: 80}, @@ -87,8 +87,8 @@ func NewHud() *Hud { {"F1": "Toggle the quick help panel"}, {"Space": "Redraw the cloth"}, {"Right click": "Tear the cloth at mouse position"}, - {"Click & hold": "Increase the mouse pressure"}, - {"Scroll Up/Down": "Change the mouse focus area"}, + {"Click & hold": "Increase cloth destruction"}, + {"Scroll Up/Down": "Increase/decrease cloth destruction area"}, {"Ctrl+click": "Pin the cloth particle at mouse position"}, } diff --git a/main.go b/main.go index a07092d..0e4a52d 100644 --- a/main.go +++ b/main.go @@ -34,8 +34,8 @@ const ( windowSizeX = 1280 windowSizeY = 820 - defaultWindowWidth = 940 - defaultWindowHeigth = 580 + defaultWindowWidth = 1024 + defaultWindowHeigth = 640 ) var ( @@ -49,6 +49,8 @@ var ( clothW int clothH int + clothSpacing = 6 + // Gio Ops related variables ops op.Ops initTime time.Time @@ -132,11 +134,17 @@ func loop(w *app.Window) error { pprof.StartCPUProfile(file) } - // Cloth is not initialized yet. Initialize it. + // Cloth is not initialized yet. if cloth == nil { clothW = gtx.Dp(unit.Dp(windowWidth)) clothH = gtx.Dp(unit.Dp(windowHeight) * 0.33) - cloth = NewCloth(clothW, clothH, 12, 0.98, defaultColor) + clothSpacing = func() int { // different cloth spacing for hi-res devices. + if clothW <= windowWidth { + return clothSpacing + } + return 2 * clothSpacing + }() + cloth = NewCloth(clothW, clothH, clothSpacing, defaultColor) width := gtx.Constraints.Max.X height := gtx.Constraints.Max.Y @@ -152,6 +160,8 @@ func loop(w *app.Window) error { Keys: key.NameEscape + "|" + key.NameCtrl + "|" + key.NameAlt + "|" + key.NameSpace + "|" + key.NameF1, }.Add(gtx.Ops) + pointer.CursorPointer.Add(gtx.Ops) + if mouse.getLeftButton() { deltaTime = time.Since(initTime) mouse.setForce(deltaTime.Seconds() * 5)