Drawing Circles with Radii: Difference between revisions

From Scribus Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
 
Line 9: Line 9:
<pre><nowiki>
<pre><nowiki>
#!/usr/bin/env python
#!/usr/bin/env python
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.


"""
"""

Latest revision as of 23:41, 9 December 2015

This article is part of the Scripts series.

This script arose from a query in the mailing list. It can form the basis of similar drawings.

Uses createLayer createLine newDocument saveDocAs setLineColor setLineWidth zoomDocument

300

#!/usr/bin/env python


# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.


"""
this script creates circles with radii. It can form the basis to other scripts, eg, add markers on one of the circles. Calls used in this script are;

createLayer
createLine
newDocument
saveDocAs
setLineColor
setLineWidth
zoomDocument
Python lists, range, for 
"""


from math import sin, cos, pi
try:
    from scribus import *
except ImportError,err:
    print "This Python script is written for the Scribus scripting interface."
    print "It can only be run from within Scribus."
    sys.exit(1)



myCircles = newDocument(PAPER_A4, (10, 10, 10, 10), LANDSCAPE, 1, UNIT_POINTS, NOFACINGPAGES, FIRSTPAGERIGHT, 1)

angleStep = pi * 2 / 360            # one degree increments

oX = []
oY = []
oZ = []
cX = []
cY = []
cZ = []
iX = []
iY = []
iZ = []

for a in range(0, 360):
   ox = sin(a * angleStep) * 1.1 * 250         # Outer ring "x" coordinates
   oy = cos(a * angleStep) * 1.1 * 250         # Outer ring "y" coordinates 
   cx = sin(a * angleStep) * 250        # Center ring
   cy = cos(a * angleStep) * 250
   ix = sin(a * angleStep) * 0.9 * 250        # Inner ring
   iy = cos(a * angleStep) * 0.9 * 250 

   oX.append(ox)                # Make a list of all the co-ordinates
   oY.append(oy) 
   oZ.append(ox)                # Place the x coordinate in oZ
   oZ.append(oy)                 # Place the y coordinate in oZ
   cX.append(cx)
   cY.append(cy)
   cZ.append(cx)
   cZ.append(cy)
   iX.append(ix)
   iY.append(iy)
   iZ.append(ix)
   iZ.append(iy)

# This is Landscape, so now move the circle to the center of the page.

for x in range(0,720,2):

    oZ[x] = oZ[x] + 841.89/2            # Every odd element has 841.89/2 added to it
    oZ[x+1] = oZ[x + 1] + 595.28/2        # Every even element has 595.28 added
    cZ[x] = cZ[x] + 841.89/2
    cZ[x+1] = cZ[x + 1] + 595.28/2
    iZ[x] = iZ[x] + 841.89/2
    iZ[x+1] = iZ[x + 1] + 595.28/2

oCircle = createPolygon(oZ)            # Draw the outer circle
setLineWidth(2, oCircle)

createLayer("innerLayer")            # To draw the inner circle
createLayer("centerLayer")            # To draw the center circle
createLayer("outerLines")            # To draw lines from the center to to outer circle

setActiveLayer("centerLayer")
cCircle = createPolygon(cZ)            # Draw the center circle
setLineWidth(0.5, cCircle)

setActiveLayer("innerLayer")    
iCircle = createPolygon(iZ)            # Draw the inner circle
setLineWidth(0.5, iCircle)

setActiveLayer("outerLines")
for x in range(0,720,24):            # Draw the lines
   line = createLine(841.89/2,595.28/2,oZ[x],oZ[x+1])
   setLineWidth(8, line)
   setLineColor("Blue", line)

zoomDocument(60.0)                # So it fits my screen
saveDocAs("circles.sla")             #Make sure this is writable