Greyscale bars/Display: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
|||
Line 9: | Line 9: | ||
=={{header|ActionScript}}== |
=={{header|ActionScript}}== |
||
< |
<syntaxhighlight lang="actionscript">package |
||
{ |
{ |
||
import flash.display.Sprite; |
import flash.display.Sprite; |
||
Line 34: | Line 34: | ||
} |
} |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
{{libheader|GTK}} |
{{libheader|GTK}} |
||
{{libheader|GtkAda}} |
{{libheader|GtkAda}} |
||
< |
<syntaxhighlight lang="ada">with Gtk.Window; use Gtk.Window; |
||
with Gtk.Enums; |
with Gtk.Enums; |
||
with Gtk.Handlers; |
with Gtk.Handlers; |
||
Line 124: | Line 124: | ||
Gtk.Main.Main; |
Gtk.Main.Main; |
||
end Greyscale; |
end Greyscale; |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Amazing Hopper}}== |
=={{header|Amazing Hopper}}== |
||
{{trans|AWK}} |
{{trans|AWK}} |
||
Version: hopper-FLOW! |
Version: hopper-FLOW! |
||
<syntaxhighlight lang="amazing hopper"> |
|||
<lang Amazing Hopper> |
|||
#include <flow.h> |
#include <flow.h> |
||
#include <flow-term.h> |
#include <flow-term.h> |
||
Line 164: | Line 164: | ||
NEXT |
NEXT |
||
RET |
RET |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|ANSI Standard BASIC}}== |
=={{header|ANSI Standard BASIC}}== |
||
Line 170: | Line 170: | ||
{{trans|BBC BASIC}} |
{{trans|BBC BASIC}} |
||
< |
<syntaxhighlight lang="ansi standard basic">100 SET WINDOW 0,1279,0,1023 |
||
110 REM (0,0) is the bottom left of the display |
110 REM (0,0) is the bottom left of the display |
||
120 SET AREA COLOR 1 ! Select color one for drawing |
120 SET AREA COLOR 1 ! Select color one for drawing |
||
Line 184: | Line 184: | ||
220 NEXT b |
220 NEXT b |
||
230 NEXT row |
230 NEXT row |
||
240 END</ |
240 END</syntaxhighlight> |
||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
Requires the GDI+ Standard Library by tic: http://www.autohotkey.com/forum/viewtopic.php?t=32238 |
Requires the GDI+ Standard Library by tic: http://www.autohotkey.com/forum/viewtopic.php?t=32238 |
||
< |
<syntaxhighlight lang="ahk">h := A_ScreenHeight |
||
w := A_ScreenWidth |
w := A_ScreenWidth |
||
pToken := gdip_Startup() |
pToken := gdip_Startup() |
||
Line 243: | Line 243: | ||
QColor(r, g, b){ |
QColor(r, g, b){ |
||
return 0xFF000000 | (r << 16) | (g << 8) | (b) |
return 0xFF000000 | (r << 16) | (g << 8) | (b) |
||
}</ |
}</syntaxhighlight> |
||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
< |
<syntaxhighlight lang="awk"> |
||
BEGIN { |
BEGIN { |
||
nrcolors = 8 |
nrcolors = 8 |
||
Line 272: | Line 272: | ||
} |
} |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|BASIC256}}== |
=={{header|BASIC256}}== |
||
<lang> |
<syntaxhighlight lang="text"> |
||
h=ceil(graphheight/4) |
h=ceil(graphheight/4) |
||
for row=1 to 4 |
for row=1 to 4 |
||
Line 286: | Line 286: | ||
next n |
next n |
||
next row |
next row |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|BBC BASIC}}== |
=={{header|BBC BASIC}}== |
||
< |
<syntaxhighlight lang="bbcbasic">MODE 8:REM 640 x 512 pixel display mode: BBC BASIC gives 2 graphics points per pixel |
||
REM (0,0) is the bottom left of the display |
REM (0,0) is the bottom left of the display |
||
GCOL 1 :REM Select colour one for drawing |
GCOL 1 :REM Select colour one for drawing |
||
Line 302: | Line 302: | ||
RECTANGLE FILL w%*b%,py%,w%,256 |
RECTANGLE FILL w%*b%,py%,w%,256 |
||
NEXT b% |
NEXT b% |
||
NEXT row%</ |
NEXT row%</syntaxhighlight> |
||
=={{header|C}}== |
=={{header|C}}== |
||
{{libheader|GTK}} |
{{libheader|GTK}} |
||
< |
<syntaxhighlight lang="c">#include <gtk/gtk.h> |
||
/* do some greyscale plotting */ |
/* do some greyscale plotting */ |
||
void gsplot (cairo_t *cr,int x,int y,double s) { |
void gsplot (cairo_t *cr,int x,int y,double s) { |
||
Line 340: | Line 340: | ||
gtk_main (); |
gtk_main (); |
||
return 0; |
return 0; |
||
} </ |
} </syntaxhighlight> |
||
=={{header|C sharp|C#}}== |
=={{header|C sharp|C#}}== |
||
{{libheader|System.Windows.Forms}} |
{{libheader|System.Windows.Forms}} |
||
< |
<syntaxhighlight lang="csharp">using System; |
||
using System.Drawing; |
using System.Drawing; |
||
using System.Windows.Forms; |
using System.Windows.Forms; |
||
Line 376: | Line 376: | ||
return colorBars; |
return colorBars; |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|C++}}== |
=={{header|C++}}== |
||
Line 383: | Line 383: | ||
file greytones.h |
file greytones.h |
||
</PRE> |
</PRE> |
||
< |
<syntaxhighlight lang="cpp">#ifndef MYWIDGET_H |
||
#define MYWIDGET_H |
#define MYWIDGET_H |
||
#include <QWidget> |
#include <QWidget> |
||
Line 396: | Line 396: | ||
void paintEvent( QPaintEvent * ) ; |
void paintEvent( QPaintEvent * ) ; |
||
} ; |
} ; |
||
#endif</ |
#endif</syntaxhighlight> |
||
<pre>file greytones.cpp</pre> |
<pre>file greytones.cpp</pre> |
||
< |
<syntaxhighlight lang="cpp">#include <QtGui> |
||
#include "greytones.h" |
#include "greytones.h" |
||
Line 431: | Line 431: | ||
run++ ; |
run++ ; |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
<PRE> |
<PRE> |
||
file main.cpp |
file main.cpp |
||
</PRE> |
</PRE> |
||
< |
<syntaxhighlight lang="cpp">#include <QApplication> |
||
#include "greytones.h" |
#include "greytones.h" |
||
Line 444: | Line 444: | ||
window.show( ) ; |
window.show( ) ; |
||
return app.exec( ) ; |
return app.exec( ) ; |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Component Pascal}}== |
=={{header|Component Pascal}}== |
||
Line 451: | Line 451: | ||
[[File:GreyScaleCp.png|thumb|right]] |
[[File:GreyScaleCp.png|thumb|right]] |
||
< |
<syntaxhighlight lang="oberon2"> |
||
MODULE RosettaGreys; |
MODULE RosettaGreys; |
||
IMPORT Views, Ports, Properties, Controllers, StdLog; |
IMPORT Views, Ports, Properties, Controllers, StdLog; |
||
Line 528: | Line 528: | ||
"RosettaGreys.Deposit; StdCmds.Open" |
"RosettaGreys.Deposit; StdCmds.Open" |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|EasyLang}}== |
=={{header|EasyLang}}== |
||
Line 534: | Line 534: | ||
[https://easylang.online/apps/_greyscale.html Run it] |
[https://easylang.online/apps/_greyscale.html Run it] |
||
<lang>n = 8 |
<syntaxhighlight lang="text">n = 8 |
||
for row range 4 |
for row range 4 |
||
sz = 100 / n |
sz = 100 / n |
||
Line 547: | Line 547: | ||
. |
. |
||
n *= 2 |
n *= 2 |
||
.</ |
.</syntaxhighlight> |
||
=={{header|Eiffel}}== |
=={{header|Eiffel}}== |
||
Line 555: | Line 555: | ||
[https://github.com/ljr1981/rosettacode_answers/blob/main/testing/rc_greyscale_bars/eifgreyscale.png PNG Output] |
[https://github.com/ljr1981/rosettacode_answers/blob/main/testing/rc_greyscale_bars/eifgreyscale.png PNG Output] |
||
< |
<syntaxhighlight lang="eiffel"> |
||
feature -- Test routines |
feature -- Test routines |
||
Line 627: | Line 627: | ||
down: INTEGER = -1 --| From `white' to `black' or ... |
down: INTEGER = -1 --| From `white' to `black' or ... |
||
up: INTEGER = 1 --| From `black' to `white' |
up: INTEGER = 1 --| From `black' to `white' |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Euler Math Toolbox}}== |
=={{header|Euler Math Toolbox}}== |
||
<syntaxhighlight lang="euler math toolbox"> |
|||
<lang Euler Math Toolbox> |
|||
>function grayscale(y1,y2,n,direction=1) ... |
>function grayscale(y1,y2,n,direction=1) ... |
||
$ loop 0 to n-1; |
$ loop 0 to n-1; |
||
Line 651: | Line 651: | ||
$endfunction |
$endfunction |
||
>grayscales: |
>grayscales: |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
< |
<syntaxhighlight lang="freebasic">' version 01-09-2017 |
||
' compile with: fbc -s console |
' compile with: fbc -s console |
||
' or compile with: fbc -s gui |
' or compile with: fbc -s gui |
||
Line 688: | Line 688: | ||
Sleep |
Sleep |
||
End</ |
End</syntaxhighlight> |
||
=={{header|Frink}}== |
=={{header|Frink}}== |
||
< |
<syntaxhighlight lang="frink"> |
||
fakewidth =!= dummy |
fakewidth =!= dummy |
||
Line 713: | Line 713: | ||
} |
} |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|FutureBasic}}== |
=={{header|FutureBasic}}== |
||
[[File:GrayscalesR.png|thumb|right]] |
[[File:GrayscalesR.png|thumb|right]] |
||
< |
<syntaxhighlight lang="futurebasic"> |
||
_window = 1 |
_window = 1 |
||
Line 772: | Line 772: | ||
HandleEvents |
HandleEvents |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{output}} |
{{output}} |
||
<pre> |
<pre> |
||
Line 778: | Line 778: | ||
</pre> |
</pre> |
||
And here's another clever and shorter solution: |
And here's another clever and shorter solution: |
||
< |
<syntaxhighlight lang="futurebasic">void local fn BuildWindow |
||
CGRect r = {0,0,640,400} |
CGRect r = {0,0,640,400} |
||
long i, j, bars = 8 |
long i, j, bars = 8 |
||
Line 802: | Line 802: | ||
fn BuildWindow |
fn BuildWindow |
||
HandleEvents</ |
HandleEvents</syntaxhighlight> |
||
=={{header|Gambas}}== |
=={{header|Gambas}}== |
||
< |
<syntaxhighlight lang="gambas">Public Sub Form_Open() |
||
Dim iRow, iCol, iClr As Integer 'For Row, Column and Colour |
Dim iRow, iCol, iClr As Integer 'For Row, Column and Colour |
||
Dim iInc As Integer = 4 'To calculate RGB colour |
Dim iInc As Integer = 4 'To calculate RGB colour |
||
Line 833: | Line 833: | ||
Next |
Next |
||
End</ |
End</syntaxhighlight> |
||
'''[http://www.cogier.com/gambas/GreyScale.png Click here for image of the output]''' |
'''[http://www.cogier.com/gambas/GreyScale.png Click here for image of the output]''' |
||
Line 840: | Line 840: | ||
{{libheader|Go Graphics}} |
{{libheader|Go Graphics}} |
||
{{trans|Java}} |
{{trans|Java}} |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 879: | Line 879: | ||
greyBars(dc) |
greyBars(dc) |
||
dc.SavePNG("greybars.png") |
dc.SavePNG("greybars.png") |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 889: | Line 889: | ||
This program uses an inlined XPM file which is scaled to fill an entire GTK fullscreen window |
This program uses an inlined XPM file which is scaled to fill an entire GTK fullscreen window |
||
< |
<syntaxhighlight lang="haskell">import Graphics.UI.Gtk |
||
import Graphics.UI.Gtk.Gdk.GC |
import Graphics.UI.Gtk.Gdk.GC |
||
import Control.Monad.Trans (liftIO) |
import Control.Monad.Trans (liftIO) |
||
Line 946: | Line 946: | ||
"AADDFFHHJJLLNNPPRRTTVVXXZZbbddffhhjjllnnpprrttvvxxzz11336688..**", |
"AADDFFHHJJLLNNPPRRTTVVXXZZbbddffhhjjllnnpprrttvvxxzz11336688..**", |
||
"*+.9876543210zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCA" |
"*+.9876543210zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCA" |
||
]</ |
]</syntaxhighlight> |
||
=={{header|Icon}} and {{header|Unicon}}== |
=={{header|Icon}} and {{header|Unicon}}== |
||
Line 953: | Line 953: | ||
[[File:Greyscale_unicon.png|thumb|right]] |
[[File:Greyscale_unicon.png|thumb|right]] |
||
< |
<syntaxhighlight lang="icon">link graphics,printf,numbers |
||
procedure main() |
procedure main() |
||
Line 983: | Line 983: | ||
put(TC.bands,band(height)) # bottom sentinal |
put(TC.bands,band(height)) # bottom sentinal |
||
return TC |
return TC |
||
end</ |
end</syntaxhighlight> |
||
{{libheader|Icon Programming Library}} |
{{libheader|Icon Programming Library}} |
||
Line 992: | Line 992: | ||
=={{header|J}}== |
=={{header|J}}== |
||
'''Solution:''' |
'''Solution:''' |
||
< |
<syntaxhighlight lang="j"> load 'viewmat' |
||
NB. size=. 2{.".wd'qm' NB. J6 |
NB. size=. 2{.".wd'qm' NB. J6 |
||
NB. size=. getscreenwh_jgtk_ '' NB. J7 |
NB. size=. getscreenwh_jgtk_ '' NB. J7 |
||
Line 1,000: | Line 1,000: | ||
togreyscale=. (256#. [:<.255 255 255&*)"0 |
togreyscale=. (256#. [:<.255 255 255&*)"0 |
||
'rgb' viewmat (4<.@%~{:size)# (64<.@%~{.size)#"1 togreyscale bars |
'rgb' viewmat (4<.@%~{:size)# (64<.@%~{.size)#"1 togreyscale bars |
||
wd 'pmove 0 _30 ',":size [ wd 'psel ',1{::,hforms_jviewmat_'' NB. J9</ |
wd 'pmove 0 _30 ',":size [ wd 'psel ',1{::,hforms_jviewmat_'' NB. J9</syntaxhighlight> |
||
Note that hardware changes over the years have left their mark on interface protocols, which shows up here as language changes. |
Note that hardware changes over the years have left their mark on interface protocols, which shows up here as language changes. |
||
Line 1,006: | Line 1,006: | ||
=={{header|Java}}== |
=={{header|Java}}== |
||
using basically the same code as in the C++ example |
using basically the same code as in the C++ example |
||
< |
<syntaxhighlight lang="java">import javax.swing.* ; |
||
import java.awt.* ; |
import java.awt.* ; |
||
Line 1,052: | Line 1,052: | ||
Greybars gb = new Greybars( ) ; |
Greybars gb = new Greybars( ) ; |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |
||
Live Demo: http://jsfiddle.net/gcN9g/embedded/result/ |
Live Demo: http://jsfiddle.net/gcN9g/embedded/result/ |
||
< |
<syntaxhighlight lang="javascript"><html><body> |
||
<script type="text/javascript"> |
<script type="text/javascript"> |
||
var width = 640; var height = 400; |
var width = 640; var height = 400; |
||
Line 1,085: | Line 1,085: | ||
</script> |
</script> |
||
</body></html> |
</body></html> |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
< |
<syntaxhighlight lang="julia">using Gtk, Cairo, ColorTypes |
||
function generategrays(n, screenwidth) |
function generategrays(n, screenwidth) |
||
Line 1,142: | Line 1,142: | ||
endit(w) = notify(cond) |
endit(w) = notify(cond) |
||
signal_connect(endit, win, :destroy) |
signal_connect(endit, win, :destroy) |
||
wait(cond)</ |
wait(cond)</syntaxhighlight> |
||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
{{trans|Java}} |
{{trans|Java}} |
||
< |
<syntaxhighlight lang="scala">// version 1.1 |
||
import java.awt.Color |
import java.awt.Color |
||
Line 1,196: | Line 1,196: | ||
fun main(args: Array<String>) { |
fun main(args: Array<String>) { |
||
GreyBars() |
GreyBars() |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Liberty BASIC}}== |
=={{header|Liberty BASIC}}== |
||
Black boxes were added around each color for ease of counting the boxes. |
Black boxes were added around each color for ease of counting the boxes. |
||
<syntaxhighlight lang="lb"> |
|||
<lang lb> |
|||
nomainwin |
nomainwin |
||
Line 1,233: | Line 1,233: | ||
end |
end |
||
</syntaxhighlight> |
|||
</lang> |
|||
Resulting [http://www.diga.me.uk/greyscale.gif GreyScale image] without the outlines. |
Resulting [http://www.diga.me.uk/greyscale.gif GreyScale image] without the outlines. |
||
Line 1,239: | Line 1,239: | ||
{{libheader|nw}} |
{{libheader|nw}} |
||
{{libheader|cairo}} |
{{libheader|cairo}} |
||
< |
<syntaxhighlight lang="lua">local nw = require("nw") |
||
local app = nw:app() |
local app = nw:app() |
||
local cw, ch = 320, 240 |
local cw, ch = 320, 240 |
||
Line 1,259: | Line 1,259: | ||
end |
end |
||
win:show() |
win:show() |
||
app:run()</ |
app:run()</syntaxhighlight> |
||
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="mathematica">CreateDocument[ Graphics[ Flatten@Table[ |
||
{ If[EvenQ[#3], GrayLevel[ 1. - j/#1 ], GrayLevel[ j/#1 ]], |
{ If[EvenQ[#3], GrayLevel[ 1. - j/#1 ], GrayLevel[ j/#1 ]], |
||
Rectangle[{j #2, 7*#3}, {#2 (j + 1), (#3 + 1) 7}]}, {j, 0, #1}] & @@@ |
Rectangle[{j #2, 7*#3}, {#2 (j + 1), (#3 + 1) 7}]}, {j, 0, #1}] & @@@ |
||
{{7, 8, 3}, {15, 4, 2}, {31, 2, 1}, {63, 1, 0} } |
{{7, 8, 3}, {15, 4, 2}, {31, 2, 1}, {63, 1, 0} } |
||
,ImageSize -> Full], WindowFrame -> "Frameless", WindowSize -> Full]</ |
,ImageSize -> Full], WindowFrame -> "Frameless", WindowSize -> Full]</syntaxhighlight> |
||
[[File:greyscales.jpg|thumb|right]] |
[[File:greyscales.jpg|thumb|right]] |
||
Line 1,273: | Line 1,273: | ||
3ds max provides customizable maps like gradient to the user, but you can also write it: |
3ds max provides customizable maps like gradient to the user, but you can also write it: |
||
<syntaxhighlight lang="maxscript"> |
|||
<lang MAXScript> |
|||
fn drawBarRow _bmp _row _width _number _inverse= |
fn drawBarRow _bmp _row _width _number _inverse= |
||
( |
( |
||
Line 1,343: | Line 1,343: | ||
b = bitmap_verticalBars() |
b = bitmap_verticalBars() |
||
display b |
display b |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
{{libheader|gintro}} |
{{libheader|gintro}} |
||
< |
<syntaxhighlight lang="nim">import gintro/[glib, gobject, gtk, gio, cairo] |
||
const |
const |
||
Line 1,413: | Line 1,413: | ||
let app = newApplication(Application, "Rosetta.GreyscaleBars") |
let app = newApplication(Application, "Rosetta.GreyscaleBars") |
||
discard app.connect("activate", activate) |
discard app.connect("activate", activate) |
||
discard app.run()</ |
discard app.run()</syntaxhighlight> |
||
=={{header|OCaml}}== |
=={{header|OCaml}}== |
||
< |
<syntaxhighlight lang="ocaml">open Graphics |
||
let round x = truncate (floor (x +. 0.5)) |
let round x = truncate (floor (x +. 0.5)) |
||
Line 1,438: | Line 1,438: | ||
done |
done |
||
) bars; |
) bars; |
||
ignore(read_key())</ |
ignore(read_key())</syntaxhighlight> |
||
Run with: |
Run with: |
||
Line 1,444: | Line 1,444: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
< |
<syntaxhighlight lang="perl">sub partition { |
||
my($all, $div) = @_; |
my($all, $div) = @_; |
||
my @marks = 0; |
my @marks = 0; |
||
Line 1,480: | Line 1,480: | ||
bars($h2,$w,4,1), |
bars($h2,$w,4,1), |
||
bars($h3,$w,5,0), |
bars($h3,$w,5,0), |
||
bars($h4,$w,6,1);</ |
bars($h4,$w,6,1);</syntaxhighlight> |
||
[https://github.com/SqrtNegInf/Rosettacode-Perl5-Smoke/blob/master/ref/Greyscale-bars-perl5.png See Greyscale-bars-perl5] (offsite image) |
[https://github.com/SqrtNegInf/Rosettacode-Perl5-Smoke/blob/master/ref/Greyscale-bars-perl5.png See Greyscale-bars-perl5] (offsite image) |
||
Line 1,488: | Line 1,488: | ||
{{libheader|Phix/online}} |
{{libheader|Phix/online}} |
||
You can run this online [http://phix.x10.mx/p2js/Greyscale_bars.htm here]. |
You can run this online [http://phix.x10.mx/p2js/Greyscale_bars.htm here]. |
||
<!--< |
<!--<syntaxhighlight lang="phix">(phixonline)--> |
||
<span style="color: #000080;font-style:italic;">-- |
<span style="color: #000080;font-style:italic;">-- |
||
-- demo\rosetta\Greyscale_bars.exw |
-- demo\rosetta\Greyscale_bars.exw |
||
Line 1,551: | Line 1,551: | ||
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span> |
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |
||
< |
<syntaxhighlight lang="picolisp">(let Pgm # Create PGM of 384 x 288 pixels |
||
(make |
(make |
||
(for N 4 |
(for N 4 |
||
Line 1,569: | Line 1,569: | ||
(prinl (length (car Pgm)) " " (length Pgm)) |
(prinl (length (car Pgm)) " " (length Pgm)) |
||
(prinl 255) |
(prinl 255) |
||
(for Y Pgm (apply wr Y)) ) )</ |
(for Y Pgm (apply wr Y)) ) )</syntaxhighlight> |
||
=={{header|Plain English}}== |
=={{header|Plain English}}== |
||
< |
<syntaxhighlight lang="plainenglish">To run: |
||
Start up. |
Start up. |
||
Clear the screen. |
Clear the screen. |
||
Line 1,616: | Line 1,616: | ||
If the flag is set, put "right-to-left" into the gradient's direction. |
If the flag is set, put "right-to-left" into the gradient's direction. |
||
If the flag is not set, put "left-to-right" into the gradient's direction. |
If the flag is not set, put "left-to-right" into the gradient's direction. |
||
Draw the gradient.</ |
Draw the gradient.</syntaxhighlight> |
||
=={{header|Processing}}== |
=={{header|Processing}}== |
||
< |
<syntaxhighlight lang="java"> |
||
//Aamrun, 3rd July 2022 |
//Aamrun, 3rd July 2022 |
||
Line 1,641: | Line 1,641: | ||
drawPanel(255,0,64,3*height/4); |
drawPanel(255,0,64,3*height/4); |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |
||
< |
<syntaxhighlight lang="purebasic">EnableExplicit |
||
Macro Check(Function) |
Macro Check(Function) |
||
Line 1,706: | Line 1,706: | ||
CloseScreen() |
CloseScreen() |
||
EndIf |
EndIf |
||
End</ |
End</syntaxhighlight> |
||
Press Enter or Escape to exit the programs's display. |
Press Enter or Escape to exit the programs's display. |
||
=={{header|Python}}== |
=={{header|Python}}== |
||
{{libheader|livewires}} |
{{libheader|livewires}} |
||
< |
<syntaxhighlight lang="python">#!/usr/bin/env python |
||
#four gray scaled stripes 8:16:32:64 in Python 2.7.1 |
#four gray scaled stripes 8:16:32:64 in Python 2.7.1 |
||
Line 1,736: | Line 1,736: | ||
while keys_pressed() != [' ']: # press spacebar to close window |
while keys_pressed() != [' ']: # press spacebar to close window |
||
pass |
pass |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|R}}== |
=={{header|R}}== |
||
Create a 4x64 matrix representing the described pattern, set margins to 0 so the image will fill the display, and plot the matrix in grayscale using the "image" function: |
Create a 4x64 matrix representing the described pattern, set margins to 0 so the image will fill the display, and plot the matrix in grayscale using the "image" function: |
||
[[File:GrayscalesR.png|thumb|right]] |
[[File:GrayscalesR.png|thumb|right]] |
||
<syntaxhighlight lang="r"> |
|||
<lang R> |
|||
mat <- matrix(c(rep(1:8, each = 8) / 8, |
mat <- matrix(c(rep(1:8, each = 8) / 8, |
||
rep(16:1, each = 4) / 16, |
rep(16:1, each = 4) / 16, |
||
Line 1,749: | Line 1,749: | ||
par(mar = rep(0, 4)) |
par(mar = rep(0, 4)) |
||
image(t(mat[4:1, ]), col = gray(1:64/64), axes = FALSE) |
image(t(mat[4:1, ]), col = gray(1:64/64), axes = FALSE) |
||
</syntaxhighlight> |
|||
</lang> |
|||
Or, this can be generalized with the function below, which produces the pattern for an arbitrary number of rows (though rows become visibly indistinguishable after about row 5): |
Or, this can be generalized with the function below, which produces the pattern for an arbitrary number of rows (though rows become visibly indistinguishable after about row 5): |
||
[[File:GrayscalesR-6.png|thumb|right]] |
[[File:GrayscalesR-6.png|thumb|right]] |
||
<syntaxhighlight lang="r"> |
|||
<lang R> |
|||
grayscalesImage <- function(nrow = 4) { |
grayscalesImage <- function(nrow = 4) { |
||
X <- matrix(NA, nrow = nrow, ncol = 2^(nrow + 2)) |
X <- matrix(NA, nrow = nrow, ncol = 2^(nrow + 2)) |
||
Line 1,765: | Line 1,765: | ||
## Example ## |
## Example ## |
||
grayscalesImage(6) # produces image shown in screenshot to the right |
grayscalesImage(6) # produces image shown in screenshot to the right |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
Line 1,773: | Line 1,773: | ||
[[File:Grayscale-pict.png|thumb|right]] |
[[File:Grayscale-pict.png|thumb|right]] |
||
< |
<syntaxhighlight lang="racket"> |
||
#lang racket/gui |
#lang racket/gui |
||
(require slideshow/pict) |
(require slideshow/pict) |
||
Line 1,794: | Line 1,794: | ||
(vc-append (grays 1/8 'right) (grays 1/16 'left) |
(vc-append (grays 1/8 'right) (grays 1/16 'left) |
||
(grays 1/32 'right) (grays 1/64 'left)) |
(grays 1/32 'right) (grays 1/64 'left)) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
(formerly Perl 6) |
(formerly Perl 6) |
||
<lang |
<syntaxhighlight lang="raku" line>my ($width,$height) = 1280,768; |
||
my $PGM = open "Greyscale-bars-perl6.pgm", :w orelse die "Can't create Greyscale-bars-perl6.pgm: $_"; |
my $PGM = open "Greyscale-bars-perl6.pgm", :w orelse die "Can't create Greyscale-bars-perl6.pgm: $_"; |
||
Line 1,832: | Line 1,832: | ||
my @marks = ((1/$div,2/$div ... 1) X* $all)».round; |
my @marks = ((1/$div,2/$div ... 1) X* $all)».round; |
||
@marks Z- 0,|@marks; |
@marks Z- 0,|@marks; |
||
}</ |
}</syntaxhighlight> |
||
[https://github.com/SqrtNegInf/Rosettacode-Perl6-Smoke/blob/master/ref/Greyscale-bars-perl6.png See Greyscale-bars-perl6] (offsite image) |
[https://github.com/SqrtNegInf/Rosettacode-Perl6-Smoke/blob/master/ref/Greyscale-bars-perl6.png See Greyscale-bars-perl6] (offsite image) |
||
=={{header|RapidQ}}== |
=={{header|RapidQ}}== |
||
<syntaxhighlight lang="vb"> |
|||
<lang vb> |
|||
Declare Sub PaintCanvas |
Declare Sub PaintCanvas |
||
Line 1,865: | Line 1,865: | ||
Form.showmodal |
Form.showmodal |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
< |
<syntaxhighlight lang="ring"> |
||
# Project : Greyscale bars/Display |
# Project : Greyscale bars/Display |
||
Line 1,927: | Line 1,927: | ||
} |
} |
||
label1 { setpicture(p1) show() } |
label1 { setpicture(p1) show() } |
||
</syntaxhighlight> |
|||
</lang> |
|||
Output: |
Output: |
||
https://www.dropbox.com/s/01iywg04iwubf55/GreyscaleBars.jpg?dl=0 |
https://www.dropbox.com/s/01iywg04iwubf55/GreyscaleBars.jpg?dl=0 |
||
=={{header|Run BASIC}}== |
=={{header|Run BASIC}}== |
||
< |
<syntaxhighlight lang="runbasic">for i = 1 to 4 |
||
incr = int(256 / (i * 8)) |
incr = int(256 / (i * 8)) |
||
c = 256 |
c = 256 |
||
Line 1,943: | Line 1,943: | ||
next i |
next i |
||
html "</table>" |
html "</table>" |
||
end</ |
end</syntaxhighlight> |
||
<pre>Run in a browser</pre> |
<pre>Run in a browser</pre> |
||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
< |
<syntaxhighlight lang="scala">import scala.swing._ |
||
class GreyscaleBars extends Component { |
class GreyscaleBars extends Component { |
||
Line 1,965: | Line 1,965: | ||
} |
} |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
Open window: |
Open window: |
||
[[File:greyscalebars_scala.png|thumb|right]] |
[[File:greyscalebars_scala.png|thumb|right]] |
||
< |
<syntaxhighlight lang="scala">new MainFrame(){ |
||
title="Greyscale bars" |
title="Greyscale bars" |
||
visible=true |
visible=true |
||
preferredSize=new Dimension(640, 320) |
preferredSize=new Dimension(640, 320) |
||
contents=new GreyscaleBars() |
contents=new GreyscaleBars() |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Seed7}}== |
=={{header|Seed7}}== |
||
< |
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i"; |
||
include "draw.s7i"; |
include "draw.s7i"; |
||
include "keybd.s7i"; |
include "keybd.s7i"; |
||
Line 2,006: | Line 2,006: | ||
end for; |
end for; |
||
ignore(getc(KEYBOARD)); |
ignore(getc(KEYBOARD)); |
||
end func;</ |
end func;</syntaxhighlight> |
||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
{{libheader|Tk}} |
{{libheader|Tk}} |
||
< |
<syntaxhighlight lang="tcl">package require Tcl 8.5 |
||
package require Tk 8.5 |
package require Tk 8.5 |
||
Line 2,030: | Line 2,030: | ||
} |
} |
||
incr y $dy |
incr y $dy |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
{{libheader|DOME}} |
{{libheader|DOME}} |
||
< |
<syntaxhighlight lang="ecmascript">import "graphics" for Canvas, Color |
||
import "dome" for Window |
import "dome" for Window |
||
import "math" for Math |
import "math" for Math |
||
Line 2,084: | Line 2,084: | ||
} |
} |
||
var Game = GreyBars.new(640, 320)</ |
var Game = GreyBars.new(640, 320)</syntaxhighlight> |
||
=={{header|XPL0}}== |
=={{header|XPL0}}== |
||
Floating point is used to get the full range of black to white. |
Floating point is used to get the full range of black to white. |
||
< |
<syntaxhighlight lang="xpl0">include c:\cxpl\codes; \intrinsic 'code' declarations |
||
int Q, N, W, B, C, Y; |
int Q, N, W, B, C, Y; |
||
[SetVid($112); \640x480x24 graphics |
[SetVid($112); \640x480x24 graphics |
||
Line 2,104: | Line 2,104: | ||
Q:= ChIn(1); \wait for keystroke |
Q:= ChIn(1); \wait for keystroke |
||
SetVid(3); \restore normal text mode |
SetVid(3); \restore normal text mode |
||
]</ |
]</syntaxhighlight> |
||
=={{header|Yabasic}}== |
=={{header|Yabasic}}== |
||
< |
<syntaxhighlight lang="yabasic">open window 1024, 600 |
||
w = peek("winwidth") |
w = peek("winwidth") |
||
h = peek("winheight") |
h = peek("winheight") |
||
Line 2,129: | Line 2,129: | ||
pause .1 |
pause .1 |
||
next n |
next n |
||
next row</ |
next row</syntaxhighlight> |
||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
Line 2,135: | Line 2,135: | ||
{{trans|XPL0}} |
{{trans|XPL0}} |
||
Uses the PPM class from http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#zkl |
Uses the PPM class from http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#zkl |
||
< |
<syntaxhighlight lang="zkl">img:=PPM(640,480); |
||
foreach q in ([0..3]){ //quarter of screen |
foreach q in ([0..3]){ //quarter of screen |
||
n:=(8).shiftLeft(q); //number of bars |
n:=(8).shiftLeft(q); //number of bars |
||
Line 2,147: | Line 2,147: | ||
} |
} |
||
} |
} |
||
img.write(File("foo.ppm","wb"));</ |
img.write(File("foo.ppm","wb"));</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Same as the R image (but smaller): |
Same as the R image (but smaller): |
||
Line 2,157: | Line 2,157: | ||
and we have a set of 8 bars: |
and we have a set of 8 bars: |
||
< |
<syntaxhighlight lang="zxbasic">10 REM wind the colour down or use a black and white television to see greyscale bars |
||
20 REM The ZX Spectrum display is 32 columns wide, so we have 8 columns of 4 spaces |
20 REM The ZX Spectrum display is 32 columns wide, so we have 8 columns of 4 spaces |
||
25 BORDER 0: CLS |
25 BORDER 0: CLS |
||
Line 2,165: | Line 2,165: | ||
60 NEXT c |
60 NEXT c |
||
70 REM at this point the cursor has wrapped, so we don't need a newline |
70 REM at this point the cursor has wrapped, so we don't need a newline |
||
80 NEXT r</ |
80 NEXT r</syntaxhighlight> |
||
{{omit from|GUISS}} |
{{omit from|GUISS}} |