Draw a pixel: Difference between revisions

Added Uiua solution
imported>Tybalt89
(Added Uiua solution)
 
(8 intermediate revisions by 7 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 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 944 ⟶ 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,057 ⟶ 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 2,083 ⟶ 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,120 ⟶ 2,262:
=={{header|Wren}}==
{{libheader|DOME}}
<syntaxhighlight lang="ecmascriptwren">import "dome" for Window
import "graphics" for Canvas, Color
 
67

edits