Vapaasti pyörivä 3D-suihkulähde.
Itse en ole 3D-koodia tehnyt, vaan konvertoinut sen AVS (Winamp-visualisaatio)-formaatista BASICille.
Ja älkää valittako siitä, että tämä on purkkaliimaa. ;)
'' 3d code by EL-VIS (from the AVS community) '' Variables (in Finnish) '' rx,ry,rz: pyörityssuunta '' rdx,rdy,rdz: pyörityssuunnan delta (eli nopeus) '' p(*).x,y,z: partikkelin sijainti '' p(*).dx,dy,dz: partikkelin sijainnin delta (eli nopeus) '' p(*).a: aktiivinen? 0=ei, 1=kyllä, 2=hävitetään (purkkaliima) '' p(*).c: väri '' p(*).l: life, montako framea partikkeli on elänyt '' p(*).px,py: viimeisin sijainti näytöllä (putsaamista varten) '' dst: "focal length", pikselin z pitää olla vähintään -dst TYPE vec x AS SINGLE y AS SINGLE z AS SINGLE dx AS SINGLE dy AS SINGLE dz AS SINGLE a AS INTEGER l AS INTEGER c AS INTEGER px AS INTEGER py AS INTEGER END TYPE CONST maxp = 700 SCREEN 13 DIM p(maxp) AS vec c = 0 d = 0 FOR x = -3 TO 3 STEP .75 FOR y = -3 TO 3 STEP .75 p(c).x = x p(c).y = 0 p(c).z = y p(c).a = 1 c = c + 1 NEXT y NEXT x xres = 10 mo = 6.28 / xres FOR i = 0 TO xres p(c).x = SIN(i * mo + 3.14 / 2) * .5 p(c).y = 0 p(c).z = COS(i * mo + 3.14 / 2) * .5 p(c).a = 1 c = c + 1 p(c).x = SIN(i * mo + 3.14 / 2) * .5 p(c).y = -.5 p(c).z = COS(i * mo + 3.14 / 2) * .5 p(c).a = 1 c = c + 1 FOR e = 0 TO .5 STEP .05 p(c).x = SIN(i * mo) * .5 p(c).y = -e p(c).z = COS(i * mo) * .5 p(c).a = 1 c = c + 1 NEXT e FOR e = .2 TO .5 STEP .05 p(c).x = SIN(i * mo) * e p(c).y = -.5 p(c).z = COS(i * mo) * e p(c).a = 1 c = c + 1 NEXT e 'p(c).x = SIN(i * mo) * .3 'p(c).y = -.5 'p(c).z = COS(i * mo) * .3 'p(c).a = 1 'c = c + 1 p(c).x = SIN(i * mo) * .15 p(c).y = -.5 p(c).z = COS(i * mo) * .15 p(c).a = 1 c = c + 1 p(c).x = SIN(i * mo) * .125 p(c).y = -.65 p(c).z = COS(i * mo) * .125 p(c).a = 1 c = c + 1 p(c).x = SIN(i * mo) * .1 p(c).y = -.8 p(c).z = COS(i * mo) * .1 p(c).a = 1 c = c + 1 NEXT i FOR i = 0 TO c p(i).c = 15 NEXT i mpar = c + 1 rpar = maxp - mpar CONST sx = 320 CONST sy = 200 CONST cx = sx / 2 CONST cy = sy / 2 CONST ra = cx * .5 pg = 0 asp = sx / sy dst = 3.5 RANDOMIZE TIMER rx = 0 ry = 0 rz = 0 rdx = RND rdy = .6 rdz = RND p = 3.14159265# p2 = 2! * p p3 = 180 / p spout = 0 WHILE INKEY$ = "" spout = spout + 1 IF spout > 3 + RND * 3 THEN par = 0 WHILE p(par).a = 1: par = INT(mpar + RND * rpar): WEND p(par).l = 0 p(par).x = 0 p(par).y = -.81 p(par).z = 0 dir = RND * 6.28 p(par).dx = COS(dir) * .005 p(par).dy = -RND * .05 p(par).dz = SIN(dir) * .005 p(par).a = 1 p(par).c = 1 + RND * 14 spout = 0 END IF FOR i = mpar TO maxp IF p(i).a THEN p(i).l = p(i).l + 1 p(i).dy = p(i).dy + .0005 dc = SQR(p(i).x ^ 2 + p(i).z ^ 2) IF dc < .5 AND p(i).y > -.5 THEN p(i).y = -.51 p(i).dy = -p(i).dy * .3 END IF IF dc < .2 AND p(i).y > -.8 THEN p(i).a = 2 END IF IF p(i).y > 0 THEN p(i).y = -.01 p(i).dy = -p(i).dy * .3 END IF IF p(i).l > 200 THEN p(i).a = 2 END IF NEXT i rx = rx + rdx ry = ry + rdy rz = rz + rdz xs = SIN(rx / p3) ys = SIN(ry / p3) zs = SIN(rz / p3) xc = COS(rx / p3) yc = COS(ry / p3) zc = COS(rz / p3) FOR i = 0 TO maxp IF p(i).a THEN PSET (p(i).px, p(i).py), 0 p(i).x = p(i).x + p(i).dx p(i).y = p(i).y + p(i).dy p(i).z = p(i).z + p(i).dz x1 = p(i).x y1 = p(i).y z1 = p(i).z y2 = y1 * xc - z1 * xs z2 = y1 * xs + z1 * xc x2 = z2 * ys + x1 * yc z3 = z2 * yc - x1 * ys x3 = x2 * zc - y2 * zs y3 = y2 * zc + x2 * zs x4 = x3 y4 = y3 + .5 z4 = z3 + .5 IF 1 THEN x = x4 / (1 + z4 / dst) y = y4 / (1 + z4 / dst) IF x > 2 OR x < -2 OR y > 2 OR y < -2 THEN ELSE p(i).px = cx + x * ra p(i).py = cy + y * ra / asp PSET (p(i).px, p(i).py), p(i).c END IF END IF IF p(i).a = 2 THEN PSET (p(i).px, p(i).py), 0 END IF NEXT i WEND
Ei hassumpaa grafiikkaa, mutta koodi olisi kyllä syytä kommentoida paremmin. Tärkeä tieto on esim. se, mitkä muuttujat vaikuttavat pyörityssuuntaan.
Akx:n voi tosin olla vaikea kommentoida, mikäli ei ole itse 3d-koodia tehnyt. Hyvin toimii tuo pyöritys kuitenkin.
Hieno, mutta kommentointi olisi kivaa.
Lisäsin kommentit muuttujista.
Hieno ei muuta voi sanoa.
Hieano.
Aihe on jo aika vanha, joten et voi enää vastata siihen.