Color of a screen pixel: Difference between revisions
Content added Content deleted
(Added Wren) |
(→{{header|Wren}}: A bit simpler.) |
||
Line 1,034: | Line 1,034: | ||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
{{libheader|DOME}} |
{{libheader|DOME}} |
||
<lang ecmascript>import "dome" for Window |
<lang ecmascript>import "dome" for Window, Process |
||
import "graphics" for Canvas, Color |
import "graphics" for Canvas, Color |
||
import "input" for Mouse |
import "input" for Mouse |
||
var Reported = false |
|||
class Game { |
class Game { |
||
static init() { |
static init() { |
||
Window.title = "Color of a screen pixel" |
Window.title = "Color of a screen pixel" |
||
⚫ | |||
} |
} |
||
static update() { |
static update() { |
||
⚫ | |||
// when the left button is first pressed |
|||
⚫ | |||
if (Mouse.isButtonPressed("left")) { |
|||
⚫ | |||
⚫ | |||
if (!Reported) { |
|||
var x = Mouse.x |
var x = Mouse.x |
||
var y = Mouse.y |
var y = Mouse.y |
||
var col = Canvas.pget(x, y) |
var col = Canvas.pget(x, y) |
||
System.print("The color of the pixel at (%(x), %(y)) is %(getRGB(col))") |
System.print("The color of the pixel at (%(x), %(y)) is %(getRGB(col))") |
||
Process.exit(0) |
|||
} |
} |
||
} |
} |
||
⚫ | |||
static getRGB(col) { "{%(col.r), %(col.g), %(col.b)}" } |
static getRGB(col) { "{%(col.r), %(col.g), %(col.b)}" } |
||
Line 1,067: | Line 1,065: | ||
<pre> |
<pre> |
||
$ ./dome color_of_screen_pixel.wren |
$ ./dome color_of_screen_pixel.wren |
||
The color of the pixel at ( |
The color of the pixel at (152, 115) is {255, 163, 0} |
||
</pre> |
</pre> |
||