Last active
January 28, 2024 21:40
-
-
Save CSchank/26596747f572921c256656d8a2ba95ab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Copy to macoutreach.rocks animation slot | |
myShapes model = | |
[ | |
myFunction 5 -- replace 5 with different number for different depth | |
] | |
myFunction n = | |
if n <= 0 then | |
group [] | |
else | |
group | |
[ | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Copy to macoutreach.rocks animation slot | |
-- loosely based on https://www.youtube.com/watch?v=SSdyo5BbRvM | |
myShapes model = | |
[ | |
fallingSquares 20 -- turn up 20 for more recursion! | |
] | |
fallingSquares n = | |
if n == 0 then | |
group [] | |
else | |
group | |
[ | |
square (5 * toFloat n) | |
|> outlined (solid 1) black | |
|> rotate (degrees (toFloat (n - 1) * 4)) | |
, fallingSquares (n-1) | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Copy to macoutreach.rocks animation slot | |
myShapes model = | |
[ | |
scaledSierpinski 5 -- turn up 5 for more recursion! Might get laggy... | |
] | |
-- accounts for the scaling | |
scaledSierpinski n = | |
sierpinski n | |
|> scale (2 ^ (-(toFloat n))) | |
sierpinski n = | |
if n == 0 then | |
group [] | |
else | |
let size = 60 * (2 ^ toFloat n) | |
-- determine colour based on n | |
colour = if modBy 3 n == 2 then green else if modBy 3 n == 1 then lightBlue else black | |
in | |
group | |
[ | |
triangle size | |
|> filled colour | |
|> rotate (degrees (-30)) | |
, sierpinski (n-1) | |
|> move (0, size / 2) | |
, sierpinski (n-1) | |
|> move (-size / 2 * sin (degrees -60), -size / 2 * cos (degrees -60)) | |
, sierpinski (n-1) | |
|> move ( size / 2 * sin (degrees -60), -size / 2 * cos (degrees -60)) | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myShapes model = | |
[ myBackground | |
, simpleSnowflake | |
] | |
simpleSnowflake = | |
let | |
divide level = | |
let | |
hex = ngon 6 level | |
|> filled (rgba 255 255 255 0.5) | |
in | |
if level > 4 then | |
let | |
children = divide (level * 0.75) | |
|> move (1.4 * level,0) | |
rotated angle = children |> rotate (degrees angle) | |
in | |
( hex :: | |
List.map rotated [0,60,120,180,240,300] ) | |
|> group | |
else | |
group [] | |
in | |
divide 7.5 | |
snowflake = | |
let | |
oneBranch = branch 30 | |
rotateBranch angle = oneBranch |> rotate (degrees angle) | |
in | |
List.map rotateBranch [0,60,120,180,240,300] | |
|> group | |
branch level = | |
if level > 1 then | |
let | |
newLevel = level * (0.4 + 0.1 * sin level) | |
outerBranch = branch newLevel | |
innerBranch = branch (0.5 * newLevel) | |
in | |
group | |
[ ngon 6 1 | |
|> outlined (solid 1) (rgba 255 255 255 0.5) | |
|> scaleX level | |
|> move (level * 0.5, 0) | |
, outerBranch | |
|> rotate (degrees 60) | |
|> move (0.66*level,0) | |
, outerBranch | |
|> rotate (degrees -60) | |
|> move (0.66*level,0) | |
, innerBranch | |
|> rotate (degrees 60) | |
|> move (0.33*level,0) | |
, innerBranch | |
|> rotate (degrees -60) | |
|> move (0.33*level,0) | |
] | |
else | |
group [] | |
myBackground = square 200 |> filled (rgb 50 50 255) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Copy to macoutreach.rocks animation slot | |
myShapes model = | |
[ | |
spinner model.time 6 -- turn up 6 for more recursion! Might get laggy... | |
] | |
spinner time n = | |
if n < 3 then | |
group [] | |
else | |
let | |
shadeOfRed = rgb (255-255/(toFloat n)) 0 0 | |
rainbow = | |
case n + 3 of | |
10 -> red | |
9 -> orange | |
8 -> yellow | |
7 -> green | |
6 -> lightBlue | |
5 -> blue | |
4 -> purple | |
3 -> pink | |
otherwise -> black | |
colour = shadeOfRed | |
in | |
group | |
[ | |
ngon n 10 | |
|> filled colour | |
|> move (30, 30) | |
, ngon n 10 | |
|> filled colour | |
|> move (-30,30) | |
, ngon n 10 | |
|> filled colour | |
|> move (30, -30) | |
, ngon n 10 | |
|> filled colour | |
|> move (-30, -30) | |
, spinner time (n-1) | |
|> move (30, 30) | |
, spinner time (n-1) | |
|> move (-30, 30) | |
, spinner time (n-1) | |
|> move (30, -30) | |
, spinner time (n-1) | |
|> move (-30, -30) | |
] |> scale (toFloat n/6) | |
|> rotate (degrees (50*time)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Copy to macoutreach.rocks animation slot | |
myShapes model = | |
let animateTree = modBy 13 (round (model.time*3)) | |
in | |
[ | |
tree 11 -- replace 11 with different number for different depth or with animateTree to get animation | |
|> move (0,-95) | |
|> scale 0.6 | |
] | |
tree n = | |
if n == 0 then | |
group [] | |
else | |
let | |
angle = 20 | |
weirdRainbow = hsl (degrees 44) 0.6 (0.32 + toFloat n) | |
colour = darkBrown | |
in | |
group | |
[ | |
rect 3 40 | |
|> filled colour | |
|> move(0,20) | |
|> rotate (degrees angle) | |
, rect 3 40 | |
|> filled colour | |
|> move(0,20) | |
|> rotate (degrees -angle) | |
, tree (n-1) | |
|> rotate (degrees -angle) | |
|> move (40*sin(degrees angle), 40*cos(degrees angle)) | |
, tree (n-1) | |
|> rotate (degrees angle) | |
|> move (-40*sin(degrees angle), 40*cos(degrees angle)) | |
] |> scale (1 - 1/(toFloat n + 1)) |
Rainbow circle spiral
-- Your shapes go here!
-- You can use model.time to animate things :)
myShapes model =
[
myFunction 200
]
myFunction n =
let
col = hsl (degrees <| toFloat n) 1 0.8
in
if n == 0 then
group []
else
group
[
circle (toFloat n)
|> outlined (solid 0.5) col
|> move (0, toFloat n)
|> rotate (degrees (2 * toFloat n))
, myFunction (n-1)
]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Rotating falling squares