Draw a pixel: Difference between revisions

Added Uiua solution
(Added Odin variant)
(Added Uiua solution)
(22 intermediate revisions by 17 users not shown)
Line 637:
}</syntaxhighlight>
 
=={{header|BASIC256BASIC}}==
==={{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.
<syntaxhighlight lang="basic256">
Line 647 ⟶ 679:
</syntaxhighlight>
 
==={{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|CCommodore BASIC}}===
Requires the [http://www.cs.colorado.edu/~main/bgi/cs1300/ WinBGIm] library.
<syntaxhighlight lang="c">
#include<graphics.h>
 
int main()
{
initwindow(320,240,"Red Pixel");
putpixel(100,100,RED);
getch();
return 0;
}
</syntaxhighlight>
 
=={{header|Commodore BASIC}}==
The Commodore 8-bit machines only had 200 lines of vertical resolution (and the VIC-20 rarely used more than 160 of them for bitmap graphics), so these examples do not quite fit the task's 240-line requirement.
 
Line 740 ⟶ 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}}==
Requires the [http://www.cs.colorado.edu/~main/bgi/cs1300/ WinBGIm] library.
<syntaxhighlight lang="c">
#include<graphics.h>
 
int main()
{
initwindow(320,240,"Red Pixel");
putpixel(100,100,RED);
getch();
return 0;
}
</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 836 ⟶ 949:
{{out}}
[https://ibb.co/VL9Qs5z]
 
=={{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.
 
<syntaxhighlight lang="easylang">
color 900
move 50 50
rect 0.5 0.5
</syntaxhighlight>
 
=={{header|F Sharp|F#}}==
Line 860 ⟶ 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 926 ⟶ 1,055:
Sleep
End</syntaxhighlight>
 
=={{header|Frink}}==
<syntaxhighlight lang="frink">i = new image[320,240]
i.setPixel[100,100,1,0,0]
i.show[]</syntaxhighlight>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
void local fn BuildWindow
CGRect r = fn CGRectMake( 0, 0, 320, 240 )
window 1, @"Single Pixel", r, NSWindowStyleMaskTitled + NSWindowStyleMaskClosable
oval fill fn CGRectMake( 100-0.5, 100-0.5, 1, 1 ), fn ColorRed
end fn
 
void local fn DoDialog( ev as long, tag as long, wnd as long )
select ( ev )
case _windowWillClose : end
end select
end fn
 
on dialog fn DoDialog
 
fn BuildWindow
 
HandleEvents
</syntaxhighlight>
 
 
=={{header|GB BASIC}}==
Line 1,017 ⟶ 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,210 ⟶ 1,359:
SDL.delay(5000)
</syntaxhighlight>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">CreateWindow[PaletteNotebook[{Graphics[{Red, Point[{100, 100}]}]}], WindowSize -> {320, 240}]</syntaxhighlight>
 
=={{header|M2000 Interpreter}}==
Line 1,262 ⟶ 1,408:
</syntaxhighlight>
[https://www.dropbox.com/s/uscltz6pwy06jxv/DrawPixelForm.png?dl=0 OutPut]
 
=={{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}}==
<syntaxhighlight lang="smallbasic">GraphicsWindow.Width = 320
GraphicsWindow.Height = 240
GraphicsWindow.SetPixel(100, 100, GraphicsWindow.GetColorFromRGB(255, 0, 0))</syntaxhighlight>
 
=={{header|MiniScript}}==
<syntaxhighlight lang="MiniScript">gfx.clear color.black, 320, 240
gfx.setPixel 100, 100, rgb(255,0,0)</syntaxhighlight>
 
=={{header|Nim}}==
Line 1,485 ⟶ 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,525 ⟶ 1,753:
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</syntaxhighlight>-->
 
=={{header|Plain English}}==
<syntaxhighlight lang="text">
To run:
Start up.
Make a box 320 pixels by 240 pixels.
Draw the box with the white color and the white color.
Make a spot with 100 pixels and 100 pixels.
Draw the spot with the red color.
Refresh the screen.
Wait for the escape key.
Shut down.
</syntaxhighlight>
 
=={{header|Processing}}==
Line 1,774 ⟶ 2,015:
 
I highly recommend you check out [https://www.digitalmzx.net/wiki/index.php?title=Sprite_(Tutorial) this tutorial] for the usage of Sprites in order to get a better understanding of all this.
 
=={{header|RPL}}==
HP devices running RPL have only black-and-white LCD screens, so so much for the red color. Screen resolution goes from 137x32 to 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
 
=={{header|Ruby}}==
Line 1,947 ⟶ 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 1,957 ⟶ 2,235:
End Sub</syntaxhighlight>
 
=={{header|V (Vlang)}}==
<syntaxhighlight lang="v (vlang)">import gg
import gx
 
Line 1,984 ⟶ 2,262:
=={{header|Wren}}==
{{libheader|DOME}}
<syntaxhighlight lang="ecmascriptwren">import "dome" for Window
import "graphics" for Canvas, Color
 
73

edits