Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Parametric Equations (interesting 3d addition)
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
lapo3399




PostPosted: Fri Jul 14, 2006 7:11 pm   Post subject: Parametric Equations (interesting 3d addition)

I love math. Therefore, I love anything that has to do with math. For me, algebra/graphing of parametric equations comes only second to calculus. Not only can these equations allow a programmer to let an object follow any path, they are also good for visual effects.

Now that I am done my small monologue, I just want to present a few interesting parametric designs that I have tried and may be useful (or just fun to watch). Most of them do not use offscreenonly, because it is unnecessary - most of them do not use Draw.Cls, because of esthetic reasons.

First: A full rotation of hyperbolic spirals branching inward to (maxx div 2, maxy div 2), then branching outward in a different colour.

code:

View.Set ("graphics:max;max")
var x, y: int

loop
    for i : 1 .. 2000
        x := round (3 * cos (i) / (i / 4000)) + (maxx div 2)
        y := round (3 * sin (i) / (i / 4000)) + (maxy div 2)
        Draw.FillOval (x, y, 1, 1, 1)
        delay (1)
    end for
    for decreasing i : 2000 .. 1
        x := round (3 * cos (i) / (i / 4000)) + (maxx div 2)
        y := round (3 * sin (i) / (i / 4000)) + (maxy div 2)
        Draw.FillOval (x, y, 1, 1, 2)
        delay (1)
    end for
end loop


Second: A bunch of colourful expanding and contracting Golden Curves, which run for 26 cycles before stopping.

code:

View.Set ("graphics:max;max")
drawfillbox (0, 0, maxx, maxy, black)
var x, y, r, n, h : int
n := 1
h := 15
for s: 1..13
    for i : 1 .. 100 * h
        for j : 1 .. 10
            x := 1 * (round (3 * (6.854 ** (i * j / 10000)) * cos (i))) + (maxx div 2)
            y := 1 * (round (3 * (6.854 ** (i * j / 10000)) * sin (i))) + (maxy div 2)
            Draw.FillOval (x, y, 1, 1, j * n)
        end for
    end for
    for decreasing i : 100 * h .. 1
        for j : 1 .. 10
            x := 1 * (round (3 * (6.854 ** (i * j / 10000)) * cos (i))) + (maxx div 2)
            y := 1 * (round (3 * (6.854 ** (i * j / 10000)) * sin (i))) + (maxy div 2)
            Draw.FillOval (x, y, 1, 1, black)
        end for
    end for
    n += 1
    h += 1
end for

for s: 1..13
    for i : 1 .. 100 * h
        for j : 1 .. 10
            x := 1 * (round (3 * (6.854 ** (i * j / 10000)) * cos (i))) + (maxx div 2)
            y := 1 * (round (3 * (6.854 ** (i * j / 10000)) * sin (i))) + (maxy div 2)
            Draw.FillOval (x, y, 1, 1, j * n)
        end for
    end for
    for decreasing i : 100 * h .. 1
        for j : 1 .. 10
            x := 1 * (round (3 * (6.854 ** (i * j / 10000)) * cos (i))) + (maxx div 2)
            y := 1 * (round (3 * (6.854 ** (i * j / 10000)) * sin (i))) + (maxy div 2)
            Draw.FillOval (x, y, 1, 1, black)
        end for
    end for
    n -= 1
    h -= 1
end for


Finally: A bunch of ovals following the path of a bunch of eight curves (basically figure 8's), all in different colours. Gives the illusion of a line of changing orientation and length. The only visible difference is that the origin of the line is also following an eight curve.

code:

View.Set ("graphics:max;max,offscreenonly")
var x, y : array 1 .. 10 of int

loop
    for i : 1 .. 100000
        Draw.Cls
        for j : 1 .. 10
            x(j) := round (40*j * sin (i / 100) + (maxx div 2))
            y(j) := round (40*j * sin (i / 100) * cos (i / 100) + (maxy div 2))
            Draw.FillOval (x(j), y(j), 2, 2, 3*j)
        end for
        View.Update
    end for
end loop


You can make these pretty quickly, and out of almost any relation with a parametric form. It's probably pretty obvious what I did to most of you, because it's not complex code and you've probably already used parametric graphing before. I just thought it was interesting to try and make patterns with parametric equations for once.
Sponsor
Sponsor
Sponsor
sponsor
lapo3399




PostPosted: Fri Jul 14, 2006 8:05 pm   Post subject: (No subject)

I just discovered an interesting 3d property with this .... movement of an array of ovals of changing size.... looks like the cone is sticking out at you. This program could be modified for any number of these 3d surfaces, to follow any parametric curve, to be any height, and to have the shape (change in oval diameter) of any curve revolved around it's central axis.

code:

View.Set ("graphics:max;max,offscreenonly")
var x, y : array 1 .. 70 of int

loop
    for i : 1 .. 100000
        Draw.Cls
            for j : 1 .. 70
                x (j) := round ((j * 5 * sin (2 * i / 100) * cos (i / 100)) + (maxx div 2))
                y (j) := round ((j * 5 * sin (2 * i / 100) * sin (i / 100)) + (maxy div 2))
                Draw.FillOval (x (j), y (j), 70-j, 70-j, 30+j)
            end for
        View.Update
    end for
end loop
lapo3399




PostPosted: Fri Jul 14, 2006 10:10 pm   Post subject: (No subject)

Here is an even further improvement to the 3d system, using rgb and borders to simulate depth, and a point that follows the mouse:

code:

View.Set ("graphics:max;max;nobuttonbar;title:3D by lapo3399,offscreenonly")
var x, y : array 0 .. 100 of int
var xm, ym, but : int
var clr : int := 218
var clr2 : int := 219

loop
    for i : 1 .. 100000
        Draw.Cls
        Mouse.Where (xm, ym, but)
        for j : 0 .. 100
            RGB.SetColor (clr, (j - 1 / 100), (j - 1 / 100), (j - 1 / 100))
            RGB.SetColor (clr2, (j - 10/ 100), (j - 10/ 100), (j - 10/ 100))
            x (j) := round (maxx div 2 + (j * (xm - maxx div 2) / 100))
            y (j) := round (maxy div 2 + (j * (ym - maxy div 2) / 100))
            Draw.FillOval (x (j), y (j), round ((100 - j)), round ((100 - j)), clr)
            Draw.Oval (x (j), y (j), round ((100 - j)), round ((100 - j)), clr2)
        end for
        View.Update
    end for
end loop


And a change in shape:

code:

View.Set ("graphics:max;max;nobuttonbar;title:3D by lapo3399,offscreenonly")
var x, y : array 0 .. 100 of int
var xm, ym, but : int
var clr : int := 218
var clr2 : int := 219

loop
    for i : 1 .. 100000
        Draw.Cls
        Mouse.Where (xm, ym, but)
        for j : 0 .. 100
            RGB.SetColor (clr, (j - 1 / 100), (j - 1 / 100), (j - 1 / 100))
            RGB.SetColor (clr2, (j - 10/ 100), (j - 10/ 100), (j - 10/ 100))
            x (j) := round (maxx div 2 + (j * (xm - maxx div 2) / 100))
            y (j) := round (maxy div 2 + (j * (ym - maxy div 2) / 100))
            Draw.FillOval (x (j), y (j), round (500/(j+1)), round (500/(j+1)), clr)
            Draw.Oval (x (j), y (j), round (500/(j+1)), round (500/(j+1)), clr2)
        end for
        View.Update
    end for
end loop

Windsurfer




PostPosted: Sun Jul 16, 2006 11:26 am   Post subject: Nice

Very nice, simple effects! I like it very much. Keep up the good work.
Maybe a tutorial could come out of this?

+25 bits
Delos




PostPosted: Sun Jul 16, 2006 11:46 am   Post subject: (No subject)

Tutorial - I'm not too sure about that. Sure this is a nifty application of some Gr12 maths, but otherwise it's just pretty pictures. Which, by the way, aren't 3D Very Happy! They're, uh, pseudo-3D...
Anyhow, I do like this, but I would like it even more if I saw less repitition in your code!
code:

       x (j) := round (maxx div 2 + (j * (xm - maxx div 2) / 100))
       y (j) := round (maxy div 2 + (j * (ym - maxy div 2) / 100))


Why!? Make a simple function that will accept a couple of necassary paramters and you'll find your life so, so much easier. Also, your code will be more meaningful. To wit:
code:

% Consider:
y := x ** 2

% versus

function square_of (num : int) : int
  result num ** 2
end square_of
y := square_of (x)

Suddenly the code is no longer simply maths, but maths that speaks to you!

+bits for preempting a manipulation I was going to suggest after having seen the first example. (Using shades of grey to emulate the 3rd dimension).[/code]
lapo3399




PostPosted: Sun Jul 16, 2006 6:54 pm   Post subject: (No subject)

Thanks for the interest. I was planning on making something along the lines of what you talked about, Delos. Allowing the user to input parameters would be an interesting feature as well... the non-pseudo-3d stuff would be interesting for plotting non-functional relations as well in a graphing program, as long as one had a polarization/parametrization (or if not, simply use y and x as functions of i, with x:=i and y:= Cartesian function with i subbed in for x). Also, the pseudo-3d stuff would be interesting for plotting solids of revolution.... hmmm...

And, not that I'm trying to invoke any kind of argument here, but imo the term pseudo-3d as applied to certain computer-generated 3d scenes is most certainly incorrect, at least in a linguistic (in terms of the term) and physical (in terms of the science) sense. Although "true" 3d graphics use a different method for displaying a 3-dimensional scene, they in truth are not 3 dimensional. Even stereoscopy does not produce true 3-dimensional space - the effect is because of the natural processes that occur in our brains. Therefore, if the laws of language and physic were to be obeyed, then the term for all CG 3D environments would be pseudo-3d. After all, pseudo is Greek for "false."

There, I've finished my monologue (I find the word "rant" disturbing*, for some reason it reminds me of walruses**).


* I am eccentric (very).
** For some reason (maybe my love for Latin and Greek) it's always seemed to me that the word walrus should actually be pluralized walri. Visit footnote 1 for another reason why I may think this.
Delos




PostPosted: Sun Jul 16, 2006 9:39 pm   Post subject: (No subject)

Hmm...I'm starting to get worried here. I was actually going to present that very argument myself as I was discussing the nature of pseudo-3dness. Ah well, that just means I get to run the rebuttal! Wheeeee!

We are speaking conxtually - never forget that. Since you chose to bring in linguistics, I'm afraid I'll have to pull out my trusty psycholinguistics and use that in this discussion. Since it's contextual now.
This is a forum about CompSci, and unless otherwise indicated, discussion in at the very least this particular thread is CompSci related. This is the basis of the context I spoke of. Hence, my reference to 'pseudo-3Dness' meant that it was not actually a 3D-engine of sorts, as it only incorporated 2 dimensions of analysis. Sure all 3D engines produce 2D projections, but that's entirely besides the point. I used the term 'pseudo-' meaning 'not quite the real thing'. This is its modern anglasisation, derived from Greek. It is also a bit of a colloquiolism too - though in a very, very broad sense...Laughing. And if you know any linguistic terminology, that joke will be quite funny indeed. Otherwise, simply nod and smile.
Now, if you're going to start talking about what happens in our brains, I'm afraid you'll have to take two or three steps back. Nay, make that twelve or thirteen. I'll just accept your point and not prolong the debate, mostly because I want to go and sleep just now. Suffice it to say that upper-cortical processing primarily in the occiptal and frontal lobes result in the concious perception of shape and dimension, regardless of fallacious lower sensory input.

Anyhow, get to work on those procs/fcns. Things are so much prettier with them!
lapo3399




PostPosted: Sun Jul 16, 2006 10:37 pm   Post subject: (No subject)

It seems as though I've always been one step ahead of you in this thread.I don't know exactly what's happening, but I'm pretty sure it's somewhere between me reading your mind and my eccentricities* getting the better of me.


*If you immediately thought of orbital mechanics then you are my new best friend...
Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: Mon Jul 17, 2006 2:21 am   Post subject: (No subject)

But... but... Delos is supposed to be the clairvoyant one!

Anyway, that's some pretty amazing stuff you've done there. Good job. Smile
Delos




PostPosted: Mon Jul 17, 2006 9:36 am   Post subject: (No subject)

Gandalf, Gandalf. Er, I mean, [Gandalf], [Gandalf]...Do you not read/listen always? lapo clearly said
lapo wrote:

It seems...


And I mentioned several times how I had the same line of thought as he, just I did not bother delving into it. Question not my clairvoyence, partial though it may be. Otherwise I might just make you drop that sandwich later on Very Happy.
NikG




PostPosted: Tue Jul 18, 2006 9:25 pm   Post subject: (No subject)

Delos wrote:
Otherwise I might just make you drop that sandwich later on Very Happy.
Whoa Delos... did you just make me drop mine??
haha

Great effects lapo3399. I particularly like the colorfully cone and your last code snippet.

+bits


Edit: hmm... I noticed something in a few of your sinppets... why is it that you commonly declare the x/y variables as arrays when you only use them once in your loops?
code:
View.Set ("graphics:max;max,offscreenonly")
var x, y : int %these do not need to be arrays
loop
    for i : 1 .. 100000
        Draw.Cls
        for j : 1 .. 70
            x := round ((j * 5 * sin (2 * i / 100) * cos (i / 100)) + (maxx div 2))
            y := round ((j * 5 * sin (2 * i / 100) * sin (i / 100)) + (maxy div 2))
            Draw.FillOval (x, y, 70 - j, 70 - j, 30 + j)
        end for
        View.Update
    end for
end loop
the_short1




PostPosted: Fri Jul 28, 2006 10:23 pm   Post subject: (No subject)

Hey matt.. . sure enuf some crazy math enhanced visuals in turing.. great stuff Smile Woulnt beleive this kid is gr11! +Bits
TokenHerbz




PostPosted: Wed Aug 02, 2006 11:10 pm   Post subject: (No subject)

I LIKE I LIKE I LIKE!!!!


Neat little things
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 13 Posts ]
Jump to:   


Style:  
Search: