Created
November 9, 2024 15:51
-
-
Save cdr6934/2b4d7380c0fa970e3036183bba196c22 to your computer and use it in GitHub Desktop.
Following is the code3 that is used to generate the Lorenz attractor used in the following video: https://www.youtube.com/watch?v=iDHWyt1v4T8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
## Class for the lorenz | |
class Lorenz: | |
def __init__(self, sceneRef, objName, color, initX, initY, initZ): | |
self.X, self.Y, self.Z = initX, initY, initZ | |
self.dt = 0.0025 | |
self.a, self.b, self.c = 10, 48, 2.76 | |
self.color = color | |
self.objName = objName | |
self.sceneRef = sceneRef | |
def Step(self): | |
self.X = self.X + (self.dt * self.a * (self.Y - self.X)) | |
self.Y = self.Y + (self.dt * (self.X * (self.b - self.Z) - self.Y)) | |
self.Z = self.Z + (self.dt * (self.X * self.Y - self.c * self.Z)) | |
def Generate(self): | |
#Define number of points to be used | |
numPoints = 20000 | |
self.curve = bpy.data.curves.new("LorenzCurve", type='CURVE') | |
self.curve.dimensions = '3D' | |
self.curve.bevel_depth = 0.25 | |
# Create spline poly | |
attractorPoly = self.curve.splines.new('POLY') | |
attractorPoly.points.add(numPoints-1) | |
for i in range(0,numPoints): | |
attractorPoly.points[i].co = (self.X, self.Y, self.Z, 1) | |
self.Step() | |
self.body = bpy.data.objects.new('curve', self.curve) | |
self.body.name = self.objName | |
self.sceneRef.collection.objects.link(self.body) | |
scene = bpy.context.scene | |
newColor = (1.0, 0.4, 0.0, 1.0) | |
attractor1 = Lorenz(scene, "attractor2", newColor, 0.1, 0.0, 0.0) | |
attractor1.Generate() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment