Draw pixel 2: Difference between revisions
m
syntax highlighting fixup automation
(J) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 10:
=={{header|Ada}}==
{{libheader|SDLAda}}
<
with SDL.Video.Windows.Makers;
Line 69:
Window.Finalize;
SDL.Finalise;
end Draw_A_Pixel_2;</
=={{header|C}}==
Same as the [[Draw_a_pixel]] task, uses the random number functions of stdlib.h to plot a random point. Requires the [http://www.cs.colorado.edu/~main/bgi/cs1300/ WinBGIm] library.
<syntaxhighlight lang="c">
#include<graphics.h>
#include<stdlib.h>
Line 90:
return 0;
}
</syntaxhighlight>
=={{header|Delphi}}==
{{libheader| Windows}}
{{libheader| Messages}}
{{libheader| SysUtils}}
<syntaxhighlight lang="delphi">
program Draw_a_pixel2;
Line 185:
CreateWin(WIN_WIDTH, WIN_HEIGHT);
ShowModal();
end.</
=={{header|Factor}}==
{{works with|Factor|0.99 development release 2019-07-10}}
<
640 480 2dup "random yellow pixel" init-window [ random ] bi@
Line 195:
begin-drawing BLACK clear-background 2dup YELLOW draw-pixel
end-drawing
] until close-window</
=={{header|FreeBASIC}}==
<
' compile with: fbc -s console
' or: fbc -s gui
Line 219:
WindowTitle "0, 0 is top left, pixel is at " & x & ", " & y & " hit any key to end program"
Sleep
End</
=={{header|Go}}==
<
import (
Line 260:
}
}
}</
{{out}}
Line 269:
=={{header|J}}==
See also [[Draw_a_pixel#J|Draw a pixel]]. Note that this pixel will be nearly invisible on most screens. There's very low contrast between yellow and white, and single pixels may be difficult to see on "modern" hardware. Remedying these visual problems would require going outside the requirements of the task. You might change the color, for example to black with <code>glrgb 0 0 0</code> and/or changing the radius to include more pixels, for example 8 with <code>glpen 8 1</code><
coinsert 'jgl2'
wd{{)n pc Rosetta closeok;cc task isidraw; set task wh 640 480;pshow}}
glpaint glpixel ?640 480 [ glpen 1 1 [ glrgb 255 255 0 [ glclear ''</
=={{header|javascript}}==
<
let canvas = document.createElement("canvas");
canvas.width = 640;
Line 285:
let y = Math.random() * 481;
ctx.fillRect(x, y, 1, 1);
</syntaxhighlight>
=={{header|Julia}}==
<
const can = @GtkCanvas()
Line 310:
signal_connect(endit, win, :destroy)
wait(cond)
</syntaxhighlight>
=={{header|Kotlin}}==
This is a variation of the [[Draw a pixel]] task and so therefore is the code to accomplish it.
<
import java.awt.Color
Line 352:
}
}
}</
{{output}}
Line 362:
=={{header|Nim}}==
{{libheader|SDL2}}
<
import sdl2
Line 378:
renderer.present()
delay(5000)</
=={{header|Objeck}}==
<
use Game.Framework;
Line 431:
};
}
}</
=={{header|Perl}}==
{{libheader|Gtk3}}
<
my $width = 640;
Line 460:
$cr->rectangle( int rand $width , int rand $height, 1, 1);
$cr->stroke;
}</
=={{header|Phix}}==
{{libheader|Phix/pGUI}}
Pixel jumps around randomly, twice a second.
<!--<
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Draw_pixel_2.exw
Line 512:
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</
=={{header|Processing}}==
<
//Aamrun, 26th June 2022
Line 523:
ellipse(random(640),random(480),1,1);
</syntaxhighlight>
=={{header|Python}}==
Line 529:
{{libheader|Tkinter}}
{{libheader|random}}
<
def draw_pixel_2 ( sizex=640,sizey=480 ):
pos = random.randint( 0,sizex-1 ),random.randint( 0,sizey-1 )
Line 540:
root.mainloop()
draw_pixel_2()</
=={{header|Racket}}==
<
(define WIDTH 640)
Line 564:
(send dc draw-point (random WIDTH) (random HEIGHT)))])
(send frame show #t)</
=={{header|Raku}}==
Line 571:
Coordinates of random pixel displayed in window title. To make the single pixel show up better I filled in the drawing area background with black to get better contrast.
<syntaxhighlight lang="raku"
use GTK::Simple::DrawingArea;
use Cairo;
Line 597:
my $ctx = $da.add-draw-handler( &rect-do );
$app.run;</
=={{header|Ring}}==
<
load "guilib.ring"
Line 660:
see "green : " + mycolor.green() + nl
see "blue : " + mycolor.blue() + nl
}</
Outputimage:
Line 673:
{{libheader|Scastie qualified}}
{{works with|Scala|2.13}}
<
import java.awt.Color
import scala.language.reflectiveCalls
Line 712:
println("Tests successfully completed with no errors found.")
}</
=={{header|Wren}}==
{{libheader|DOME}}
<
import "graphics" for Canvas, Color
import "random" for Random
Line 737:
static getRGB(col) { "{%(col.r), %(col.g), %(col.b)}" }
}</
=={{header|XPL0}}==
This is all that's required on the Raspberry Pi version of XPL0.
<
|