Color of a screen pixel: Difference between revisions

Content added Content deleted
(Added Wren)
(→‎{{header|Wren}}: A bit simpler.)
Line 1,034:
=={{header|Wren}}==
{{libheader|DOME}}
<lang ecmascript>import "dome" for Window, Process
import "graphics" for Canvas, Color
import "input" for Mouse
 
var Reported = false
 
class Game {
static init() {
Window.title = "Color of a screen pixel"
Canvas.cls(Color.orange) // {255, 163, 0} in the default palette
}
 
static update() {}
// report initial location and color of pixel at mouse cursor
 
// when the left button is first pressed
static draw(dt) {
if (Mouse.isButtonPressed("left")) {
Canvas.cls(Color.orange) // {255, 163, 0} in the default palette
 
// report initial location and color of pixel at mouse cursor
if (!Reported) {
var x = Mouse.x
var y = Mouse.y
var col = Canvas.pget(x, y)
System.print("The color of the pixel at (%(x), %(y)) is %(getRGB(col))")
Reported = trueProcess.exit(0)
}
}
 
static draw(dt) {}
 
static getRGB(col) { "{%(col.r), %(col.g), %(col.b)}" }
Line 1,067 ⟶ 1,065:
<pre>
$ ./dome color_of_screen_pixel.wren
The color of the pixel at (141152, 138115) is {255, 163, 0}
</pre>