automated snapshot
This commit is contained in:
35
sierpinski.go
Normal file
35
sierpinski.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
type SierpinskiArrow struct{}
|
||||
|
||||
func (s *SierpinskiArrow) Draw(ctx *RenderCtx) {
|
||||
sierpinskiArrow(ctx, int(ctx.Ports["sierpinskiArrowDepth"]), ctx.Ports["sierpinskiArrowLength"])
|
||||
}
|
||||
|
||||
func sierpinskiArrow(ctx *RenderCtx, order int, length float64) {
|
||||
if order == 0 {
|
||||
curve(ctx, order, length, ctx.Ports["sierpinskiArrowAngle"])
|
||||
} else {
|
||||
rl.Rotatef(float32(ctx.Ports["sierpinskiArrowAngle"]), 0, 0, 1)
|
||||
curve(ctx, order, length, -ctx.Ports["sierpinskiArrowAngle"])
|
||||
}
|
||||
}
|
||||
|
||||
func curve(ctx *RenderCtx, order int, length float64, angle float64) {
|
||||
if order == 0 {
|
||||
len := int32(length)
|
||||
rl.DrawLine(0, 0, len, 0, rl.Black)
|
||||
rl.Translatef(float32(length), 0, 0)
|
||||
} else {
|
||||
curve(ctx, order-1, length/2, -angle)
|
||||
rl.Rotatef(float32(angle), 0, 0, 1)
|
||||
curve(ctx, order-1, length/2, angle)
|
||||
rl.Rotatef(float32(angle), 0, 0, 1)
|
||||
curve(ctx, order-1, length/2, -angle)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user