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"
Canvas.cls(Color.orange) // {255, 163, 0} in the default palette
}
}


static update() {}
static update() {
// report 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 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))")
Reported = true
Process.exit(0)
}
}
}
}

static draw(dt) {}


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 (141, 138) is {255, 163, 0}
The color of the pixel at (152, 115) is {255, 163, 0}
</pre>
</pre>