Koch curve: Difference between revisions

→‎{{header|J}}: link to image produced by the implementation
m (→‎{{header|Lua}}: added ref to bresenham's line impl)
(→‎{{header|J}}: link to image produced by the implementation)
Line 887:
tri=: ^ j. 4r3 * (_2 o. 0) * i._4
plot koch ^: 5 tri</lang>
 
[[j:File:Koch-snowflake.png|example]]
 
The idea is to continually expand the segments between a list of points in the complex plane. Given consecutive x and y in the list, v = (y-x)/3 is a vector representing 1/3 of the trip from x to y. An iteration building the Koch curve starts at x, advances by v, advances by v rotated by 60 degrees, advances by v rotated -60 degrees, and finally advances by another v, reaching y. x seg y produces this expansion. koch takes a list of points and expands segments between consecutive ones, producing another list. koch ^: 5 does this 5 times, and plot shows the snowflake in a window.
6,962

edits