Fall Foliage
#1
That time of year again...


Attached Files Thumbnail(s)

.bas   fall foliage.bas (Size: 2.17 KB / Downloads: 9)
B += x
Reply
#2
Great. Now my hard drive is filled up with a bunch of damn leaves. Angry You wouldn't happen to have the code for a blower handy by any chance, would ya?

Pete Big Grin
Reply
#3
Hi Pete, 

Try Tree Swirl...

wait... try Psychedelic Swirl, after that you won't care how many leaves you have. Big Grin
B += x
Reply
#4
You may want to try some of that stuff yourself, because look, I just got THREE stars!

Pete Big Grin
Reply
#5
3 Stars! Congrats!

If you want to see stars, some rising, some falling, growing, shrinking, all moving, all twirling...:

Code:
'remake Star Worlds.bas for SmallBASIC [B+=MGA] 2017-03-29
'using Chris method in Triangles to create what Johnno calls Particle Programs
'and shian's LOCAL method, and new plasma/flasher method

func rand(n1, n2)
 local l
 if n1 > n2 then l.hi = n1 : l.lo = n2 else l.hi = n2 : l.lo = n1
 rand = (rnd * (l.hi - l.lo + 1)) \ 1 + l.lo
end

func starArr(byref star)
 ' x, y are same as for circle,
 ' rInner is center circle radius
 ' rOuter is the outer most point of star
 ' nPoints is the number of points,
 ' angleOffset = angle offset IN DEGREES, it will be converted to radians in sub
 ' this is to allow us to spin the polygon of n sides
 ' TFfill filled True or False (1 or 0)
 
 'use l. method for tracking what is local
 local l   'p_angle, rad_angle_offset, x1, y1, i, arr
 dim l.arr()
 l.p_angle = rad(360 / star.n)  :  l.rad_angle_offset = rad(star.a - 90)
 l.x1 = star.x + star.ro * cos(l.rad_angle_offset)
 l.y1 = star.y + star.ro * sin(l.rad_angle_offset)
 l.arr << l.x1 : l.arr << l.y1
 for l.i = 0 to star.n - 1
   l.x1 = star.x + star.ri * cos(l.i * l.p_angle + l.rad_angle_offset + .5 * l.p_angle)
   l.y1 = star.y + star.ri * sin(l.i * l.p_angle + l.rad_angle_offset + .5 * l.p_angle)
   l.arr << l.x1 : l.arr << l.y1
   l.x1 = star.x + star.ro * cos((l.i + 1) * l.p_angle + l.rad_angle_offset)
   l.y1 = star.y + star.ro * sin((l.i + 1) * l.p_angle + l.rad_angle_offset)
   l.arr << l.x1 : l.arr << l.y1
 next
 if star.f then drawpoly l.arr filled else drawpoly l.arr
 starArr = l.arr
end

func makeStarProperties
 local p
 p.x = rand(0, xmax)
 p.y = rand(0, ymax)
 p.ri = rand(5, 20)
 p.m = rand(1.2, 3.5)
 p.ro = p.ri * p.m
 p.n = rand(3, 17)
 p.a = rand(0, 360)
 p.f = rand(0, 1)
 p.dx = rand(-5, 5)
 p.dy = rand(-5, 5)
 p.sp = rand(-10, 10)
 p.z = rand(-3, 3)
 p.c = rgb(rand(128, 255), rand(128, 255), rand(128, 255))
 makeStarProperties = p
end

dim StarWorlds
n = 50
for i = 0 to n
 StarWorlds << makeStarProperties
next

while 1
 cls
 for i = 0 to n
   color StarWorlds(i).c
   istar = starArr(StarWorlds(i))
   StarWorlds(i).c = StarWorlds(i).c * .999
   StarWorlds(i).a = (StarWorlds(i).a + StarWorlds(i).sp) mod 360
   StarWorlds(i).ri = StarWorlds(i).ri + StarWorlds(i).z
   if StarWorlds(i).ri > 50 then
     StarWorlds(i).ri = 50 : StarWorlds(i).z = -1 * StarWorlds(i).z
   elif StarWorlds(i).ri < 5
     StarWorlds(i).ri = 5 : StarWorlds(i).z = -1 * StarWorlds(i).z
   end if
   StarWorlds(i).ro = StarWorlds(i).m * StarWorlds(i).ri
   StarWorlds(i).x = (StarWorlds(i).x + StarWorlds(i).dx)
   if StarWorlds(i).x < -50 or StarWorlds(i).x > xmax + 50 then
     StarWorlds(i) = makeStarProperties
   end if
   StarWorlds(i).y = (StarWorlds(i).y + StarWorlds(i).dy)
   if StarWorlds(i).y < -50 or StarWorlds(i).y > ymax + 50 then
     StarWorlds(i) = makeStarProperties
   end if
 next
 showpage
 delay 10
wend


Attached Files Thumbnail(s)

B += x
Reply
#6
Actually I was counting on a parade but in a pinch...

Pete Big Grin
Reply
#7
At QB64.org, Bplus had asked me to convert his Fall Foilage demo into 3D one.
Here it is -
17. 3D Fall Foilage/Fractal Tree with leaves (or whatever you may call it)
Code:
'3D Fall Foilage or Fractal Tree with cubed leaves
'Made by Ashish, especially for Bplus.


_TITLE "3D Fall Foilage"
SCREEN _NEWIMAGE(800, 600, 32)
DECLARE LIBRARY
    SUB gluLookAt (BYVAL eyeX#, BYVAL eyeY#, BYVAL eyeZ#, BYVAL centerX#, BYVAL centerY#, BYVAL centerZ#, BYVAL upX#, BYVAL upY#, BYVAL upZ#)
    SUB glutSolidCube (BYVAL dsize AS DOUBLE)
END DECLARE

TYPE vec3
    x AS SINGLE
    y AS SINGLE
    z AS SINGLE
END TYPE

FOR y = 0 TO _HEIGHT
    COLOR _RGB(map(y, 0, _WIDTH, 0, 10), map(y, 0, _HEIGHT, 0, 180), 128)
    LINE (0, y)-(_WIDTH, y)
NEXT y

DIM SHARED glAllow AS _BYTE, VertexCount
_GLRENDER _ONTOP
COLOR _rgb(255,255,255), 1

glAllow = -1
_DELAY .2
DO
    IF NOT me THEN
        me = -1
        PRINT VertexCount; " Vertices are being rendered."
    END IF
    _LIMIT 40
LOOP

SUB _GL () STATIC
    IF NOT glAllow THEN EXIT SUB
    IF NOT glSetup THEN
        _glViewport 0, 0, _WIDTH, _HEIGHT
        aspect# = _WIDTH / _HEIGHT
    END IF
   
    _glMatrixMode _GL_PROJECTION
    _gluPerspective 45.0, aspect#, 1, 1000
   
    _glMatrixMode _GL_MODELVIEW
   
    _glEnable _GL_DEPTH_TEST
    _glEnable _GL_BLEND
   
    gluLookAt 0, 1.1, 4.9, 0, 0, 0, 0, 1, 0
    _glRotatef -clock# * 60, 0, 1, 0
   
    IF NOT glListGenerated THEN
        fractal_tree = _glGenLists(1)
        _glNewList fractal_tree, _GL_COMPILE
        _glTranslatef 0, 0, 0
        _glRotatef 180, 0, 0, 1
       
        _glLineWidth 10
        _glColor3f .6, .3, 0
        _glBegin _GL_LINES
        _glVertex3f 0, 0, 0
        _glVertex3f 0, 1.4, 0
        _glEnd
        drawTree3D 0, 0, 0, .76, 35, 35
       
        _glTranslatef 0, 1.4, 0
        _glColor3f 1, 1, 1
        drawGround3D
        _glEndList
        glListGenerated = -1
    END IF
    _glCallList fractal_tree
   
    _glFlush
    clock# = clock# + .01
END SUB

SUB drawTree3D (x, y, z, r, t1, t2)
    ' IF r < 0.4 THEN _glColor4f 0, .8, 0, 0.7 ELSE _glColor3f .6, .3, 0
    _glColor4f map(r, 0, 1, .8, .5), map(r, 0, 1, .5, .3), 0, .7

    _glLineWidth map(r, 0.8, 0.06, 10, 1)

    _glPushMatrix
    _glRotatef t1, 0, 0, 1
    _glBegin _GL_LINES
    _glVertex3f x, y, z
    _glVertex3f x, y - r, z
    _glEnd
    drawLeaf3D x, y - r, z
    _glPopMatrix
   
    _glColor4f map(r, 0, 1, .8, .5), map(r, 0, 1, .5, .3), 0, .7

    _glPushMatrix
    _glRotatef -t1, 0, 0, 1
    _glBegin _GL_LINES
    _glVertex3f x, y, z
    _glVertex3f x, y - r, z
    _glEnd
    drawLeaf3D x, y - r, z
    _glPopMatrix

    _glColor4f map(r, 0, 1, .8, .5), map(r, 0, 1, .5, .3), 0, .7
   
    _glPushMatrix
    _glRotatef t2, 1, 0, 0
    _glBegin _GL_LINES
    _glVertex3f x, y, z
    _glVertex3f x, y - r, z
    _glEnd
    drawLeaf3D x, y - r, z
    _glPopMatrix

    _glColor4f map(r, 0, 1, .8, .5), map(r, 0, 1, .5, .3), 0, .7
   
    _glPushMatrix
    _glRotatef -t2, 1, 0, 0
    _glBegin _GL_LINES
    _glVertex3f x, y, z
    _glVertex3f x, y - r, z
    _glEnd
    drawLeaf3D x, y - r, z
    _glPopMatrix

    VertexCount = VertexCount + 8

    IF r > 0.06 THEN
        _glPushMatrix
        _glRotatef t1, 0, 0, 1
        _glTranslatef x, y - r, z
        drawTree3D 0, 0, 0, r * 0.61, t1, t2
        _glPopMatrix

        _glPushMatrix
        _glRotatef -t1, 0, 0, 1
        _glTranslatef x, y - r, z
        drawTree3D 0, 0, 0, r * 0.61, t1, t2
        _glPopMatrix

        _glPushMatrix
        _glRotatef t2, 1, 0, 0
        _glTranslatef x, y - r, z
        drawTree3D 0, 0, 0, r * 0.61, t1, t2
        _glPopMatrix

        _glPushMatrix
        _glRotatef -t2, 1, 0, 0
        _glTranslatef x, y - r, z
        drawTree3D 0, 0, 0, r * 0.61, t1, t2
        _glPopMatrix

    END IF

END SUB

SUB drawLeaf3D (x, y, z)
    area = 0.2
    leafs = p5random(2, 3)
    FOR n = 1 TO leafs
        _glColor4f p5random(0.19, 0.98), p5random(0.1, 1), p5random(0, 0.16), 0.6
        _glPushMatrix
        _glTranslatef x + RND * area - RND * area, y + RND * area - RND * area, z + RND * area - RND * area
        glutSolidCube 0.001 + RND * .02
        _glPopMatrix
        VertexCount = VertexCount + 8
    NEXT
END SUB

SUB drawGround3D ()
    _glBegin _GL_TRIANGLES
    _glColor3f 0.27, 0.42, 0.11
    _glVertex3f -2, 0, -2
    _glColor3f 0.03, 0.31, 0.02
    _glVertex3f -2, 0, 2
    _glVertex3f 2, 0, -2
   
    _glColor3f 0.03, 0.31, 0.02
    _glVertex3f 2, 0, -2
    _glColor3f 0.27, 0.42, 0.11
    _glVertex3f 2, 0, 2
    _glColor3f 0.03, 0.31, 0.02
    _glVertex3f -2, 0, 2
    _glEnd
END SUB

'taken from a 2D rendering library, p5js.bas
'http://bit.ly/p5jsbas
FUNCTION map! (value!, minRange!, maxRange!, newMinRange!, newMaxRange!)
    map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!
END FUNCTION

FUNCTION p5random! (mn!, mx!)
    IF mn! > mx! THEN
        SWAP mn!, mx!
    END IF
    p5random! = RND * (mx! - mn!) + mn!
END FUNCTION


Attached Files Thumbnail(s)

Reply
#8
Hi Ashish, 

As I said at other forum "fabulous!" 

I am honored to see my name with the project.

I do have to report my Vertices Count is not changing from 0. I have tried copy /paste from here and .net and both versions stay at 0.
B += x
Reply
#9
Hi bplus! Smile
Try changing the delay length on line 28 for Vertices Count.
Please let me know if this was solved.
Reply
#10
(10-30-2017, 08:13 PM)KingAshish Wrote: Hi bplus! Smile
Try changing the delay length on line 28 for Vertices Count.
Please let me know if this was solved.

Yes! that was it. 

I guess I'm... er my machine is a little slow; I have that problem with _SCREENMOVE _MIDDLE also.

And now, another little problem, my vertices count is 393191 should it be the same as yours?

Sorry, I am trolling, a little trick I learned for Halloween.

If you are laughing now, that is my treat!

I do it all for Halloween, tricks plus treats!

Non of this "Either Or" stuff that Kierkegaad ex-spouses for me.

(But then again, I don't exist.)

OK I leaf now....
B += x
Reply
#11
If you ask me, he's a few trees short of a forest but who's counting.

Pete Big Grin
Reply