Vibrating rectangles: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) (→{{header|Perl 6}}: Add an SDL2 graphics lib version) |
|||
Line 138: | Line 138: | ||
} |
} |
||
}</lang> |
}</lang> |
||
=={{header|J}}== |
|||
<pre> |
|||
NB. warning: overwrites /tmp/10[0-3][0-9].jpg |
|||
NB. and /tmp/r.gif |
|||
NB. uses imagemagic convert and a browser to display the animation. |
|||
NB. works on linux |
|||
NB. https://rosettacode.org/wiki/Ulam_spiral_(for_primes)#J |
|||
require'jpeg' |
|||
spiral =: ,~ $ [: /: }.@(2 # >:@i.@-) +/\@# <:@+: $ (, -)@(1&,) |
|||
ulamspiral =: *: - spiral |
|||
NB. Corners are the squares of every other odd number. |
|||
NB. Rectangles ulams with first column < and <: second column of CORNERS |
|||
[CORNERS=: *: 1 2 p. i. _20 2 |
|||
5929 6241 |
|||
5329 5625 |
|||
4761 5041 |
|||
4225 4489 |
|||
3721 3969 |
|||
3249 3481 |
|||
2809 3025 |
|||
2401 2601 |
|||
2025 2209 |
|||
1681 1849 |
|||
1369 1521 |
|||
1089 1225 |
|||
841 961 |
|||
625 729 |
|||
441 529 |
|||
289 361 |
|||
169 225 |
|||
81 121 |
|||
25 49 |
|||
1 9 |
|||
NB. S is a sufficiently large Ulam spiral matrix |
|||
S=: ulamspiral 81 |
|||
NB. A are 20 Boolean bitmaps of squares |
|||
A =: CORNERS ((> {.)~ *. (<: {:)~)"1 _ S |
|||
NB. B is a bitmap of all the squares |
|||
B =: +/ A |
|||
NB. C is a running sum. first 6 upper left corners shown |
|||
<"2 ] 6 10 10 {. C =: B +"2 +/\ A |
|||
┌───────────────────┬───────────────────┬───────────────────┬───────────────────┬───────────────────┬───────────────────┐ |
|||
│0 0 0 0 0 0 0 0 0 0│0 0 0 0 0 0 0 0 0 0│0 0 0 0 0 0 0 0 0 0│0 0 0 0 0 0 0 0 0 0│0 0 0 0 0 0 0 0 0 0│0 0 0 0 0 0 0 0 0 0│ |
|||
│0 2 2 2 2 2 2 2 2 2│0 2 2 2 2 2 2 2 2 2│0 2 2 2 2 2 2 2 2 2│0 2 2 2 2 2 2 2 2 2│0 2 2 2 2 2 2 2 2 2│0 2 2 2 2 2 2 2 2 2│ |
|||
│0 2 0 0 0 0 0 0 0 0│0 2 0 0 0 0 0 0 0 0│0 2 0 0 0 0 0 0 0 0│0 2 0 0 0 0 0 0 0 0│0 2 0 0 0 0 0 0 0 0│0 2 0 0 0 0 0 0 0 0│ |
|||
│0 2 0 1 1 1 1 1 1 1│0 2 0 2 2 2 2 2 2 2│0 2 0 2 2 2 2 2 2 2│0 2 0 2 2 2 2 2 2 2│0 2 0 2 2 2 2 2 2 2│0 2 0 2 2 2 2 2 2 2│ |
|||
│0 2 0 1 0 0 0 0 0 0│0 2 0 2 0 0 0 0 0 0│0 2 0 2 0 0 0 0 0 0│0 2 0 2 0 0 0 0 0 0│0 2 0 2 0 0 0 0 0 0│0 2 0 2 0 0 0 0 0 0│ |
|||
│0 2 0 1 0 1 1 1 1 1│0 2 0 2 0 1 1 1 1 1│0 2 0 2 0 2 2 2 2 2│0 2 0 2 0 2 2 2 2 2│0 2 0 2 0 2 2 2 2 2│0 2 0 2 0 2 2 2 2 2│ |
|||
│0 2 0 1 0 1 0 0 0 0│0 2 0 2 0 1 0 0 0 0│0 2 0 2 0 2 0 0 0 0│0 2 0 2 0 2 0 0 0 0│0 2 0 2 0 2 0 0 0 0│0 2 0 2 0 2 0 0 0 0│ |
|||
│0 2 0 1 0 1 0 1 1 1│0 2 0 2 0 1 0 1 1 1│0 2 0 2 0 2 0 1 1 1│0 2 0 2 0 2 0 2 2 2│0 2 0 2 0 2 0 2 2 2│0 2 0 2 0 2 0 2 2 2│ |
|||
│0 2 0 1 0 1 0 1 0 0│0 2 0 2 0 1 0 1 0 0│0 2 0 2 0 2 0 1 0 0│0 2 0 2 0 2 0 2 0 0│0 2 0 2 0 2 0 2 0 0│0 2 0 2 0 2 0 2 0 0│ |
|||
│0 2 0 1 0 1 0 1 0 1│0 2 0 2 0 1 0 1 0 1│0 2 0 2 0 2 0 1 0 1│0 2 0 2 0 2 0 2 0 1│0 2 0 2 0 2 0 2 0 2│0 2 0 2 0 2 0 2 0 2│ |
|||
└───────────────────┴───────────────────┴───────────────────┴───────────────────┴───────────────────┴───────────────────┘ |
|||
NB. D is C catenated to itself with the ones and twos swapped. |
|||
D=: (, ]`(0,2,:1"0)}) C |
|||
NB. E is the 40 matrices with ID, in 3 levels |
|||
E=: (;"2 0 (1000 + i.@#))@:(*&16b301070) D |
|||
NB. overwrite the files then get some help from the shell |
|||
empty@:(writejpeg('.jpg' ,~ '/tmp/' , ":))&>/"1 E |
|||
2!:0'convert -resize 600% /tmp/10[0-3][0-9].jpg -delay 10 -loop 0 /tmp/r.gif' |
|||
echo 'please view the animation /tmp/r.gif in chrome browser' |
|||
</pre> |
|||
=={{header|Javascript}}== |
=={{header|Javascript}}== |