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

Username:   Password: 
 RegisterRegister   
 sin wave surface in 3D
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
zylum




PostPosted: Sat Apr 03, 2004 5:18 pm   Post subject: sin wave surface in 3D

well, i was looking through the best of turing submissions thread and saw a few particle systems and thought i'd mak one in 3d... anyways, one thing lead to another and i came up with this.... sorry it's a bit slow but it has a lot of points to calculate.

code:
setscreen ("offscreenonly,graphics:1000;700,nobuttonbar,position:middle;middle")

type _3D :
    record
        x : real
        y : real
        z : real
    end record

const xs := 30
const zs := 30
const perspective := 400
const spread := 10
const amplitude := 12
const wavelength := 2

var coords : array 1 .. xs * zs of _3D
var depth : int
var n : int := 0
var x, y, oldx, oldy : int
var angX, angY : real := 45
var a : real := 0

const colors := 220
var clr : array - colors div 2 .. colors div 2 of int
for i : 1 .. colors
    clr (i - colors div 2) := RGB.AddColor (i / colors, i / colors, i / colors)
end for

var COS, SIN : array 0 .. 360 of real
for i : 0 .. 360
    COS (i) := cos (i * (Math.PI / 180))
    SIN (i) := sin (i * (Math.PI / 180))
end for

procedure rotate (xpp, ypp, zpp, ax, ay, az : real)
    var temp : real
    var xp, yp, zp : real
    yp := ypp * COS (round (ax)) - zpp * SIN (round (ax))
    zp := zpp * COS (round (ax)) + ypp * SIN (round (ax))
    temp := zp
    zp := zp * COS (round (ay)) - xpp * SIN (round (ay))
    xp := xpp * COS (round (ay)) + temp * SIN (round (ay))
    temp := xp
    xp := xp * COS (round (az)) - yp * SIN (round (az))
    yp := yp * COS (round (az)) + temp * SIN (round (az))
    depth := round (zp)
    x := round (xp / (1 - zp / perspective)) + maxx div 2
    y := round (yp / (1 - zp / perspective)) + maxy div 2
end rotate

for _x : 1 .. xs
    for _z : 1 .. zs
        n += 1
        coords (n).x := _x * spread - (xs / 2) * spread
        coords (n).z := _z * spread - (zs / 2) * spread
        coords (n).y := (cos (_x / wavelength) * amplitude) + (sin (_z / wavelength) * amplitude)
    end for
end for

loop
    n := 0
    a += 0.05
    angX := sin (a) * 35 + 90
    angY += 2
    for _x : 1 .. xs
        for _z : 1 .. zs
            n += 1
            rotate (coords (n).x, coords (n).y, coords (n).z, angX mod 360, 1, angY mod 360)
            if _z > 1 then
                Draw.ThickLine (oldx, oldy, x, y, (depth + 250) div 15, clr (depth * -1))
            end if
            oldx := x
            oldy := y
        end for
    end for
    View.Update
    cls
end loop


-zylum Wink
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Sat Apr 03, 2004 5:23 pm   Post subject: (No subject)

nice Very Happy looks good, too bad it runs slow Confused +20Bits
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Paul




PostPosted: Sat Apr 03, 2004 5:24 pm   Post subject: (No subject)

omg thats crazy, its like when I first saw runescape, and thought it was crazy being done with java applet lol Razz
recneps




PostPosted: Sat Apr 03, 2004 8:03 pm   Post subject: (No subject)

OMG that amazing. Teach us! lol +bits
zylum




PostPosted: Sun Apr 04, 2004 4:18 pm   Post subject: (No subject)

i'm glad you guys like it! Razz

here's another similar effect... make sure you dont draw for too long cuz it will get lagy.

-zylum



3d_001.t
 Description:

Download
 Filename:  3d_001.t
 Filesize:  2.28 KB
 Downloaded:  341 Time(s)

Catalyst




PostPosted: Sun Apr 04, 2004 5:19 pm   Post subject: (No subject)

i like both of them
very creative

have ... 83 bits
Paul




PostPosted: Sun Apr 04, 2004 6:35 pm   Post subject: (No subject)

holy!!! that is just amazing? that second one, were you trying to achieve a 3D effect? cause thats what I see...
zylum




PostPosted: Sun Apr 04, 2004 6:39 pm   Post subject: (No subject)

wow thanks, nuf bits there catalyst Shocked

and yeah, i was trying to make it 3D

[edit] well it is 3D[/edit]

-zylum
Sponsor
Sponsor
Sponsor
sponsor
valor




PostPosted: Wed Apr 07, 2004 2:33 pm   Post subject: (No subject)

wow the day i learn how to do that is when Micheal Jackson isnt a Child Malester
i dont have much but here +10 bits
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  [ 9 Posts ]
Jump to:   


Style:  
Search: