Challenge #26 - Christmas / New Years Scene generation

Started by kevin, December 22, 2012, 03:16:05 PM

Previous topic - Next topic

kevin





Challenge #26 - Christmas / New Years Scene generation


   It's well and truly that time of season again, so in keeping with the season let's make a programming challenge out of it.  This time you're challenged to create a Christmas or News Years scene purely out of code.    So the trick here,  is you're going to have to procedural generate the graphics in the scene, you can't use any media.  

  The scene you create can be either animated or static, no difference.   The subject matter can be pretty much anything, a  Christmas scene might show a Tree with lights, Santa, Presents,  Snow Man / Snow scene .....  Where a New years scene is probably going to be a fireworks show or something.. But think outside the box and see what you come up with.


    As always we'll award   Extra Brownie points to the most creative submissions .



Submission

 * Submissions can be written in any version of PlayBASIC
 
 * Submission can only be accepted in Source Code form only.

 * No external media is permitted for this challenge.

 * Zip up your Submissions and please try to keep it smaller than 500K !

 * Authors automatically give consent for their submission(s) to distributed and used for promotional purposes via UnderwareDesign.com, PlayBasic.com code tank.

 * Authors can submit as many times as they like.

 * To make a submission, zip up your projects and either post it in this thread, or create your own thread in either the Source Codes or Show Case forums and post a link bellow.



Dead Line

    Anytime before the next ice age



Prizes

    * The best submissions will be periodically highlighted through the PlayBasic IDE news service/News Letters/ FaceBook,  Twitter or the PlayBASIC youtube channel.



Sigtrygg

Merry christmas, all together!

Here is my programm for the competition.
A small programm for creating snowflakes.
Have fun to change parameters for flakes.

Sigtrygg

PlayBASIC Code: [Select]
; PROJECT : SnowFlake
; AUTHOR : Sigtrygg
; CREATED : 12/26/2012
; EDITED : 12/26/2012
; ---------------------------------------------------------------------

//==============================================================================
//============================== SNOWFLAKE-PROGRAMM=============================
//==============================================================================

// Have fun to make experiments with changing parameters!!!



r=300; Radius
x=100; start x, center of image
y=300; start y, center of image


Do

CreateImage 1,200,600,2;size of image = 200x600
RenderToImage 1

Ink RGB (Rnd(255),Rnd(255),Rnd(255))
Line x,y,x,y-r
t=RndRange (1,100);distance of first feather from center
distance=RndRange(1,50);distance between feathers

For u= t To 300 Step distance
Ink RGB (Rnd(255),Rnd(255),Rnd(255))
i=RndRange (5,80);Lenght of feather
Line x,y-u,x+1.333*i,y-u-i;make lines in angles of 60 degree
Line x,y-u,x-1.333*i,y-u-i
Next u

RenderToScreen
CreateSprite 1
SpriteImage 1,1
SpriteHandle 1,-100,-300
SpriteDrawMode 1,2

For t=1 To 5
CopySprite 1,t+1
TurnSprite t+1,t*60
PositionSprite t,GetScreenWidth()/2,GetScreenHeight()/2
Next t

DrawAllSprites

Sync

;waitkey
Wait 1000

Cls

Loop



kevin

  This function draws a chunky pine Christmas tree without decorations.  


PlayBASIC Code: [Select]
   Draw_Xmas_Tree(400,300,200,300)   

Sync
WaitKey


Function Draw_Xmas_Tree(xpos,ypos,width,Height)

; 90 % of it's height is branches
Top =Ypos-Height
Bottom =top+(Height*0.90)

; scaler between width and height
WidthScaler#=Width/float(Height)

BranchSize#=2.3

x2=xpos
y2=ypos+top

c2=$20a800
c1=rgbfade(c2,80)


lp#=top
while lp#<=Bottom

Dist# =lp#-top
BranchWidth# =Dist#*WidthScaler#

x1=xpos
y1=ypos+Dist#

; draw the left and right fragments
gouraudtri x2-BranchWidth#,y1,c2,x1,y1,c1,x2,y2, c2
gouraudtri x2+BranchWidth#,y1,c2,x1,y1,c1,x2,y2, c2

lp#+=BranchSize#
BranchSize#+=1.5
x2=x1
y2=y1

endwhile

; draw trunk
y2=Ypos+Height

Size#=width*0.05
x1=xpos-size#
x2=xpos+size#

c1=$915700
c2=$714700
shadebox x1,y1,x2,y2,c1,c2,c2,c1


EndFunction






  This version draws something of a perspective forest of pine trees

PlayBASIC Code: [Select]
   setfps 60

global ProjectionX#=200
global ProjectionY#=200

MaxDepth =2000
Trees =150

Type tTree
x#
y#
Width#
Height#
DEpth#

EndType

Dim tree(trees) as tTree

depth#=MaxDepth
depthstep#=float(MaxDepth)/Trees
For lp =1 to Trees
inittree(lp,depth#)
depth#-=Depthstep#
next



Cam=NewCamera()

cameracls cam,off

SceneCacheSize 1024*1024

speed#=4

Do

cls


capturetoscene
clsscene
For lp =1 to Trees
Tree(lp).depth-=Speed#

if Tree(lp).depth<50
inittree(lp,maxdepth)
endif

capturedepth Tree(lp).depth

DrawTree(lp)


next
drawcamera cam

sync

loop






Function DrawTree(lp)

depth#=Tree(lp).depth
width#=Tree(lp).Width/2
Height#=Tree(lp).Height

x1#=Tree(lp).x-Width#
x2#=Tree(lp).x+Width#

y1#=Tree(lp).y-Height#
y2#=Tree(lp).y


; convert 3d space to 2d space

Screenx1# =(ProjectionX#*X1#)/depth#
ScreenY1# =(ProjectionY#*y1#)/depth#
Screenx2# =(ProjectionX#*X2#)/depth#
ScreenY2# =(ProjectionY#*y2#)/depth#

; center in screen
ScreenX1#+=400
ScreenX2#+=400

ScreenY1#+=300
ScreenY2#+=300


x=(SCreenX2#+ScreenX1#)/2
y=(SCreenY2#)
W=(SCreenX2#-ScreenX1#)
H=(SCreenY2#-ScreenY1#)

Draw_Xmas_Tree(x,y,w,H)



EndFunction


Psub InitTree(lp,depth#)

Width=rndrange(100,250)
Height=rndrange(400,600)

Tree(lp).x =rndrange(-2000,2000)
Tree(lp).y =0
Tree(lp).Width =Width
Tree(lp).Height=Height

Tree(lp).depth=depth#

EndPsub


Function Draw_Xmas_Tree(xpos,ypos,width,Height)


; 90 % of it's height is branches
Top =Ypos-Height
Bottom# =top+(Height*0.90)

; scaler between width and height
WidthScaler#=Width/float(Height)

BranchCount =15

BranchSize#=(Height*0.80)/BranchCount

x2=xpos
y2=ypos+top

c2=$20a800
c1=rgbfade(c2,80)


lp#=top
for Branch=1 to BranchCount
Dist# =lp#-top
BranchWidth# =Dist#*WidthScaler#
Login required to view complete source code