GradientDemo.py :  » Ajax » pyjamas » src » examples » gwtcanvas » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Ajax » pyjamas 
pyjamas » src » examples » gwtcanvas » GradientDemo.py
"""
* Copyright 2008 Google Inc.
* Copyright (C) 2009 Luke Kenneth Casson Leighton <lkcl@lkcl.net>
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http:#www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
"""


from pyjamas.ui.Composite import Composite
from pyjamas.ui.HTML import HTML
from pyjamas.ui.VerticalPanel import VerticalPanel

from pyjamas.Canvas.Color import Color


from SimpleCanvasDemo import SimpleCanvasDemo

class GradientDemoControls (Composite):
    def __init__(self):
        layout = VerticalPanel()
        layout.add(HTML(
        "<b style=\"color:#f00;\">Gradients currently not working correctly in IE. Contributor assistance welcome :).</b>"))
        Composite.__init__(self, layout)
    


"""*
* Simple Demo of gradient fills and strokes.
"""
class GradientDemo (SimpleCanvasDemo):
    
    def __init__(self, theCanvas):
        SimpleCanvasDemo.__init__(self, theCanvas)

        self.width = 400
        self.height = 400
        self.demoName = "Gradients"
    
    
    def createControls(self):
        self.controls = GradientDemoControls()
    
    
    def drawDemo(self):
        self.canvas.resize(self.width, self.height)
        
        # DRAW SOME LINEAR GRADIENTS
        # Demos ported from Mozilla Development Center Canvas Tutorial
        self.canvas.saveContext()
        
        # Create gradients
        lingrad = self.canvas.createLinearGradient(0, 0, 0, 150)
        lingrad.addColorStop(0.0, Color("#00ABEB"))
        lingrad.addColorStop(0.5, Color("#fff"))
        lingrad.addColorStop(0.5, Color("#26C000"))
        lingrad.addColorStop(1, Color("#fff"))
        
        lingrad2 = self.canvas.createLinearGradient(0, 50, 0, 95)
        lingrad2.addColorStop(0.5, Color("#000"))
        lingrad2.addColorStop(1, Color("rgba(0,0,0,0)"))
        
        # assign gradients to fill and stroke styles
        self.canvas.setFillStyle(lingrad)
        self.canvas.setStrokeStyle(lingrad2)
        
        # draw shapes
        self.canvas.fillRect(10, 10, 130, 130)
        self.canvas.strokeRect(50, 50, 50, 50)
        
        self.canvas.restoreContext()
        
        # DRAW SOME RADIAL GRADIENTS
        # Demos ported from Mozilla Development Center Canvas Tutorial
        self.canvas.saveContext()
        self.canvas.translate(150, 150)
        
        radgrad = self.canvas.createRadialGradient(45, 45, 10, 52, 50, 30)
        radgrad.addColorStop(0, Color("#A7D30C"))
        radgrad.addColorStop(0.9, Color("#019F62"))
        radgrad.addColorStop(1, Color("rgba(1,159,98,0)"))
        
        radgrad2 = self.canvas.createRadialGradient(105, 105, 20, 112, 120, 50)
        radgrad2.addColorStop(0, Color("#FF5F98"))
        radgrad2.addColorStop(0.75, Color("#FF0188"))
        radgrad2.addColorStop(1, Color("rgba(255,1,136,0)"))
        
        radgrad3 = self.canvas.createRadialGradient(95, 15, 15, 102, 20, 40)
        radgrad3.addColorStop(0, Color("#00C9FF"))
        radgrad3.addColorStop(0.8, Color("#00B5E2"))
        radgrad3.addColorStop(1, Color("rgba(0,201,255,0)"))
        
        radgrad4 = self.canvas.createRadialGradient(0, 150, 50, 0, 140, 90)
        radgrad4.addColorStop(0, Color("#F4F201"))
        radgrad4.addColorStop(0.8, Color("#E4C700"))
        radgrad4.addColorStop(1, Color("rgba(228,199,0,0)"))
        
        # draw shapes
        self.canvas.setFillStyle(radgrad4)
        self.canvas.fillRect(0, 0, 150, 150)
        self.canvas.setFillStyle(radgrad3)
        self.canvas.fillRect(0, 0, 150, 150)
        self.canvas.setFillStyle(radgrad2)
        self.canvas.fillRect(0, 0, 150, 150)
        self.canvas.setFillStyle(radgrad)
        self.canvas.fillRect(0, 0, 150, 150)
        
        self.canvas.restoreContext()
    
    
    def stopDemo(self):
        pass
    


www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.