Thrive Game Development
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Thrive Game Development

Development of the evolution game Thrive.
 
HomeHome  PortalPortal  Latest imagesLatest images  SearchSearch  RegisterRegister  Log inLog in  
Welcome new and returning members!
If you're new, read around a bit before you post: the odds are we've already covered your suggestion.
If you want to join the development team, sign up and tell us why.
ADMIN is pleased to note that this marquee has finally been updated.
ADMIN reminds you that the Devblog is REQUIRED reading.
Currently: The Microbe Stage GUI is under heavy development
Log in
Username:
Password:
Log in automatically: 
:: I forgot my password
Quick Links
Website
/r/thrive
GitHub
FAQs
Wiki
New Posts
Search
 
 

Display results as :
 
Rechercher Advanced Search
Statistics
We have 1675 registered users
The newest registered user is dejo123

Our users have posted a total of 30851 messages in 1411 subjects
Who is online?
In total there are 5 users online :: 0 Registered, 0 Hidden and 5 Guests

None

Most users ever online was 443 on Sun Mar 17, 2013 5:41 pm
Latest topics
» THIS FORUM IS NOW OBSOLETE
Proceedural Tree Generator Emptyby NickTheNick Sat Sep 26, 2015 10:26 pm

» To all the people who come here looking for thrive.
Proceedural Tree Generator Emptyby NickTheNick Sat Sep 26, 2015 10:22 pm

» Build Error Code::Blocks / CMake
Proceedural Tree Generator Emptyby crovea Tue Jul 28, 2015 5:28 pm

» Hello! I can translate in japanese
Proceedural Tree Generator Emptyby tjwhale Thu Jul 02, 2015 7:23 pm

» On Leave (Offline thread)
Proceedural Tree Generator Emptyby NickTheNick Wed Jul 01, 2015 12:20 am

» Devblog #14: A Brave New Forum
Proceedural Tree Generator Emptyby NickTheNick Mon Jun 29, 2015 4:49 am

» Application for Programmer
Proceedural Tree Generator Emptyby crovea Fri Jun 26, 2015 11:14 am

» Re-Reapplication
Proceedural Tree Generator Emptyby The Creator Thu Jun 25, 2015 10:57 pm

» Application (programming)
Proceedural Tree Generator Emptyby crovea Tue Jun 23, 2015 8:00 am

» Achieving Sapience
Proceedural Tree Generator Emptyby MitochondriaBox Sun Jun 21, 2015 7:03 pm

» Microbe Stage GDD
Proceedural Tree Generator Emptyby tjwhale Sat Jun 20, 2015 3:44 pm

» Application for Programmer/ Theorist
Proceedural Tree Generator Emptyby tjwhale Wed Jun 17, 2015 9:56 am

» Application for a 3D Modeler.
Proceedural Tree Generator Emptyby Kaiju4u Wed Jun 10, 2015 11:16 am

» Presentation
Proceedural Tree Generator Emptyby Othithu Tue Jun 02, 2015 10:38 am

» Application of Sorts
Proceedural Tree Generator Emptyby crovea Sun May 31, 2015 5:06 pm

» want to contribute
Proceedural Tree Generator Emptyby Renzope Sun May 31, 2015 12:58 pm

» Music List Thread (Post New Themes Here)
Proceedural Tree Generator Emptyby Oliveriver Thu May 28, 2015 1:06 pm

» Application: English-Spanish translator
Proceedural Tree Generator Emptyby Renzope Tue May 26, 2015 1:53 pm

» Want to be promoter or project manager
Proceedural Tree Generator Emptyby TheBudderBros Sun May 24, 2015 9:00 pm

» A new round of Forum Revamps!
Proceedural Tree Generator Emptyby Oliveriver Wed May 20, 2015 11:32 am


 

 Proceedural Tree Generator

Go down 
3 posters
AuthorMessage
tjwhale
Theorist
tjwhale


Posts : 87
Reputation : 26
Join date : 2014-09-07

Proceedural Tree Generator Empty
PostSubject: Proceedural Tree Generator   Proceedural Tree Generator EmptySat Feb 21, 2015 11:51 am

This is not much help for this stage but I made a proceedural tree generator for a friend and it could be useful to Thrive.




I'll also put it in the prototypes subfolder of the git.

Code:


import pygame
import math
import random
from pygame.locals import *

#setup

background_colour = (255,255,255)
(width, height) = (1600, 800)

screen = pygame.display.set_mode((width, height))#,pygame.FULLSCREEN)
screen.fill(background_colour)
pygame.display.set_caption('Trees')
pygame.font.init()

myfont = pygame.font.SysFont("monospace", 20)

#base variables
junctions_per_branch = 3
base_length = 200
reduction_factor = 0.75
angle_change = math.pi/4
max_generation = 7

#where to center the display
X_shift = width/2
Y_shift = height

trunk_colour = (160,82,45)
leaf_colour = (34,139,34)

class branch:
   def __init__(self, junction = None):
      #if this branch is the trunk
      self.start_x = 0
      self.start_y = 0
      self.start_z = 0
      self.end_x = 0
      self.end_y = 0
      self.end_z = base_length
      self.generation = 1
      self.length = base_length
      self.phi = 0
      self.theta = 0
      self.number_of_children = 0

      #if this branch is coming off a junction
      if junction:
         self.generation = junction.generation + 1
         self.length = base_length*(reduction_factor**self.generation)
         self.theta = junction.theta + random.uniform(-angle_change, + angle_change)
         self.phi = junction.phi + random.uniform(-angle_change, + angle_change)
         self.start_x = junction.x
         self.start_y = junction.y
         self.start_z = junction.z
         self.end_x = self.start_x +  self.length*math.sin(self.theta)*math.cos(self.phi)
         self.end_y = self.start_y +  self.length*math.sin(self.theta)*math.sin(self.phi)
         self.end_z = self.start_z +  self.length*math.cos(self.theta)
         self.number_of_children = 0
         


   def display(self, rotation):
      screen_x_0 = math.cos(rotation)*self.start_x + math.sin(rotation)*self.start_y
      screen_x_1 = math.sin(rotation)*self.end_y + math.cos(rotation)*self.end_x
      pygame.draw.line(screen, trunk_colour, [int(screen_x_0 + X_shift), int(-self.start_z + Y_shift)],
         [int(screen_x_1 + X_shift),int(- self.end_z + Y_shift)], int(20*(reduction_factor**self.generation)))


# a place where one brach comes off another
class junction:
   def __init__(self, branch):
      self.generation = branch.generation
      self.theta = branch.theta
      self.phi = branch.phi
      step = 1.0/junctions_per_branch

      self.x = branch.end_x + step*branch.number_of_children*(branch.start_x - branch.end_x)
      self.y = branch.end_y + step*branch.number_of_children*(branch.start_y - branch.end_y)
      self.z = branch.end_z + step*branch.number_of_children*(branch.start_z - branch.end_z)

      branch.number_of_children += 1

class leaf:
   def __init__(self, junction):
      self.x = junction.x
      self.y = junction.y
      self.z = junction.z

   def display(self, rotation):
      screen_x_0 = math.cos(rotation)*self.x + math.sin(rotation)*self.y
      pygame.draw.circle(screen, leaf_colour, (int(screen_x_0 + X_shift), int(-self.z + Y_shift)),5)



def mainloop():
   global branches
   global leaves
   branches = []
   junctions = []

   branches.append(branch())

   current_generation = 1

   while current_generation <=  max_generation:
      #for every junction add a branch
      for i in junctions:
         branches.append(branch(i))
      junctions = []

      #for each branch keep adding junctions until they all have the right number
      repeat = True
      while repeat:
         found_one = False
         for i in branches:
            if i. generation == current_generation and i.number_of_children <= junctions_per_branch - 1:
               junctions.append(junction(i))
               found_one = True
         if not found_one:
            repeat = False

      current_generation += 1

   leaves = []

   for i in junctions:
      leaves.append(leaf(i))



   


mainloop()

running = True
while running:
   for event in pygame.event.get():
       if event.type == pygame.QUIT:
           running = False
       elif event.type == KEYDOWN:
           if event.key == K_ESCAPE:
               running = False
           if event.key == K_SPACE:
              mainloop()

   screen.fill(background_colour)

   pos = pygame.mouse.get_pos()
   rotation = float(pos[0])/300

   for i in branches:
      i.display(rotation)
   for i in leaves:
      i.display(rotation)

   pygame.display.flip()
   

pygame.quit()

Back to top Go down
MitochondriaBox
Learner
MitochondriaBox


Posts : 188
Reputation : 7
Join date : 2013-01-29
Age : 24
Location : Houston, Texas

Proceedural Tree Generator Empty
PostSubject: Re: Proceedural Tree Generator   Proceedural Tree Generator EmptySat Feb 21, 2015 2:20 pm

Neat! It might not work for Thrive if plants will be alive (heh rhymes), since the player's supposed to have the chance to actually play as them if they take that direction in the Multicellular Stage. Then again, this COULD be applied to them growing, since not all the player's plants'll turn out the same, with evolution limited to certain parameters (general shape, etc.). Stats could be attached to them and have the organism procedurally change accordingly. I dunnno.

What was your buddy working on?
Back to top Go down
tjwhale
Theorist
tjwhale


Posts : 87
Reputation : 26
Join date : 2014-09-07

Proceedural Tree Generator Empty
PostSubject: Re: Proceedural Tree Generator   Proceedural Tree Generator EmptySat Feb 21, 2015 2:56 pm


I think the game will look very different if you are playing as a tree. This prototype is more like a tiny step towards being able to procedurally generate a landscape for your animal to wander around in. We're going to need whole forests of different trees.

He's working on a game, I can't really say too much about it but suffice to say your dragons can get shot down by Tesla coils, so it's going to be awesome and crazy.
Back to top Go down
tjwhale
Theorist
tjwhale


Posts : 87
Reputation : 26
Join date : 2014-09-07

Proceedural Tree Generator Empty
PostSubject: Re: Proceedural Tree Generator   Proceedural Tree Generator EmptySat Feb 21, 2015 3:54 pm

Managed to get a couple of different types of  tree. It's a bit of a struggle to get it to do certain things but hopefully it should be possible to get some good variety going.

Spoiler:
Back to top Go down
crovea
Programming Team lead
crovea


Posts : 310
Reputation : 59
Join date : 2013-10-07
Age : 34
Location : Denmark

Proceedural Tree Generator Empty
PostSubject: Re: Proceedural Tree Generator   Proceedural Tree Generator EmptySat Feb 21, 2015 8:41 pm

I can think of ways this can become useful in the future!
Back to top Go down
Sponsored content





Proceedural Tree Generator Empty
PostSubject: Re: Proceedural Tree Generator   Proceedural Tree Generator Empty

Back to top Go down
 
Proceedural Tree Generator
Back to top 
Page 1 of 1
 Similar topics
-
» Tree / Photosynthesizer gameplay prototype
» Simple language generator (v1.01)
» Galaxy generator, models and systems.
» Evolution tree
» My Evolution System Concept

Permissions in this forum:You cannot reply to topics in this forum
Thrive Game Development :: Development :: Design :: Prototypes-
Jump to: