Files
sumi/main.go

109 lines
2.3 KiB
Go

package main
import (
"fmt"
"github.com/gen2brain/raylib-go/raylib"
"github.com/ojrac/opensimplex-go"
)
func main() {
const (
screenWidth = 2200
screenHeight = 1200
)
rl.InitWindow(screenWidth, screenHeight, "sumi sierpinski arrow")
var camera rl.Camera2D
camera.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
fmt.Printf("angles[%d] = %.2f\n", i, angles[i])
}
frameNum := 0
for !rl.WindowShouldClose() {
frameNum++
if rl.IsMouseButtonDown(rl.MouseRightButton) {
delta := rl.GetMouseDelta()
delta = rl.Vector2Scale(delta, -1.0/camera.Zoom)
camera.Target = rl.Vector2Add(camera.Target, delta)
}
// Zoom based on mouse wheel
wheel := rl.GetMouseWheelMove()
if wheel != 0 {
// Get the world point that is under the mouse
mouseWorldPos := rl.GetScreenToWorld2D(rl.GetMousePosition(), camera)
// Set the offset to where the mouse is
camera.Offset = rl.GetMousePosition()
// Set the target to match, so that the camera maps the world space point
// under the cursor to the screen space point under the cursor at any zoom
camera.Target = mouseWorldPos
// Zoom increment
const zoomIncrement float32 = 0.125
camera.Zoom += (wheel * zoomIncrement)
if camera.Zoom < zoomIncrement {
camera.Zoom = zoomIncrement
}
}
rl.BeginDrawing()
rl.ClearBackground(rl.RayWhite)
rl.BeginMode2D(camera)
rl.PushMatrix()
rl.Translatef(screenWidth/2, screenHeight/2, 0);
// initial transform by halfway again through angle array
angleIndex := frameNum%len(angles)
angle := angles[angleIndex]
initAngle := angles[(angleIndex + len(angles)/2)%len(angles)]
rl.Rotatef(250*initAngle, 0, 0, 1)
rl.Translatef(100*initAngle, 100*initAngle, 0)
for range 1000 {
rl.DrawLine(0, 0, 10, 0, rl.Black)
rl.Translatef(10, 0, 0)
rl.Rotatef(angle, 0, 0, 1)
angleIndex++
angleIndex = angleIndex%len(angles)
angle += angles[angleIndex]
}
rl.PopMatrix()
/*
rl.PushMatrix()
rl.Translatef(0, 25*50, 0)
rl.Rotatef(90, 1, 0, 0)
rl.DrawGrid(100, 50)
rl.PopMatrix()
*/
rl.EndMode2D()
rl.DrawText("Mouse right button drag to move, mouse wheel to zoom", 10, 10, 20, rl.White)
rl.EndDrawing()
}
rl.CloseWindow()
}