header

 

More links

AutoHotkey | Android | Arduino | COMM140Fractals | Grammar Checkers | Knots | A Million Dots Activity |  Processing | Processing for Scratch Users | Redbubble | Tutorials | Weather | World Time Meeting Planner | Favicon Generator.

Home > Tutorials > Processing > Processing Examples > Evolution of Xanthoria 001 > Evolution of Xanthorrhoea 001_4

Evolution of Xanthorrhoea 001_4

 

2010-10-20_0546.png

Comments:

Added a fower stem and head as well as the ability to change colour of tree
Note the stem should be drawn from the center of the top of the trunk this is still not quite right.

 

processing code

// Author: Rupert Russell
// Title: xanthorrhoea 001.4
// Date: October 21, 2010

  
// global vairables
  float min_x1 = 0;
  float max_x2 = 0;
  float center_of_trunk;

void setup() {
  size(300, 300);
  smooth();
  noLoop(); 
}  // end of viod setup

void draw() {
  
  int trunk_width;
  int trunk_height;
  float lean;
  int start_x;
  int start_y;
  int colour;

  // draw first trunk

  trunk_width = 25;
  trunk_height = 150;
  lean = 0;
  start_x = width /4;
  start_y = height - 20;
  colour = 60;
  xanthorrhoea(trunk_width, trunk_height, lean, start_x, start_y, colour);    
  
  // draw second trunk
  trunk_width = 24;
  trunk_height = 170;
  lean = -0.1;
  start_x = width /2;
  start_y = height;
  colour = 110;
  xanthorrhoea(trunk_width, trunk_height, lean, start_x, start_y, colour);   
  
} // end void draw()
   

void xanthorrhoea(int trunk_width, int trunk_height, float lean, int start_x, int start_y, int colour){
   
  // draw trunk
  float step = 0.5;
  float x1;
  float y1;
  float x2;
  float y2;
  float y_stem;
  float x_stem;


  for (int counter = 0; counter < trunk_height; counter ++){
    
    // generate random values for trunk
    stroke(colour);
    strokeWeight(random(0.2, 2));
    float rand_y = random(0.2, 5);
    float rand_x = random(10);
    x1 = start_x + rand_x + (lean * counter);   // apply a lean to the trunk
    y1 = start_y - (step * counter) - rand_y;
    x2 = start_x + trunk_width + rand_x + (lean * counter);  // slightly random trunk width
    y2 = start_y - (step * counter) - rand_y * 2;
    line(x1, y1, x2, y2);
    center_of_trunk = (x2 - x1) / 2 + x1;  // center_of_trunk is a global variable used to position the flower stem
  } // end of for loop


  // draw flower stem
  y_stem = start_y - (step * trunk_height);

  
  // flower stem
  x_stem = center_of_trunk;
  for (int count = 0; count < 90; count ++) {
    x_stem = x_stem + random(-1, 1);
    if(count < 50 ){
      //draw stem
      strokeWeight(2);
    }
    else{
      //draw flower head
      strokeWeight(4);
    }
      point(x_stem, y_stem - count);
  }
  
  

} // end of viod xanthorrhoea
code formatter

APA citation:
Russell, R. (2016, July 05, 07:26 am). Evolution of Xanthorrhoea 001_4.
     Retrieved December 23, 2024, from http://www.rupert.id.au/tutorials/processing/examples/xanthorrea001/001_4.php

Last refreshed: December 23 2024. 01:37.54 am

rupert dot russell at acu dot edu dot au Support Wikipedia

Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License.


2383 visits since October 21, 2010