Help! I need coding help! I want to code a heart beat...

Anyone know how to go about coding or creating a heart beat thing - you know like in hospitals your heart is hooked up to some sort of machine that gives you that squiggly line on the monitor? I want to create that heartbeat some how - and be able to increase it’s speed or decrease the heart rate speed… anyone have any ideas?

You could do this one of two ways.

  1. Spawn dots, each one right next to each other and control how high up or down they spawn. Scroll the dots to the right until they reach the edge of the screen, and then delete them. Push the dots up gradually on the heart beat, and push them down gradually (and back to the center).
  2. Use a 3D GLSL filter to do it - it’s a bit more controllable, but it requires you to use GLSL. An example can be found in AMD’s RenderMonkey software.

Hmm - using a 3D GLSL filter, I want this to be for inside blender’s game engine -
Is it possible to use a python script to superimpose a drawing line ( which follows some sin wave or wtv) over the screen?
Also - the dots idea is a pretty good one…

Also - SolarLune - can you see a way of adapting this : , in blender some how using python script? Or do you think it’s easier to just use a thing that spawns dots (objects) . Also, do you know if python knows the sin in mathutils lib?

Yeah, it’s possible to implement that in the BGE - you would use dot objects, or you could use the drawLine function that you mentioned. Alternatively, the GLSL filter is a viable route to implement it in the BGE. And the sin function is in the math module (not mathutils).

I think I’ll do the drawLine function - can you show me a test of a simple line being drawn from code into the blender game window?

Got it ! Nevermind - ok… so - Now is there a way to use the drawLine method to alter it into it making it look like a sine function moving like a heart beat monitor? Probably not…

Yeah, it should be possible, but there’s more to it than just drawing a sine function. If it was just drawing a sine function, you’d basically have to draw a line from each point to the next, and modulate the point’s positions on the Z-axis by the sin() function’s value.

You could maybe create a line of very small quads and then use the KX_VertexProxy class to set the vertex positions according to some sinusoidal function.

Not sure how practical or easy this would be, and you’d need some maths for wave equations, but I’m just throwing the idea out there.

Edit: Just had a (very) brief look at the freelancegames link and it might be possible to use that algorithm as a basis for setting the vertex coordinates instead of going into wave equations. They really are hard to get your head round. :spin:

Hmm - well if anyone has any ideas that really use a drawmethod instead of using in game objects - I’m all ears. So far - the trick seems to be drawLine -but I need a way of it to look like a heartbeat -

Anyway to use python script to drawCurve? Instead of line? Or to use drawLine, to draw a curve? I need code snippet (I am inexperienced)

It seems like a lot of hard work to custom-code a curve tool for bge just for a heart-rate monitor unless it’s a major part of your project. If I wanted a realtime curve, I’d use a mesh that consists of a single horizontal face loop scaled down along the vertical axis to look like a line, set the texture to “wireframe” and use KX_VertexProxy to manipulate the mesh according to an algorithm. You’d need to do the same thing to both the upper and lower edge loops to keep the polygons in shape, but this would be a lot easier than a custom curve implimentation.

I don’t like using objects where not needed is all :stuck_out_tongue_winking_eye: , if it can be scripted - I script it no matter what.
This way I can really optimize my game, and have little information. Every logic brick you add - and every in game object you add - increases file size, where as a text file is just characters and file size is kept to a minimal. I’m all about optimization and learning python! If someone knows of an algorithm that can manipulate the drawLine, would be appreciated!

I do see your point and I share your old-school philosophy of keeping file sizes small and efficient. :slight_smile:

I absolutely hate bloated software which is one of the reasons I think Blender is one of the shining gems amongst the current selection of softwares.

But mesh data is really tiny. Mesh data is essentially a load of 3d coordinates and can be stored in a few bytes. The entire of my current “4d pool” game project is about 100kb (not Mb) for all the game objects and the scripts. I’m deliberately keeping the file size down as a personal challenge. :wink:

If you use a standard Blender material instead of textures then this also keeps the file size down since texture data is massive compared to the space requirements of any topology.

I’m not suggesting that you do things without scripting, I’m merely suggesting that manipulating the existing C/C++ data types using Python might save development time and might be more efficient than creating an entire homebrew solution using Python alone. This is not saying that homebrew solutions are bad, in fact my preference is to code things myself. Unfortunately my C/C++ knowledge is pretty poor right now to say the least.

If you wanted to do this yourself using Python entirely then the first step would possibly be to create a “customCurve” class. This class would contain all of the points on your customCurve. The points themselves might also be instances of a customPoint class.

The customCurve class might have an “update” method that would accept a “magnitude” parameter and a “time” parameter. This “update” method would position all of the points of your “customCurve” by creating the blip of the heart beat using a displacement of “magnitude” and positioning this blip along the customCurve according to the “time” parameter. You could build in support for multiple blips along a single line that each have different “magnitude” and “time” parameters. Maybe this would be implemented using a “customBlip” class so you can change the shape of individual blips in order to represent both regular and irregular heartbeats.

All of the above would be needed if you used my mesh method or just used points. If you used a mesh then setting these points would be the final step, but if you want to script it with points then you would need a “draw” method that iterates along the points in your customCurve and then calls drawLine for every point and connects it to (point+1). (Of course, the final point in your customCurve would not be calculated as it doesn’t need to be joined to any other points.)

There’s probably a better way of doing this since I have a talent for doing things the hard way, but maybe this could provide inspiration if nobody else offers some help.

Hope you get this working, one way or the other (or maybe a different way?). :slight_smile:

I had a curve drawing function that I made in Game Maker - maybe I’ll see if I can port it over to Blender. It worked by drawing lines. However, Funky’s mesh manipulation method might be better, since you won’t have to worry about drawing lines between points - the BGE would handle that part for you. You would just have to worry about handling the points themselves.