Archive: AVS broke my heart:(


17th February 2005 01:12 UTC

AVS broke my heart:(
Not really, I just tried to make a per point valentine's day heart in avs and it went all to heck:(.

I got this far via the search feature + help from ^_^. Unfortunately I'm stuck. Rereading the sections about registers, megabuffs, and loops, in Pak-9's guide. I have a sneaking suspicion they would help. Just a matter of figuring out how.

I'll try to explain what I did, then post the code, in hopes someone with more knowledge will see what I did wrong.

First I took a piece of graph paper and plotted out the shape. I have x's negative on the left, and y's negative on the top(made a note of it on the paper so I wouldn't forget). Then I proceeded to mark the points into the shape I was trying for. A simple, rather boxy heart shape. I then made sure to mark the points with their respective #'s like this: x,y, so for example the point at the bottom tip of the heart is marked as 0,8.

After I marked and labelled all my points on the graph paper I wrote out the code longhand on the paper. I started at the top of the heart, right in the middle, at 0,0 then went all the way around, first for x then for y.

Then I typed it all up in Notepad and saved it(just in case avs would crash on me). Here's the code I tried to write:

init ~ n=29;

frame ~ p=0;

point ~

p=p+1;

x=equal(p,1)*0.0+equal(p,2)*0.1+equal(p,3)*0.2+equal(p,4)*0.3+equal
(p,5)*0.4+equal(p,6)*0.5+equal(p,7)*0.6+equal(p,8)*0.6+equal
(p,9)*0.6+equal(p,9)*0.5+equal(p,10)*0.4+equal(p,11)*0.3+equal
(p,12)*0.2+equal(p,13)*0.1+equal(p,14)*0.0+equal
(p,15)*-0.1+equal(p,16)*-0.2+equal(p,17)*-0.3+equal
(p,18)*-0.4+equal(p,19)*-0.5+equal(p,20)*-0.6+equal
(p,21)*0.6+equal(p,22)*0.6+equal(p,23)*-0.5+equal
(p,24)*-0.4+equal(p,25)*-0.3+equal(p,26)*-0.3+equal
(p,27)*-0.2+equal(p,28)*-0.1+equal(p,29)*0.0;

y=equal(p,1)*0.0+equal(p,2)*-0.1+equal(p,3)*-0.2+equal
(p,4)*-0.2+equal(p,5)*-0.2+equal(p,6)*-0.1+equal
(p,7)*0.0+equal(p,8)*0.1+equal(p,9)*0.2+equal
(p,10)*0.3+equal(p,11)*0.4+equal(p,12)*0.5+equal
(p,13)*0.6+equal(p,14)*0.7+equal(p,15)*0.8+equal
(p,16)*0.7+equal(p,17)*0.6+equal(p,18)*0.5+equal
(p,19)*0.4+equal(p,20)*0.3+equal(p,21)*0.2+equal
(p,22)*0.1+equal(p,23)*0.0+equal(p,24)*-0.1+equal
(p,25)*-0.2+equal(p,26)*-0.2+equal(p,27)*-0.2+equal
(p,28)*-0.1+equal(p,29)*0.0;


On the paper it's a symetrical boxy kind of a heart shape(don't wanna get too fancy just yet) but in avs it's all wonky. When displayed as dots it's close but no cigar, and when displayed as lines it's just a big old mess.

If it basically looks okay, and doesn't look like I did anything especially wrong, then I'll just go back over it and rewrite the code, trying extra hard to make sure each point is matched in x and y. Going back and forth between x and y if need be.

I'm just hoping someone can tell me if it's looking pretty much okay, or if I left something out. From there I can work on fixing it.


17th February 2005 10:47 UTC

to get a better view of what's your problem perhaps you could better write it all out in lines like:

y=
equal(p,1)*0.0+
equal(p,2)*-.1 etc.

then write a table of all x and y coördinates you wrote on paper and check that with your code.


17th February 2005 11:03 UTC

Funnily enough, that's what I did. Or at least what I think I did. I'm guessing that at a glance it looks okay, which means I must have typed the code wrong at some point.


17th February 2005 12:57 UTC

Are the points being drawn in the correct order?


17th February 2005 17:50 UTC

equal(p,18)*-0.4+
equal(p,19)*-0.5+
equal(p,20)*-0.6+
equal(p,21)*0.6+
equal(p,22)*0.6

Notice that here your X coordinates go from negative X to positive X, resulting in diagonals.

+equal(p,9)*0.6+equal(p,9)*0.5+

Here you have p=9 twice.

Looking at the shape, it seems you are not drawing the points in the correct order, and that you copied a few points incorrectly. Perhaps you made a mistake on paper when you marked the X,Y coordinates.


17th February 2005 18:05 UTC

If I had this many coordinates I would use the megabuf, assign all the points in init and read them out in point. In your init do:

assign((megabuf,0),<point 1 x>);
assign((megabuf,1),<point 1 y>);
assign((megabuf,2),<point 2 x>);
assign((megabuf,3),<point 2 y>);
assign((megabuf,4),<point 3 x>);
assign((megabuf,5),<point 3 y>);
etc...

then you can just read out the x and y pairs in your point box:

frame:
point=0;

point:
x=megabuf(point);
y=megabuf(point+1);
point=point+1;


To be honest if it was me I would just describe the shape geometrically, it would be a lot less painful. Two warped semi-cirles would do it. The equation of a centred circle is x^2+y^2=r^2 so assuming a radius of 1.. y=sqrt(1-y^2) sticking x as i will probably get you a semicircle (I'm not in front of AVS so I cant test all this) Then just warp it upwards with some trial and error (y=sqrt(1-y^2)-(y+1)*0.1 or something) and scale it down to the size you want.


17th February 2005 23:11 UTC

Thanks so much for pointing out where I had p,9 twice. I couldn't find it(probably because of so many points). Also thanks for suggesting megabufs. I'm still trying to wrap my brain around that concept though. Was just happy to finally be able to put some points in place(although I placed them wrong:(). Back to the drawing board.


11th March 2005 22:37 UTC

Hi,

I backburnerred this for awhile. I knew it wasn't hopeless, just a case of not being able to see the forest for the trees. Today, I reaxamined my code, and still couldn't figure out what was wrong. Then I stared at the broken heart, both as lines and dots for a time. Suddenly I was able to see where I went wrong.

Instead of trying to write the code longhand, I just took my graphed heart with coordinates and started typing in the code. The heart was still broken, then I stared some more at the heart, and realized that I had not only double-typed some points, but flipped some negatives and positives.

To Pak-9, I still don't have megabuff in, because I'm still trying to understand megabuff. I'll get there. I'm just happy I've finally figured out per point placement(not sure if that's the correct term). :)

Fixed it, and here's how the superscope looks now:


12th March 2005 01:08 UTC

congrats! as you said: it works! :up:

Now (if you want) try to do it with megabuf. The idea behind that is quite simple when you know what the megabuf is or what it does (and which other functions you need in order to use it ;)). Just imagine a table or list or something with ca. 1,000,000 free "places". Now you assign your x- and y-values to the places of those buffer at the beginning. Instead of selcting the correct coordinates at the right time using equal(p,1)*xcoord1 or so you just look them up in the buffer. If you stored them in the correct order, you will only have to proceed to the next entry of the buffer everytime there is a new frame. Hope you can understand this explanation...