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 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
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
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
|
|
|
Goto Forum:
Current Time: Thu Nov 14 01:29:31 GMT 2024
Powered by FUDForum. Page generated in 0.03660 seconds
|