Adds an example file

This commit is contained in:
Sloom Sloum Sluom IV 2024-06-09 21:13:20 -07:00
parent 4f1c7df059
commit 4eee7dd115
2 changed files with 42 additions and 1 deletions

View File

@ -0,0 +1,24 @@
(define size 1)
(define color 1)
(define colordir 1)
(define sizedir 1)
(define tick 1)
(set! draw
(lambda ()
(set! tick (+ tick 1))
(circle (/ screen-width 2) (/ screen-height 2) size color)
(set! size (rand-range-int 1 screen-width))
(line
(rand-range-int 0 screen-width) (rand-range-int 0 screen-height)
(rand-range-int 0 screen-width) (rand-range-int 0 screen-height)
(rand-range-int 1 4))
(if
(equal?
(% tick 8) 0)
(begin
(set! color (+ color colordir))
(if (or (equal? color 4) (equal? color 1))
(set! colordir (- colordir)))))))
(run)

View File

@ -141,5 +141,22 @@ var slopeMathLib = {
return Math.round(nums[0]);
},
"rand": Math.random,
"rand-range": function(...nums) {
if (!nums.length) {
throw new Error("'rand-range' expects at least one number (representing the top of the range with 0 as a start point) or two numbers (representing the bottom and top of the range)");
}
if (nums.length == 1) {
return Math.random() * nums[0];
}
return Math.random() * (nums[1] - nums[0] + 1) + nums[1]
},
"rand-range-int": function(...nums) {
if (!nums.length) {
throw new Error("'rand-range-int' expects at least one number (representing the top of the range with 0 as a start point) or two numbers (representing the bottom and top of the range)");
}
if (nums.length == 1) {
return Math.floor(Math.random() * nums[0]);
}
return Math.floor(Math.random() * (nums[1] - nums[0] + 1) + nums[0]);
}
}