Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

rudimentary Christmas tree

 [1/2] from: antonr:lexicon at: 1-Jan-2005 1:57


Look I know it's a bit late... but I haven't been all that well the last two weeks, and I moved house and stuff... rebol [ Title: "Christmas tree AGG" File: %Christmas-tree-AGG.r Date: 31-Dec-2004 Version: 1.0.0 Needs: [View] Author: "Anton Rolls" Language: 'English Purpose: {Display a christmas tree using AGG Draw dialect} Usage: {} ToDo: { - collect all the draw commands in one block and draw all at once - can then perform global transforms - colour gradients - star on top, presents at the bottom :) sparkles, baubles and snow } History: [ 1.0.0 [31-Dec-2004 {First version} "Anton"] ] Notes: {} ] ; taken from library/trigonometry.r angle: func ["calculate angle given x and y - returns positive angles in degrees" x y /local a ][ a: either x = 0 [either y < 0 [270][90]][ arctangent y / x ] ; left of centre? arctangent won't be quite right then. if x < 0 [a: a + 180] ; this should fix "quirkiness" return (a + 720) // 360 ] draw-branch: func [ image [image!] start [pair!] grow [pair!] n [integer!] /locals base left right top colour fill-colour ang dang dist curve rcurve code ][ if n > 0 [ ;print [n start] base: (-1x1 * reverse grow) * 0.05 ; 5% perpendicular of growth direction left: start - base right: start + base top: start + grow colour: green fill-colour: leaf draw image [ line-width 1 pen colour fill-pen fill-colour polygon left right top ] ; recurse ;left: 1x-1 * reverse grow ; simple 90 degree turn ;right: -1x1 * reverse grow ; simple 90 degree turn ; arbitrary angle turns ang: angle grow/x grow/y ;dist2: grow * grow ;dist: square-root dist2/x + dist2/y dist: square-root ((grow/x * grow/x) + (grow/y * grow/y)) code: copy [] repeat i 9 [ dang: i + 1 * -2 + 90 left: as-pair dist * cosine (ang + dang) dist * sine (ang + dang) right: as-pair dist * cosine (ang - dang) dist * sine (ang - dang) curve: square-root (i * 0.1) rcurve: (1 - square-root (i * 0.1)) * 0.7 append code reduce [ 'draw-branch image (grow * curve + start) (left * rcurve) (n - 1) 'draw-branch image (grow * curve + start) (right * rcurve) (n - 1) ] ] do code ] ] img: make image! 400x400 draw-branch img 200x370 0x-360 3 view center-face layout [image img]

 [2/2] from: alanore::comcast::net at: 31-Dec-2004 15:43


At 06:57 AM 12/31/2004, Anton wrote: tried and got this: ** Syntax Error: Invalid string -- "calculate angle given x and y - returns positive angles in ** Near: (line 25) angle: func ["calculate angle given x and y - returns pos itive angles in