Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Glimmer Canvas Shape DSL & Animation DSL for SWT(Canvas Graphics Come to Glimmer DSL for SWT, Finally!)
Glimmer Canvas Shape DSL & Animation DSL for SWT [message #1836995] Wed, 20 January 2021 18:38
Andy Maleh is currently offline Andy MalehFriend
Messages: 75
Registered: March 2020
Location: Montreal, Quebec, Canada
Member
Hello, Canvas! Sample

# From: https://github.com/AndyObtiva/glimmer-dsl-swt/blob/master/samples/hello/hello_canvas.rb
include Glimmer

shell {
  text 'Hello, Canvas!'
  minimum_size 320, 400

  canvas {
    background :yellow
    rectangle(0, 0, 220, 400, fill: true) {
      background :red
    }
    rectangle(50, 20, 300, 150, 30, 50, round: true, fill: true) {
      background :magenta
    }
    rectangle(150, 200, 100, 70, true, gradient: true) {
      background :dark_magenta
      foreground :yellow
    }
    rectangle(50, 200, 30, 70, false, gradient: true) {
      background :magenta
      foreground :dark_blue
    }
    rectangle(205, 50, 88, 96) {
      foreground :yellow
    }
    text('Picasso', 60, 80) {
      background :yellow
      foreground :dark_magenta
      font name: 'Courier', height: 30
    }
    oval(110, 310, 100, 100, fill: true) {
      background rgb(128, 138, 248)
    }
    arc(210, 210, 100, 100, 30, -77, fill: true) {
      background :red
    }
    polygon(250, 210, 260, 170, 270, 210, 290, 230, fill: true) {
      background :dark_yellow
    }
    polyline(250, 110, 260, 70, 270, 110, 290, 130, 250, 110)
  }
}.open


https://raw.githubusercontent.com/AndyObtiva/glimmer-dsl-swt/master/images/glimmer-hello-canvas.png

Hello, Canvas Animation! Sample

include Glimmer

shell {
  text 'Hello, Canvas Animation!'
  minimum_size 800, 420

  canvas {
    animation {
      every 0.01 # in seconds (one hundredth)
            
      frame { |index| # frame block loops indefinitely (unless frame_count is set to an integer)
        background rgb(index%255, 100, 200) # sets canvas background color
        
        oval(0, 0, 400, 400) { # x, y, width, height
          foreground :black # sets oval background color
        }
        arc(0, 0, 400, 400, -1.4*index%360, 10, fill: true) {  # x, y, width, height, start angle, arc angle
          background rgb(200, 200, 50) # sets arc background color
        }
      }
    }
  }

  canvas {
    colors = [:yellow, :red]
    animation {
      every 0.25 # in seconds (one quarter)
      cycle colors # cycles array of colors into the second variable of the frame block below

      frame { |index, color| # frame block loops indefinitely (unless frame_count or cycle_count is set to an integer)
        outside_color = colors[index % 2]
        inside_color = colors[(index + 1) % 2]
        
        background outside_color # sets canvas background color
        
        rectangle(0, 0, 200, 200, fill: true) {
          background inside_color # sets rectangle background color
        }
        rectangle(200, 200, 200, 200, fill: true) {
          background inside_color # sets rectangle background color
        }
      }
    }
  }
}.open


https://raw.githubusercontent.com/AndyObtiva/glimmer-dsl-swt/master/images/glimmer-hello-canvas-animation.png

https://raw.githubusercontent.com/AndyObtiva/glimmer-dsl-swt/master/images/glimmer-hello-canvas-animation-frame2.png

Original Article

Glimmer Canvas Shape DSL

Glimmer Canvas Animation DSL

Glimmer DSL for SWT

Enjoy!


EclipseCon / EclipseWorld / Agile Conference Speaker
Open-Source Software Author of Glimmer DSL for SWT
Previous Topic:Moving a shell from a high-dpi to a low-dpi monitor does not rescale the shell and its contents
Next Topic:SVG error
Goto Forum:
  


Current Time: Sat Apr 20 00:28:55 GMT 2024

Powered by FUDForum. Page generated in 0.02782 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top