Translating generative art from P5.JS Processing to Wolfram Language using LLM AI-reasoner models involves semantic mapping, syntax transformation, and leveraging Wolfram’s symbolic computation strengths. The process includes converting imperative loops (for, while) into functional constructs like Table or Map, replacing canvas-based rendering with Graphics primitives, and ensuring dynamic updates via Dynamic or Manipulate. Mathematical operations such as sin() and cos() are translated to their Wolfram equivalents (Sin[], Cos[]), while stateful variables are encapsulated in DynamicModule for localized interactivity.
Original artwork
Original artwork
Original P5.JS Processing code 1
Original P5.JS Processing code 1
a=(x,y,o=mag(k=x/4-12.5,e=y/9)/9)=>point((q=x+99+cos(9/k)+o*k*(cos(e*9)/3+cos(y/9)/.7)*sin(o*4-t))*.7*sin(c=o*e/30-t/8)+200,200+y/9*cos(c*4-t/2)-q/2*cos(c))
t=0,draw=$=>{t||createCanvas(w=400,w);background(6).stroke(w,46);for(t+=PI/60,i=3e4;i--;)a(i%100,i/150)}
t=0,draw=$=>{t||createCanvas(w=400,w);background(6).stroke(w,46);for(t+=PI/60,i=3e4;i--;)a(i%100,i/150)}
Original P5.JS Processing code 2
Original P5.JS Processing code 2
a=(x,y,o=mag(k=x/4-12.5,e=y/9+5)/9)=>point((q=x+99+tan(1/k)+o*k*(cos(e*9)/4+cos(y/2))*sin(o*4-t))*.7*sin(c=o*e/30-t/8)+9*cos(y/19+t)+200,200+q/2*cos(c))
t=0,draw=$=>{t||createCanvas(w=400,w);background(6).stroke(w,46);for(t+=PI/90,i=2e4;i--;)a(i%100,i/100)}
t=0,draw=$=>{t||createCanvas(w=400,w);background(6).stroke(w,46);for(t+=PI/90,i=2e4;i--;)a(i%100,i/100)}
Prompt for LLM AI-reasoner models
Prompt for LLM AI-reasoner models
A concise prompt such as “Translate the following Processing code to Wolfram, ensuring the final animation is expressed via the `Manipulate` function” is sufficient for modern AI reasoners to perform accurate translations. Known AI reasoners capable of handling such tasks include Open AI o1/o3, Qwen2.5-Max, DeepSeek R1, and other advanced language models trained in code translation and symbolic computation and reasoning. These systems excel at understanding both the syntactic and semantic nuances of programming languages, enabling seamless cross-language code transformations.
Translate the following Processing code to Wolfram. Final animation should be expressed via Manipulate function. Make sure animation is perfectly looped as original.
Original art on 𝕏
Original art on 𝕏
The original artist, Yuruyurau, is credited for creating the sea worm animations and math models behind them. Their work serves as the foundation for this translation project, bridging generative art and computational mathematics. More details can be found on their 𝕏 profile:
Artist 𝕏 feedL
Artist 𝕏 feedL
Original sea worms on 𝕏:
Original sea worms on 𝕏:
Wolfram code for 1st sea worm
Wolfram code for 1st sea worm
The first Wolfram code generates sea worm-like patterns by leveraging trigonometric transformations and modular arithmetic to calculate the positions of thousands of points. The mathematical expressions for k, e, and o normalize and scale the spatial coordinates, while the term Cos[9/k] introduces singularities that create sharp transitions in the pattern. The sinusoidal modulation of q with Sin[o*4 - t] produces oscillatory motion, and the angular term c = o*e/30 - t/8 governs the rotational dynamics of the points. These transformations collectively produce a dynamic, organic effect resembling wriggling worms.
ClearAll[frame1]frame1[t_?NumericQ] := Module[ { n = 30000, xs, ys, k, e, o, q, c, xp, yp, pts, cosTerm, tol = 10^-6, valid }, (* Compute x and y for i = 0, 1, …, n-1 *) xs = Mod[Range[0, n - 1], 100]; ys = Range[0, n - 1]/150; (* Compute k, e, and o *) k = xs/4 - 12.5; e = ys/9; o = Sqrt[k^2 + e^2]/9; (* Guard against division by zero: if |k| is too small, use 0 instead of Cos[9/k] *) cosTerm = Map[If[Abs[#] < tol, 0, Cos[9/#]] &, k]; (* Compute q *) q = xs + 99 + cosTerm + o*k*(Cos[9*e]/3 + Cos[ys/9]/0.7)*Sin[o*4 - t]; (* Compute c and final coordinates *) c = o*e/30 - t/8; xp = q*0.7*Sin[c] + 200; yp = 200 + ys/9*Cos[4*c - t/2] - (q/2)*Cos[c]; (* Filter out any points with non-numeric coordinates *) valid = MapThread[NumericQ[#1] && NumericQ[#2] &, {xp, yp}]; pts = Pick[Transpose[{xp, yp}], valid]; Point[pts]];
Wolfram code for 2nd sea worm
Wolfram code for 2nd sea worm
The second Wolfram code modifies the visual dynamics by introducing tangent-based terms (Tan[1/k]) and additional sinusoidal components like Cos[ys/19 + t]. The tangent function amplifies small variations in k, creating localized spikes that add complexity to the pattern. The term Cos[9*e]/4 + Cos[ys/2] modulates the amplitude of oscillations, while the vertical displacement 9*Cos[ys/19 + t] introduces a secondary wave-like motion. These mathematical adjustments enhance the visual richness, producing a more intricate and varied animation that retains the organic nature of the original sea worm patterns.
Clear[frame2]frame2[t_?NumericQ] := Module[ {n = 20000, xs, ys, k, e, o, c, q, xp, yp, pts, tanTerm, tol = 10^-6, valid}, (* Build lists for x and y. *) xs = Mod[Range[0, n - 1], 100]; ys = Range[0, n - 1]/100; (* Compute k, e, o *) k = xs/4 - 12.5; e = ys/9 + 5; o = Sqrt[k^2 + e^2]/9; (* Guard against division by zero in tan(1/k) *) tanTerm = Map[If[Abs[#] < tol, 0, Tan[1/#]]&, k]; (* Compute c and q, using our guarded tanTerm *) c = o*e/30 - t/8; q = xs + 99 + tanTerm + o*k*((Cos[9*e]/4) + Cos[ys/2])*Sin[o*4 - t]; (* Compute final coordinates *) xp = q*0.7*Sin[c] + 9*Cos[ys/19 + t] + 200; yp = 200 + (q/2)*Cos[c]; (* Remove any points with non-numeric coordinates *) valid = MapThread[NumericQ[#1] && NumericQ[#2] &, {xp, yp}]; pts = Pick[Transpose[{xp, yp}], valid]; Point[pts]];
Interactive animation
Interactive animation
The interactive animation combines both translated versions of the code using the Manipulate function. Users can adjust parameters like vertical displacement (d) and time (t) to explore variations in the sea worm visualizations. The Translate function shifts the two sets of points vertically, while Directive and PointSize control the appearance of the points. The PlotRange, ImageSize, and Background options ensure proper scaling and aesthetics.
In[]:=
Manipulate[Graphics[ { Directive[White, Opacity[.3], PointSize[.0025]], Translate[frame1[t],{0,-d}],Translate[frame2[t],{0,d}] }, PlotRange -> {{20, 380}, {-40, 430}}, ImageSize -> 550, Background -> GrayLevel[6/255], AspectRatio -> 1, Axes -> False, Frame -> False ],{{d,100},-150,150},{{t,30}, 0, 16 Pi}]
Video generation
Video generation
The video animation is generated using the AnimationVideo function, exporting the dynamic visualizations as a high-resolution video file. This step leverages Wolfram’s performance optimizations, including parallelized computation (Parallelize) and vectorized operations, to ensure smooth rendering at 720p resolution. The animation spans a time range of {t, 0, 16 Pi} with a default duration of 24 seconds, demonstrating the flexibility of Wolfram Language for dynamic content creation and dissemination.
CITE THIS NOTEBOOK
CITE THIS NOTEBOOK
Sea worms: translating from P5.JS Processing to Wolfram using LLM AI-reasoner models
by Vitaliy Kaurov
Wolfram Community, STAFF PICKS, February 3, 2025
https://community.wolfram.com/groups/-/m/t/3375671
by Vitaliy Kaurov
Wolfram Community, STAFF PICKS, February 3, 2025
https://community.wolfram.com/groups/-/m/t/3375671