POV-Ray : Newsgroups : povray.general : Rendering an electromagnetic field and photon rays : Re: Rendering an electromagnetic field and photon rays Server Time
29 Apr 2024 00:05:57 EDT (-0400)
  Re: Rendering an electromagnetic field and photon rays  
From: Bald Eagle
Date: 25 Oct 2017 17:45:00
Message: <web.59f104fd9b56bbdd5cafe28e0@news.povray.org>
Car tire is all fixed.
25 min of driving time, and already I get a flat.   :|
UN-believable.

"cbpypov" <nomail@nomail> wrote:
> Moreover, I'd really enjoy getting your code and to see what can do with it :)

....and here it is:
(be aware that copying and pasting from a forum post may give you bad formatting
results, and you'll have to fix any CR/NL line errors)
I couldn't figure out to get the original Processing code - supposedly he has
all the code posted for each of his Code Challenge videos.
Perhaps someone else can figure it out.  (I still suck at using GitHub)
============================================================================

#version 3.7;
global_settings { assumed_gamma 1.0 }

//------------------------------------------
// SDL for Perlin Noise flow field
// NOT WORKING - vector array looks fine, it's the "movement" of the points that
the problem
// the points don't follow the flow field.
// The loop at the end just simulates an animation, without having to render all
the frames.
// Bill Walker - 2017
//------------------------------------------

#include "colors.inc"
#include "functions.inc"

#declare Aspect = image_width/image_height;

camera {
 location  <(image_width/2), (image_height/2), -600>
 right x*Aspect
 look_at <(image_width/2), (image_height/2), 0>
}

light_source { <10, 50, 0>  color rgb <1, 1, 1>}

sky_sphere { pigment {White} }

//=====================================================================================================================
==

#declare E = 0.000001;
#declare inc = 0.02;
#declare Scale = 10;

#declare cols = floor (image_width / Scale);
#declare rows = floor (image_height / Scale);
#declare Particles = array [100];
#declare FF = cols*rows;
//#debug concat ( " FF = ", str (FF, 3, 1),  "\n")
#declare FlowField = array [cols * rows];
#declare Mag = 1;
#declare MaxSpeed = 4;

#declare Seed = seed (12345);

#macro Vect (A)
 <cos(A), sin(A), 0>
#end // end macro Vect

#macro Particle ()
 #declare Pos = <rand(Seed)*image_width, rand(Seed)*image_height>;
 #declare Vel = <0, 0>; //<rand(Seed), rand(Seed)>;
 #declare Acc = <0, 0>;
 #declare PrevPos = Pos;
 array [4] {Pos, Vel, Acc, PrevPos}
#end // end macro Particles

#macro Update (P)
 #declare P[1] = P[1] + P[2];
 #declare P[1] = <min (P[1].x, MaxSpeed), min (P[1].y, MaxSpeed)>;  // limits
speed to max speed
 #declare P[0] = P[0] + P[1];
 #declare P[2] = P[2] * 0;
#end // end macro Update

#macro Follow (P, Vectors)
 #declare XX = floor (P[0].x / Scale);
 #declare YY = floor (P[0].y / Scale);
 #declare Index = XX + YY * cols;
 //#debug concat ( " Index = ", str (Index, 3, 1),  "\n")
 #declare F = Vectors [Index];
 Force (P, F)
#end // end macro Follow

#macro Force (P, F)
 #declare P[2] = P[2] + <F.x, F.y>;
#end // end macro Force

#macro Show (P)
 //sphere {<P[0].x, P[0].y, 0> 0.5 texture {pigment {Color} finish {specular
0.4}} }
 cylinder {<P[3].x, P[3].y, 0>, <P[0].x, P[0].y, 0> 1 texture {pigment {Color}
finish {specular 0.4}} }
 UpdatePrev (P)
#end // end macro Show

#macro UpdatePrev (P)
 //#debug concat ( "Prev = ", vstr(3, P[3], ", ", 2, 0), " \n")
 #declare P[3] = P[0]+<E,E>;
 //#debug concat ( "Current = ", vstr(3, P[3], ", ", 2, 0), " \n")
#end // end macro UpdatePrev

#macro Edges (P)
 //#local PX = P[0].x;
 //#local PY = P[0].y;
 #if (P[0].x > image_width)  #declare P[0] = <1, P[0].y>;     UpdatePrev (P)
#end
 #if (P[0].x < 0)    #declare P[0] = <image_width-1, P[0].y>;  UpdatePrev (P)
#end
 #if (P[0].y > image_height)  #declare P[0] = <P[0].x, 0>;     UpdatePrev (P)
#end
 #if (P[0].y < 0)    #declare P[0] = <P[0].x, image_height-1>;  UpdatePrev (P)
#end
#end // end macro Edges


#macro Draw()
 #declare zoff = 0;
 #local yoff = 0;
 #for (Y, 0, rows-1)
  #local xoff = 0;
  #for (X, 0, cols-1)
   #local index = X + Y * cols;

   #local r = f_noise_generator (xoff, yoff, zoff, 3); // 3 = Perlin noise
   #local A = degrees (r*2*pi);
   #local V = Vect (A)*Mag;
   #declare FlowField [index] = V;

   #local xoff = xoff + inc;

   #local Grayscale = 0;
   //#local HSV_Angle = rand (Seed)*360;
   //#local Color = CHSV2RGB (<HSV_Angle, 1, 1>);
   //box {<X*Scale, (Y/Aspect)*Scale, 0>, <X*Scale+Scale,
((Y*Scale)/Aspect)+Scale, 0.1> pigment {rgb Grayscale}}
   cylinder {<0,0,0>, V*(1/Mag)*Scale 0.5 translate <X*Scale, Y*Scale, 0>
pigment {rgb Grayscale}}
  #end // end for X
  #local yoff = yoff + inc;
  //#declare zoff = zoff + 0.0003;
 #end // end for Y
#end // end macro Draw

//Draw()
#for (i, 0, 99)
 #declare Particles [i] = Particle();  // create a particle with position,
velocity, accel
#end

#for (Clock, 0, 500)
Draw() // update vectors

#for (i, 0, 99)
 #declare Color = CHSV2RGB (<i*3.6, 1, 1>);

 Follow (Particles [i], FlowField)   // pair particle at location with vector in
that part of field
 Update (Particles [i])     // update particle position, velocity, acceleration
 Edges  (Particles [i])     // wrap particles around edges
 Show   (Particles [i])     // plot particle positions / paths

#end // end for i

#end // end for Clock


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.