473,382 Members | 1,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

svg in python(fractal systems)

Expand|Select|Wrap|Line Numbers
  1. [python]
  2. import math
  3.  
  4. start = "+++++++++++++X"
  5. iterations = 7 # how many iterations to do
  6. delta = 1.5
  7. # Start: X
  8. # Rules:
  9. # X --> F[T+++++++++X]-F[S-----------!X]RX
  10.  
  11.  
  12.  
  13. def generate(l):
  14.     r="" 
  15.     for x in l: # Go through the list of actions, expand according to rules above
  16.         if x == 'F':
  17.             r = r + "FF"
  18.         elif x == 'X':
  19.             r = r + "F[T+++++++++X]-F[S-----------!X]RX"
  20.  
  21.         else:
  22.             r =  r + x # Copy character over, no expansion
  23.     return r
  24.  
  25.  
  26.  
  27.  
  28. def Draw(f,s):
  29.     cur_angle = math.radians(360) # Start angle in radians -- looks best if we start at 90degrees
  30.     angle = math.radians(7.2) # we turn left or right by this angle
  31.     store = [] # For saving the current position 
  32.     pos = (400,400) # Start position (in 2D plane)
  33.     delta = 1.5
  34.     for c in s:
  35.         if c == 'F': # means draw forward, number of units
  36.             x,y = pos
  37.             # compute new position
  38.             newx,newy = x + delta*math.cos(cur_angle), y + delta*math.sin(cur_angle)
  39.             # draw the line
  40.             f.write('<line x1="%.2f"  y1="%.2f" x2="%.2f" y2="%.2f" />\n' % (x,y,newx,newy))
  41.             pos = (newx,newy) # We move to new position
  42.  
  43.     elif c == 'T':
  44.         delta*0.5
  45.     elif c == 'S':
  46.         delta*0.4
  47.     elif c == 'R':
  48.         delta*0.6
  49.     elif c == '!':
  50.         if c == '-':
  51.             cur_angle-=angle
  52.         if c == '+':
  53.             cur_angle+=angle
  54.         elif c == '-':
  55.             cur_angle += angle 
  56.         elif c == '+':
  57.             cur_angle -= angle 
  58.         elif c == '[': # means save current position
  59.             store.append((pos,cur_angle))
  60.         elif c == ']': # get back last saved position, angle
  61.             pos,cur_angle = store.pop()
  62.         else: # Ignore all others (as per spec)
  63.             pass
  64.  
  65.  
  66. # Now starts the program proper 
  67. end = start
  68. for i in range(0,iterations):
  69.     end = generate(end)
  70.  
  71.  
  72. f = open("tumble weed.svg", "w")
  73.  
  74. #Print SVG preamble
  75. f.write("<?xml version='1.0'?>\n")
  76. f.write("<svg xmlns='http://www.w3.org/2000/svg'>\n")
  77. f.write("<g id=\"x\" stroke=\"blue\">\n")
  78.  
  79. Draw(f,end) # Draw the image
  80. f.write("</g>\n</svg>\n")
  81. f.close()
This is code to draw tumble weed in svg using python, it doesn't produce the right result, how can it be modified
May 3 '10 #1
3 2302
Glenton
391 Expert 256MB
You're kidding, right?!
May 4 '10 #2
No, it does not produce the right result
May 4 '10 #3
Glenton
391 Expert 256MB
I mean, are you seriously expecting us to help you with so little information? What's it meant to produce? What's it's producing? I'm afraid I can't read your mind.
May 10 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: louis | last post by:
For those in the DFW area, there's an IT open house at Perot Systems. (In my group, we're looking to hire one senior sql server DBA. Go to the perot systems web site to apply). ...
0
by: avinash | last post by:
EIGHTEENTH INTERNATIONAL CONFERENCE ON SYSTEMS ENGINEERING (ICSEng05) LAS VEGAS, USA, AUGUST 16-18, 2005 (http://www.icseng.info) This series of International Conferences is jointly organized...
0
by: Emine Ekin | last post by:
/*Apologize for multiple posts*/ FIRST CALL FOR PAPERS ADVIS 2006 Fourth Biennial International Conference on Advances in Information Systems 18-20 October, 2006 Izmir, Turkey
0
by: Bill Law | last post by:
Great Company on the Maryland Eastern Shore needs a DB2 Systems Programmer and DBA (DB2) to join their IT team. The selected candidate MUST have a BS degree and both DB2 DBA And DB2 Systems...
12
by: Bill Hanna | last post by:
C is inadequate for embedded systems for the following reasons: 1) Direct addressing of memory mapped I/O is not supported simply and easily. You have to find work-arounds that are compiler...
3
by: user | last post by:
Hi all, At the outset, I regret having to post this slightly OT post here. However, I strongly feel that people in this group would be the best to advise me on my predicament. I am working as...
54
by: Matt | last post by:
How do we define systems programs? when we say systems programming, does it necessary mean that the programs we write need to interact with hardware directly? For example, OS, compiler, kernel,...
20
by: Jack | last post by:
Is there a Python packaging that is specifically for embedded systems? ie, very small and configurable so the user gets to select what modules to install? For Linux-based embedded systems in...
0
by: Sabri.Pllana | last post by:
We apologize if you receive multiple copies of this call for papers. *********************************************************************** 2008 International Workshop on Multi-Core Computing...
3
by: Ty Oft | last post by:
Hello Bytes! Maybe my question seems a bit silly (as one could simply answer it "Well, what are you more passionate about?" or stuff like that - please don't answer like this), but I am in a bit...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.