Draw a pixel: Difference between revisions

Added Uiua solution
(add RPL)
(Added Uiua solution)
(14 intermediate revisions by 12 users not shown)
Line 638:
 
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
<syntaxhighlight lang="basic"> 100 WIDTH = 320
110 HEIGHT = 240
120 C = 1: REM RED
130 X = 100
140 Y = 100
150 DEF FN X(X) = INT ((X - 1) / 14)
160 DEF FN Y(Y) = INT ((Y - 1) / 8)
170 W = FN X(WIDTH)
180 H = FN Y(HEIGHT)
190 WX = INT ( RND (1) * (40 - W))
200 WY = INT ( RND (1) * (48 - H))
210 C$ = "0123456789:;<=>?"
220 C$ = MID$ (C$,C,I) + MID$ (C$,C + 2, LEN (C$) - C - 1)
230 I = INT ( RND (1) * LEN (C$))
240 COLOR= ASC ( MID$ (C$,I + 1)) - 48
250 C$ = MID$ (C$,1,I) + MID$ (C$,I + 2, LEN (C$) - I - 1)
260 A = PEEK (49234) + PEEK (49240) + PEEK (49232)
270 FOR I = 0 TO 39
280 VLIN 0,47 AT I
290 NEXT
300 COLOR= ASC ( MID$ (C$, INT ( RND (1) * LEN (C$)) + 1)) - 48
310 FOR I = WX TO WX + W
320 VLIN WY,WY + H AT I
330 NEXT
340 COLOR= C
350 PLOT WX + FN X(X),WY + FN Y(Y)
360 WAIT 49152,128
370 TEXT
380 HOME</syntaxhighlight>
 
==={{header|BASIC256}}===
It seems that the program should be this. And the BASIC256 tutorial programs work on my ubuntu system. This program neither draws the pixel nor resizes the window. Can't see anything when I plot many spots. Oh well. I've tried the rgb(255,0,0) function as well as the fastgraphics/refresh statements.
Line 650 ⟶ 681:
==={{header|BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
<syntaxhighlight lang="bbcbasic"> VDU 23, 22, 320; 240; 8, 8, 8, 0128, 18, 0, 19, 25, 69, 100; 100;</syntaxhighlight>
 
==={{header|Commodore BASIC}}===
Line 724 ⟶ 755:
80 GETKEY K$:REM WAIT FOR KEYPRESS
90 @TEXT:REM BACK TO TEXT MODE</syntaxhighlight>
 
==={{header|IS-BASIC}}===
<syntaxhighlight lang="is-basic">100 SET VIDEO X 40:SET VIDEO Y 26:SET VIDEO MODE 5:SET VIDEO COLOR 0
110 OPEN #101:"video:"
120 DISPLAY #101:AT 1 FROM 1 TO 26
130 SET PALETTE BLACK,RED
140 PLOT 100,100</syntaxhighlight>
 
=={{header|C}}==
Line 741 ⟶ 779:
}
</syntaxhighlight>
 
===Plain Xlib version===
Which is why most people use a framework :)
<syntaxhighlight lang="c">// dotrosetta.c - https://rosettacode.org/wiki/Draw_a_pixel
 
#include <X11/Xutil.h>
#include <stdio.h>
#include <stdlib.h>
 
int
main(void)
{
Atom wm_both_protocols[1];
Atom wm_delete;
Atom wm_protocols;
Display *display;
GC gc;
Window root;
Window window;
XEvent event;
XSetWindowAttributes attr;
int more = 1;
 
display = XOpenDisplay(NULL);
if(display == NULL)
{
fprintf(stderr,"Error: The display cannot be opened\n");
exit(1);
}
root = DefaultRootWindow(display);
wm_delete = XInternAtom(display, "WM_DELETE_WINDOW", False);
wm_protocols = XInternAtom(display, "WM_PROTOCOLS", False);
attr.background_pixel = 0x000000;
attr.event_mask = ExposureMask;
window = XCreateWindow(display, root,
0, 0, 320, 240, 0,
CopyFromParent, InputOutput, CopyFromParent,
CWBackPixel | CWEventMask,
&attr
);
XStoreName(display, window, "Draw a Pixel");
wm_both_protocols[0] = wm_delete;
XSetWMProtocols(display, window, wm_both_protocols, 1);
gc = XCreateGC(display, window, 0, NULL);
XSetForeground(display, gc, 0xFF0000);
XMapWindow(display, window);
 
while(more)
{
XNextEvent(display, &event);
switch(event.type)
{
case Expose:
XDrawPoint(display, window, gc, 100, 100);
break;
 
case ClientMessage: // for close request from WM
if(event.xclient.window == window &&
event.xclient.message_type == wm_protocols &&
event.xclient.format == 32 &&
event.xclient.data.l[0] == wm_delete)
{
more = 0;
}
break;
 
default:
printf("unexpected event.type %d\n", event.type);;
}
}
 
XCloseDisplay(display);
exit(0);
}</syntaxhighlight>
 
=={{header|Delphi}}==
Line 839 ⟶ 951:
 
=={{header|EasyLang}}==
The Easylang graphic does not work with pixels. Although the drawing area is set to be 100x100 units - not pixels - this can be scaled and it can be drawn on intermediate positions. A pixel can be simulated by a small filled square.
Because of EasyLang's limitations, the canvas is limited to 100x100. To draw a pixel, draw a rectangle of size 1x1. To put a pixel at (100, 100), we must set the coordinates at (99, 99) because 100 is located at the very edge of the canvas. 900 is a color that is equivalent to red.
 
<syntaxhighlight lang="easylang">color 900
<syntaxhighlight lang="easylang">
move 99 99
color 900
rect 1 1</syntaxhighlight>
move 50 50
rect 0.5 0.5
</syntaxhighlight>
 
=={{header|F Sharp|F#}}==
Line 867 ⟶ 982:
MAIN: draw-pixel</syntaxhighlight>
 
=={{header|Evaldraw}}==
 
Assumes you resize your Evaldraw instance to 320x240 or open it from commandline with "evaldraw program.kc /320x240"
<syntaxhighlight lang="c">
()
cls(0);
setcol(255,0,0);
setpix(100,100);
</syntaxhighlight>
 
=={{header|Forth}}==
Line 934 ⟶ 1,056:
End</syntaxhighlight>
 
=={{header|Frink}}==
<syntaxhighlight lang="frink">i = new image[320,240]
i.setPixel[100,100,1,0,0]
i.show[]</syntaxhighlight>
 
=={{header|FutureBasic}}==
Line 1,047 ⟶ 1,173:
Event()
end</syntaxhighlight>
 
=={{header|IS-BASIC}}==
<syntaxhighlight lang="is-basic">100 SET VIDEO X 40:SET VIDEO Y 26:SET VIDEO MODE 5:SET VIDEO COLOR 0
110 OPEN #101:"video:"
120 DISPLAY #101:AT 1 FROM 1 TO 26
130 SET PALETTE BLACK,RED
140 PLOT 100,100</syntaxhighlight>
 
=={{header|J}}==
Line 1,292 ⟶ 1,411:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">CreateWindow[PaletteNotebook[{Graphics[{Red, Point[{100, 100}]}]}], WindowSize -> {320, 240}]</syntaxhighlight>
 
=={{header|Maxima}}==
<syntaxhighlight lang="maxima">
/* Matrix that represents the window and the pixel positioned in it */
ematrix(320,240,1,100,100)$
 
/* Drawing the window and the pixel as needed */
wxdraw2d(palette = [white,gray,red], image(%,0,0,320,240))$
</syntaxhighlight>
[[File:DrawPixelMaxima.png|thumb|center]]
 
=={{header|Microsoft Small Basic}}==
Line 1,524 ⟶ 1,653:
$cr->stroke;
}</syntaxhighlight>
 
===Alternate with Perl/Tk===
 
<syntaxhighlight lang="perl">#!/usr/bin/perl
 
use strict; # https://rosettacode.org/wiki/Draw_a_pixel
use warnings;
use Tk;
 
my $mw = MainWindow->new;
my $canvas = $mw->Canvas( -width => 320, -height => 240 )->pack;
$canvas->createRectangle( 100, 100, 100, 100, -outline => 'red' );
MainLoop;</syntaxhighlight>
 
===Alternate with X11::Protocol===
 
<syntaxhighlight lang="perl">#!/usr/bin/perl
 
use strict; # https://rosettacode.org/wiki/Draw_a_pixel
use warnings;
use X11::Protocol;
 
my $x = new X11::Protocol or die "X11 connection failed";
$x->CreateWindow(my $id = $x->new_rsrc, $x->root, 'InputOutput',
$x->root_depth, 'CopyFromParent',
0, 0, 320, 240, 0,
background_pixel => 0x000000,
event_mask => $x->pack_event_mask( qw( Exposure )),
);
$x->ChangeProperty($id, $x->atom('WM_NAME'), $x->atom('STRING'),
8, 'Replace', 'Draw a Pixel');
$x->ChangeProperty($id, $x->atom('WM_PROTOCOLS'), $x->atom('ATOM'),
32, 'Replace', pack('L', $x->atom('WM_DELETE_WINDOW')));
$x->CreateGC(my $gc = $x->new_rsrc, $id, foreground => 0xff0000);
$x->MapWindow($id);
$x->event_handler('queue');
 
my ($more, $name, %e) = 1;
while($more)
{
%e = $x->next_event;
$name = $e{name};
EVENT->$name;
}
 
sub EVENT::Expose { $x->PolyPoint($id, $gc, 'ORIGIN', 100, 100) }
sub EVENT::ConfigureNotify { }
sub EVENT::ClientMessage
{
if($e{type} == $x->atom('WM_PROTOCOLS') &&
unpack('L', $e{data}) == $x->atom('WM_DELETE_WINDOW'))
{
$more = 0;
}
else
{
warn "Unknown $name, $e{type}\n";
}
}
sub EVENT::AUTOLOAD { die "Sorry, no handler for $name\n" }</syntaxhighlight>
 
=={{header|Phix}}==
Line 1,828 ⟶ 2,017:
 
=={{header|RPL}}==
HP devices running RPL have only black-and-white LCD screens, so so much for the red color. ResolutionScreen isresolution eithergoes 64x131from or137x32 80x131to 131x80 depending on the model, but the user can freely define coordinates for the bottom-left pixel (minimum value) and for the top-right pixel (maximum value)., so the program below works on any model:
≪ CLLCD (0,0) PMIN (320,240) PMAX (100,100) PIXEL ≫ EVAL
 
Line 2,003 ⟶ 2,192:
PLOT 100,100
END</syntaxhighlight>
 
=={{header|Uiua}}==
{{works with|Uiua|0.10.0}}
Run it using Uiua Pad to see the teeny-weeny dot.
<syntaxhighlight lang="Uiua">
↯240_320_3 0
⍜(⊡[100 100]|[1 0 0]◌)
</syntaxhighlight>
 
=={{header|Uxntal}}==
<syntaxhighlight lang="Uxntal">
( $ uxnasm draw-pixel.tal draw-pixel.rom && uxnemu draw-pixel.rom )
 
|00 @System &vector $2 &expansion $2 &wst $1 &rst $1 &metadata $2 &r $2 &g $2 &b $2 &debug $1 &state $1
|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1
 
|0100
( set theme )
#0f00 .System/r DEO2
#0000 .System/g DEO2
#0000 .System/b DEO2
 
( set screen size )
#0140 .Screen/width DEO2
#00f0 .Screen/height DEO2
 
( set position )
#0064 .Screen/x DEO2
#0064 .Screen/y DEO2
 
( draw pixel )
#01 .Screen/pixel DEO
BRK</syntaxhighlight>
 
=={{header|VBA}}==
Line 2,040 ⟶ 2,262:
=={{header|Wren}}==
{{libheader|DOME}}
<syntaxhighlight lang="ecmascriptwren">import "dome" for Window
import "graphics" for Canvas, Color
 
73

edits