Skip to content

Instantly share code, notes, and snippets.

@darrenwiens
Created March 14, 2022 22:54
Show Gist options
  • Save darrenwiens/c7efcfafa4c043b114192b66323b0a49 to your computer and use it in GitHub Desktop.
Save darrenwiens/c7efcfafa4c043b114192b66323b0a49 to your computer and use it in GitHub Desktop.
Climate spiral, Blender
import bpy
import math
import pandas as pd
df = pd.read_csv(
bpy.path.abspath("//HadCRUT.4.6.0.0.monthly_ns_avg.txt"),
delim_whitespace=True,
header=None
)
first_year = 1850
last_year = 2021
year_range = last_year - first_year
curveData = bpy.data.curves.new('myCurve', type='CURVE')
curveData.dimensions = '3D'
curveData.resolution_u = 2
curveData.bevel_depth = 0.01
polyline = curveData.splines.new('NURBS')
for index, row in df.iterrows():
year = int(row[0][:4])
month = int(row[0][5:])
angle = (2 * math.pi/11) * month
r = row[1] + 1
x = math.sin(angle) * r
y = math.cos(angle) * r
z = (year - first_year)/100
polyline.points.add(1)
polyline.points[-1].co = (x, y, z, 1)
curveOB = bpy.data.objects.new('myCurve', curveData)
bpy.data.collections['Curves'].objects.link(curveOB)
def change_text():
text = bpy.data.objects["YearText"]
current_frame = bpy.context.scene.frame_current
if current_frame <= 150: # I only want to update text in the first 150 frames
text.data.body = str(first_year + int((current_frame/150) * year_range))
def text_handler(scene):
change_text()
def register():
bpy.app.handlers.frame_change_post.append(text_handler)
register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment