Greyscale bars/Display: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(8 intermediate revisions by 3 users not shown)
Line 165:
RET
</syntaxhighlight>
 
=={{header|ANSI Standard 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
120 SET AREA COLOR 1 ! Select color one for drawing
130 FOR row=1 TO 4
140 LET n=IP(2^(row+2))
150 LET w=IP(1280/n)
160 LET py=IP(256*(4-row))
170 FOR b=0 TO n-1
180 LET g=b/(n-1)
190 IF n=16 OR n=64 THEN LET g=1-g
200 SET COLOR MIX(1) g,g,g ! Reprogram color 1 to the gray we want
210 PLOT AREA: w*b,py; w*b+w,py; w*b+w,py+256; w*b,py+256
220 NEXT b
230 NEXT row
240 END</syntaxhighlight>
 
=={{header|AutoHotkey}}==
Line 274 ⟶ 254:
</syntaxhighlight>
 
=={{header|BASIC256BASIC}}==
==={{header|ANSI BASIC}}===
{{trans|BBC BASIC}}
{{works with|Decimal BASIC}}
<syntaxhighlight lang="basic">100 SET WINDOW 0,1279,0,1023
110 REM (0,0) is the bottom left of the display
120 SET AREA COLOR 1 ! Select color one for drawing
130 FOR row=1 TO 4
140 LET n=IP(2^(row+2))
150 LET w=IP(1280/n)
160 LET py=IP(256*(4-row))
170 FOR b=0 TO n-1
180 LET g=b/(n-1)
190 IF n=16 OR n=64 THEN LET g=1-g
200 SET COLOR MIX(1) g,g,g ! Reprogram color 1 to the gray we want
210 PLOT AREA: w*b,py; w*b+w,py; w*b+w,py+256; w*b,py+256
220 NEXT b
230 NEXT row
240 END</syntaxhighlight>
 
==={{header|BASIC256}}===
<syntaxhighlight lang="text">
h=ceil(graphheight/4)
Line 288:
</syntaxhighlight>
 
==={{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
Line 529:
"RosettaGreys.Deposit; StdCmds.Open"
</syntaxhighlight>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|Windows,Types,StdCtrls,ExtCtrls,SysUtils,Graphics}}
Uses Delphi graphic objects to create a subroutine which draws rows of bars according to specificification for number of bars and rows, the row number and the direction of the color graident.
 
<syntaxhighlight lang="Delphi">
procedure DrawBar(Image: TImage; Bars,Rows,Row: integer; WhiteToBlack: boolean);
{Draw horizontal bar according the following parameters:}
{Bars = number of color bars to fit into the horizontal space}
{Rows = number of rows to fit into the vertical space}
{Row = the row to place the current bar - numbered 0..n, top to bottom}
{WhiteToBlack - if true, bars in the row go from white to back}
var X: integer;
var Color: integer;
var ColorStep: double;
var BarHeight: integer;
var R,R2: TRect;
begin
{Calculate bar dimensions}
BarHeight:=Image.Height div Rows;
R:=Rect(0,0,(Image.Width div Bars)+1, BarHeight);
OffsetRect(R,0,BarHeight * Row);
R2:=R;
{Calculate color parameters}
ColorStep:=255/(Bars-1);
if WhiteToBlack then
begin
Color:=255;
ColorStep:=-ColorStep
end
else Color:=0;
{Draw bars}
for X:=1 to Bars do
begin
{Set color}
Image.Canvas.Brush.Color:=RGB(Color,Color,Color);
Image.Canvas.Pen.Color:=RGB(Color,Color,Color);
{Draw rectangular bar}
Image.Canvas.Rectangle(R2);
{Move rectangle and calculate color}
OffsetRect(R2,R.Right,0);
Color:=Round(X * ColorStep);
end;
end;
 
 
procedure ShowGrayBars(Image: TImage);
{Draw four bar, with alternating color scheme}
begin
DrawBar(Image,8,4,0,False);
DrawBar(Image,16,4,1,True);
DrawBar(Image,32,4,2,False);
DrawBar(Image,64,4,3,True);
end;
</syntaxhighlight>
{{out}}
[[File:DelphGrayBars.png|thumb|none]]
<pre>
</pre>
 
=={{header|EasyLang}}==
 
[https://easylang.dev/show/#cod=PY5BDoMgEEX3nOIvK00RMKbdeBqKCYkyDZqa9PSdMSAr5v3PGzImvNRMBYUOvlvshEEB2H48OmvRI8ssndQaGQ84oXwCw8St2wm7StN8Gld6w4uo4tp3XA0VmeahhcrAcbiilb5RPqJ5wXPkN6LU8GPNSwy75HcWXnBbYvzAGutVs2foCV4Z9Qc= Run it]
[https://easylang.online/apps/_greyscale.html Run it]
 
<syntaxhighlight lang="text">
n = 8
for row = 0 to 3
sz = 100 / n
for i = 0 to n - 1
c = i / (n - 1)
if row mod 2 = 1
c = 1 - c
.
color3 c c c
move sz * i 10075 - row * 25
rect sz + 1 25
sleep 0.02
.
n *= 2.
n *= 2
.
</syntaxhighlight>
Line 2,083 ⟶ 2,144:
=={{header|Wren}}==
{{libheader|DOME}}
<syntaxhighlight lang="ecmascriptwren">import "graphics" for Canvas, Color
import "dome" for Window
import "math" for Math
9,485

edits