Skip to content

Instantly share code, notes, and snippets.

@0racle
Last active May 16, 2025 10:44
Show Gist options
  • Save 0racle/863fd417b1e0ddf126722c6d43834263 to your computer and use it in GitHub Desktop.
Save 0racle/863fd417b1e0ddf126722c6d43834263 to your computer and use it in GitHub Desktop.
J-80 Examples
n =: 100
z =: 136 240
pos =: 5 + (? n # ,: 10 -~ z)
vel =: 5 * 0.5 -~ (? n # ,: 0 0)
col =: >: 15 | i. n
R =: [: >./ (2 2 -~"1 ($ #: I.@,)#:14 31 31 31 14)&(|.!.0)
F =: {{)d
pos =: pos + vel
vel =: vel * <: +: ((z-3)&> *. 3&<)"1 pos
R col (<. pos)} z $ 0
}}
b =: - ($ #: I.@,) '#' = ];._2 {{)n
.....#######.....
...##.......##...
..#...........#..
.#.......###...#.
.#.........##..#.
#...........##..#
#............#..#
#............#..#
#...............#
#............#..#
#...............#
#...............#
.#.............#.
.#.............#.
..#...........#..
...##.......##...
.....#######.....
}}
NB. https://github.com/mlochbaum/JScripts/blob/master/Graphics/Perlin.ijs
d =: 512
S =: 0 0 3 _2&p.
H =: (+: >: d)&$
g =: H <: +: d ?@$ 0 [ q =: H ?~ d
N =: {{ ((,&,:~ -.) S {. 0 _1 +/ 1 | y) +/@:* g {~ q {~ d | 0 1 +/ <. y }}
o =: i. # p =: ? 32 $ ,: z =: 136 240
F =: {{
p =: z |"1 p + 0.5 * N o +/ 0.01 * x + 0 64
8 10 {~ >./ b&|. 1 (<. p)} z $ 0
}}
tile =: "."0;._2 {{)n
00001
01112
01112
01112
12222
}}
off =. 14 15 0 {~ tile
on =. 5 6 8 {~ tile
xo =: off ,&,: on
g =: ? 27 48 $ 2
r =: ,/ ,"0/~ i: 1
F =: {{)d
g =: +./ (1 ,: g) *. (3 4) =/ +/ r |. g
,./^:2 xo {~ g
}}
a =: +&*:/ |: (#: i.) 240 136
F =: {{ 5 | 10 <.@%~ a + x }}
load 'math/misc/trig'
NB. https://rosettacode.org/wiki/Bitmap/Bresenham's_line_algorithm#J
Bresenham =: {{
steep =. </@:(|@-~/) y
points =. |."1^:steep y
slope =. %~/ -~/ points
ypts =. (<./ + -~ i.@+ _1 ^ >)/ {."1 points
xpts =. ({: + 0.5 <.@:+ slope * ypts - {.) {. points
|."1^:steep ypts,.xpts
}}
Ngon =: {{ <. |: ({: y) * (cos,:sin) x + (i.*2*pi%]) {. y }}
Line =: {{ ; 2 <@Bresenham\ (, {.) x +"1 y }}
Mat =: (i.@[ e. #.)~ 1 + >./
F =: {{
NB. color position rotation sides size
ngon3 =. 2 * Mat 68 120 Line (x * 0.08) Ngon 3 15
ngon4 =. 4 * Mat 68 120 Line (x * _0.06) Ngon 4 30
ngon5 =. 6 * Mat 68 120 Line (x * 0.04) Ngon 5 45
ngon6 =. 10 * Mat 68 120 Line (x * _0.02) Ngon 6 60
>./ ngon3, ngon4, ngon5 ,: ngon6
}}
p =: 64 64 [ z =: 136 240
d =: 0 1
F =: {{)d
s =. (? 8) { 4 * >: i. 8
q =. 4 >. (4 -~ z) <. p + s * d
b =. q,~ p +"1 (* *"1 i."0&.|:@:|) q - p
y =. (>: 15 | x) (b)} y
y =. 0 ((1 1) +"1 b)} y
d =: -^:(?2) |. d
p =: q
y
}}
NB. Adapted from https://johnearnest.github.io/ok/ike/ike.html?key=YjUJa3Fg
s =: 0.014 * i. 50
P =: ([ * 2 1 o. ])"_1
A =: (68 + [ P s + ])"_1
W =: {{ (y * 6) A x + y * 0.02 * m }}"_1
C =: {{ ,/ y m W/ >: i. 10 }}"_1
G =: ((i.@[ e. #.)~ 1 + >./)"_1
F =: {{ >./ 2 3 4 5 11 * G <. 0 52 +"1 x C 2.5 %~ o. i. 5 }}
sin =: 1&o.
hypot =: +&.*:
atan2 =: 12 o. j.
i =: 0.2 * (-: -"1 (#: i.)) 240 136
a =: (hypot + atan2)/ |: i
F =: {{ 0 < sin a - x % 8 }}
NB. Adapted from https://webbox.lafayette.edu/~reiterc/mvp/v3harm
base =: 0.2 * (-: d) -"1~ (#: i.) d =: 240 136
init =: +/ |: {{ 2 o. x, y, x +&.*: y }}/"1 base
F =: 4 | 0.1 + ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment