house/bot/bot.rkt

44 lines
1.5 KiB
Racket
Raw Normal View History

2023-02-02 21:23:03 +00:00
#lang syndicate
(module+ main
(require syndicate/distributed/tcp)
(require syndicate/drivers/timer)
(require syndicate/gensym)
(require racket/math)
(require "schemas/scene.rkt")
(require "schemas/shapes.rkt")
(assertion-struct SceneHandle (ds))
(standard-actor-system (ds)
(define (on-connected remote-ds)
(at remote-ds
(during (SceneHandle $scene-e)
(define scene (embedded-value scene-e))
(define (bouncy-box)
(define me (symbol->string (strong-gensym 'user)))
(define start-time (current-inexact-milliseconds))
(define-field deadline start-time)
(define-field x (* (- (random) 0.5) 100))
(define y0 (+ 1.0 (* (random) 10)))
(define-field y y0)
(define-field z (* (- (random) 0.5) 100))
(at ds
(on (asserted (LaterThan (deadline)))
(deadline (+ (deadline) (/ 1000 10)))
(y (+ y0 (cos (/ (- (deadline) start-time) 1000.0 (/ 1 2 pi)))))))
(define r (random))
(define g (random))
(define b (random))
(at scene
(assert (Sprite me (Move (Vector3 (x) (y) (z))
(Color-opaque r g b (Box)))))
))
(for [(i 100)] (bouncy-box)))))
(run-tcp-client-relay ds #:hostname "vr.demo.leastfixedpoint.com" #:port 9001
#:import (lambda (v) (on-connected (embedded-value v))))))