Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/show_angles.py
blob: 4352930e90982f0801b02b8c1947ef302b878366 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# Copyright 2007 Mitchell N. Charity
# Copyright 2009 Walter Bender
#
# This file is part of Ruler.
#
# Ruler 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 3 of the License, or
# (at your option) any later version.
#
# Ruler is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ruler.  If not, see <http://www.gnu.org/licenses/>

from __future__ import division
import cairo
from util import mm
from util import set_background_color
from util import set_color
from math import pi,sin,cos

from colorsys import * #XXX

def d2r(d):
    return d/180*pi

class Angles90():
    def __init__(self,font,font_bold,w,h):
        self.font = font
        self.font_bold = font_bold
        self.w = w
        self.h = h

    def draw(self,c,dpi):
        set_background_color(c,self.w,self.h)

        c.set_antialias(True)

        ox = mm(dpi,0)
        oy = mm(dpi,99)
        d = mm(dpi,90)
        def xy(angle,m=d):
            return cos(-angle)*m+ox,sin(-angle)*m+oy
        def ray(angle,r0=0,r1=d):
            c.move_to(*xy(angle,r0))
            c.line_to(*xy(angle,r1))

        lw = 6
        c.set_line_width(lw)
        c.move_to(ox,oy+lw/2)
        c.line_to(*xy(pi/2))
        ray(0)
        c.stroke()

        c.save()
        c.set_line_width(3)
        c.set_dash([mm(dpi,5)])
        ray(pi/4)
        c.stroke()
        c.restore()

        c.set_line_width(4)
        for a in range(10,81,10):
            ray(d2r(a),mm(dpi,10),mm(dpi,85))
        c.stroke()
        c.set_line_width(2)
        for a in range(10,81,10):
            ray(d2r(a),mm(dpi,3),mm(dpi,20))
        c.stroke()

        c.set_line_width(2)
        for a in range(1,90,1):
            ray(d2r(a),mm(dpi,70),mm(dpi,80))
        c.stroke()
        c.set_line_width(2)
        for a in range(0,90,5):
            ray(d2r(a),mm(dpi,20),mm(dpi,81))
        c.stroke()

class Angles360():
    def __init__(self,font,font_bold,w,h):
        self.font = font
        self.font_bold = font_bold
        self.w = w
        self.h = h

    def draw(self,c,dpi):
        set_background_color(c,self.w,self.h)
        c.set_antialias(True)

        ox = mm(dpi,75)
        oy = mm(dpi,50)
        d = mm(dpi,44)
        def xy(angle,m=d):
            return cos(-angle)*m+ox,sin(-angle)*m+oy
        def ray(angle,r0=0,r1=d):
            c.move_to(*xy(angle,r0))
            c.line_to(*xy(angle,r1))
        def annulus(a0,a1,r0,r1):
            c.move_to(*xy(a0,r0))
            c.arc_to(ox,oy,r0,a0,a1)
            c.rel_line_to(*xy(a1,r1))
            c.arc_to(ox,oy,r1,a1,a0)
            c.close_path()

        def rays(step,r0=0,r1=d,w=1):
            c.save()
            c.set_line_width(w)
            for a in range(0,360,step):
                ray(d2r(a),r0,r1)
            c.stroke()
            c.restore()

        rays(1,mm(dpi,35),w=2,r1=mm(dpi,43))
        rays(5,mm(dpi,10),w=2)
        rays(10,mm(dpi,10),w=4)
#        rays(10,mm(dpi,3),mm(dpi,20),w=2)
        c.save()
        #c.set_dash([mm(dpi,5)])
        set_color(c,'dark gray')
        rays(45,0,mm(dpi,45),w=6)
        c.restore()
        rays(90,0,mm(dpi,45),w=6)