MCPcopy Create free account
hub / github.com/cogentcore/core / TestGradient

Function TestGradient

paint/raster/raster_test.go:449–567  ·  view source on GitHub ↗

TestGradient tests a Dasher's ability to function as a filler, stroker, and dasher by invoking the corresponding anonymous structs

(t *testing.T)

Source from the content-addressed store, hash-verified

447// TestGradient tests a Dasher's ability to function
448// as a filler, stroker, and dasher by invoking the corresponding anonymous structs
449func TestGradient(t *testing.T) {
450 var (
451 wx, wy = 512, 512
452 img = image.NewRGBA(image.Rect(0, 0, wx, wy))
453 scanner = scan.NewScanner(scan.NewImgSpanner(img), wx, wy)
454 )
455
456 linear := gradient.NewLinear()
457 linear.SetBox(math32.B2(50, 50, 150, 150)).
458 AddStop(colors.Aquamarine, 0.3).
459 AddStop(colors.Skyblue, 0.6).
460 AddStop(colors.ApplyOpacity(colors.Darksalmon, 0.75), 1)
461
462 radial := gradient.NewRadial()
463 radial.SetBox(math32.B2(230, 230, 330, 330)).
464 SetSpread(gradient.Reflect).
465 AddStop(colors.Orchid, 0.3).
466 AddStop(colors.Bisque, 0.6).
467 AddStop(colors.ApplyOpacity(colors.Chartreuse, 0.4), 1)
468
469 d := NewDasher(wx, wy, scanner)
470 d.SetStroke(10*64, 4*64, RoundCap, nil, RoundGap, ArcClip, []float32{33, 12}, 0)
471 // p is in the shape of a capital Q
472 p := getPartPath()
473
474 f := &d.Filler // This is the anon Filler in the Dasher. It also satisfies
475 // the Rasterizer interface, and can only perform a fill on the path.
476
477 offsetPath := &MatrixAdder{Adder: f, M: math32.Identity2().Translate(180, 180)}
478
479 p.AddTo(offsetPath)
480
481 scanner.SetColor(radial)
482 f.Draw()
483 f.Clear()
484
485 scanner.SetClip(image.Rect(420, 350, 460, 400))
486 offsetPath.M = math32.Identity2().Translate(340, 180)
487 scanner.SetColor(radial)
488 p.AddTo(offsetPath)
489 f.Draw()
490 f.Clear()
491 scanner.SetClip(image.ZR)
492 offsetPath.M = math32.Identity2().Translate(180, 340)
493 p.AddTo(offsetPath)
494 f.Draw()
495 f.Clear()
496 offsetPath.Reset()
497 if isClose(offsetPath.M, math32.Identity2(), 1e-12) == false {
498 t.Error("path reset failed", offsetPath)
499 }
500
501 scanner.SetColor(linear)
502 p.AddTo(f)
503 f.Draw()
504 f.Clear()
505
506 linear.SetSpread(gradient.Repeat)

Callers

nothing calls this directly

Calls 15

SetStrokeMethod · 0.95
ResetMethod · 0.95
SetFocalMethod · 0.95
NewScannerFunction · 0.92
NewImgSpannerFunction · 0.92
NewLinearFunction · 0.92
B2Function · 0.92
ApplyOpacityFunction · 0.92
NewRadialFunction · 0.92
Identity2Function · 0.92
Vector2ScalarFunction · 0.92
Vec2Function · 0.92

Tested by

no test coverage detected