checkpoint
This commit is contained in:
141
main.go
141
main.go
@@ -2,28 +2,108 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
"github.com/ojrac/opensimplex-go"
|
||||
"github.com/go-git/go-git/v6"
|
||||
)
|
||||
|
||||
func HeadHash(repoPath string) (string, error) {
|
||||
r, err := git.PlainOpen(repoPath)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
ref, err := r.Head()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return ref.Hash().String(), nil
|
||||
}
|
||||
|
||||
func IsDirty(repoPath string) (bool, error) {
|
||||
r, err := git.PlainOpen(repoPath)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
wt, err := r.Worktree()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
status, err := wt.Status()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return !status.IsClean(), nil
|
||||
}
|
||||
|
||||
func clamp01(v float64) float64 {
|
||||
if v < 0 {
|
||||
return 0
|
||||
}
|
||||
if v > 1 {
|
||||
return 1
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func GrayCurve(v, k float64) rl.Color {
|
||||
v = math.Pow(clamp01(v), k) // k < 1 boosts highlights, k > 1 boosts shadows
|
||||
c := uint8(v * 255)
|
||||
return rl.Color{R: c, G: c, B: c, A: 255}
|
||||
}
|
||||
|
||||
func sierpinskiArrow(order int, length float64) {
|
||||
rl.Scalef(1, -1, 1)
|
||||
//rl.Rotatef(180, 0, 0, 1)
|
||||
if order == 0 {
|
||||
curve(order, length, 60)
|
||||
} else {
|
||||
rl.Rotatef(60, 0, 0, 1)
|
||||
curve(order, length, -60)
|
||||
}
|
||||
}
|
||||
|
||||
func curve(order int, length float64, angle float64) {
|
||||
if order == 0 {
|
||||
len := int32(length)
|
||||
rl.DrawLine(0, 0, len, 0, rl.Black)
|
||||
rl.Translatef(float32(len), 0, 0)
|
||||
} else {
|
||||
curve(order - 1, length/2, -angle)
|
||||
rl.Rotatef(float32(angle), 0, 0, 1)
|
||||
curve(order - 1, length/2, angle)
|
||||
rl.Rotatef(float32(angle), 0, 0, 1)
|
||||
curve(order - 1, length/2, -angle)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
const (
|
||||
screenWidth = 2200
|
||||
screenHeight = 1200
|
||||
screenWidth = 1200
|
||||
screenHeight = 700
|
||||
)
|
||||
|
||||
rl.InitWindow(screenWidth, screenHeight, "sumi sierpinski arrow")
|
||||
|
||||
var camera rl.Camera2D
|
||||
camera.Zoom = 1.0
|
||||
var camera = rl.Camera2D {
|
||||
Target: rl.Vector2{X: 0, Y: 0},
|
||||
Offset: rl.Vector2{X: float32(screenWidth) / 2, Y: float32(screenHeight) / 2},
|
||||
Rotation: 0,
|
||||
Zoom: 1.0,
|
||||
}
|
||||
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
angles := make([]float32, 1000)
|
||||
noise := opensimplex.NewNormalized(0)
|
||||
for i := range len(angles) {
|
||||
angles[i] = float32(noise.Eval2(float64(i)*0.0001, 0.00)) * 2 - 1
|
||||
angles[i] = float32(noise.Eval2(float64(i)*0.05, 0.00)) * 0.1 - 0.05
|
||||
fmt.Printf("angles[%d] = %.2f\n", i, angles[i])
|
||||
}
|
||||
|
||||
@@ -67,7 +147,17 @@ func main() {
|
||||
rl.BeginMode2D(camera)
|
||||
|
||||
rl.PushMatrix()
|
||||
rl.Translatef(screenWidth/2, screenHeight/2, 0);
|
||||
|
||||
/**
|
||||
for x := range screenWidth {
|
||||
for y := range screenHeight {
|
||||
sp := rl.Vector2 { X: float32(x), Y: float32(y) };
|
||||
wp := rl.GetScreenToWorld2D(sp, camera);
|
||||
normVal := noise.Eval2(float64(wp.X), float64(wp.Y))
|
||||
rl.DrawPixelV(wp, GrayCurve(normVal, 0.8));
|
||||
}
|
||||
}
|
||||
**/
|
||||
|
||||
// initial transform by halfway again through angle array
|
||||
|
||||
@@ -75,12 +165,13 @@ func main() {
|
||||
angle := angles[angleIndex]
|
||||
|
||||
initAngle := angles[(angleIndex + len(angles)/2)%len(angles)]
|
||||
rl.Rotatef(250*initAngle, 0, 0, 1)
|
||||
rl.Rotatef(2500*initAngle, 0, 0, 1)
|
||||
rl.Translatef(100*initAngle, 100*initAngle, 0)
|
||||
|
||||
stepSize := int32(1)
|
||||
for range 1000 {
|
||||
rl.DrawLine(0, 0, 10, 0, rl.Black)
|
||||
rl.Translatef(10, 0, 0)
|
||||
rl.DrawLine(0, 0, stepSize, 0, rl.Black)
|
||||
rl.Translatef(float32(stepSize), 0, 0)
|
||||
rl.Rotatef(angle, 0, 0, 1)
|
||||
angleIndex++
|
||||
angleIndex = angleIndex%len(angles)
|
||||
@@ -88,6 +179,15 @@ func main() {
|
||||
}
|
||||
rl.PopMatrix()
|
||||
|
||||
|
||||
rl.PushMatrix()
|
||||
|
||||
//rl.Translatef(-screenWidth/2, screenHeight/2, 0)
|
||||
|
||||
sierpinskiArrow(9,800)
|
||||
|
||||
rl.PopMatrix()
|
||||
|
||||
/*
|
||||
rl.PushMatrix()
|
||||
rl.Translatef(0, 25*50, 0)
|
||||
@@ -98,6 +198,29 @@ func main() {
|
||||
|
||||
rl.EndMode2D()
|
||||
|
||||
if rl.IsKeyDown(rl.KeySpace) {
|
||||
//rl.TakeScreenshot("snapshot.png")
|
||||
img := rl.LoadImageFromScreen()
|
||||
defer rl.UnloadImage(img)
|
||||
rl.ExportImage(*img, "shot.png")
|
||||
|
||||
dflag, err := IsDirty(".")
|
||||
|
||||
if err == nil {
|
||||
|
||||
if dflag {
|
||||
fmt.Printf("working tree is dirty\n")
|
||||
} else {
|
||||
fmt.Printf("working tree is clean\n")
|
||||
}
|
||||
|
||||
hash, err := HeadHash(".")
|
||||
if err == nil {
|
||||
fmt.Printf("HEAD -> %s\n", hash)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rl.DrawText("Mouse right button drag to move, mouse wheel to zoom", 10, 10, 20, rl.White)
|
||||
|
||||
rl.EndDrawing()
|
||||
|
||||
Reference in New Issue
Block a user