Pinstripe/Display: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (→‎{{header|Wren}}: Aligned comments.)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(17 intermediate revisions by 10 users not shown)
Line 1:
{{task|Test card}}
[[File:Pinstripe-mono-unicon.gif|thumb|right|Sample image]]
 
The task is to demonstrate the creation of a series of vertical pinstripes across '''the entire width of the display'''.
* in the first quarter the pinstripes should alternate one pixel white, one pixel black = 1 pixel wide vertical pinestripes
Line 6 ⟶ 7:
* Half way down the display, we switch to 3 pixels wide,
* for the lower quarter of the display we use 4 pixels.
 
 
c.f. [[Colour_pinstripe/Display]]
<br><br>
=={{header|6502 Assembly}}==
{{works with|https://skilldrick.github.io/easy6502/ Easy6502}}
This is very similar to the color pinstripe task. It actually takes <i>more</i> code to execute, though not by much.
Output can be viewed by copying this source code, then clicking "Assemble" then "Run."
<syntaxhighlight lang="6502asm">define color $00
define looptemp $01
lda #1
sta color
 
loop_1wide:
lda color
and #$01
; this takes advantage of the fact that Easy6502 maps black to 0 and white to 1.
; Thus if we clear all but bit 0 the color will be either black or white, alternating infinitely regardless of the actual value
; of the color variable.
 
sta $0200,x
inc color
inx
bne loop_1wide
 
loop_2wide:
lda color
and #$01
sta $0300,x
inx
sta $0300,x
inc color
inx
bne loop_2wide
 
lda #1
sta color
lda #0
tax
tay
sta looptemp ;reset regs
 
loop_3wide:
lda color
and #$01
sta $0400,x
inc looptemp
inx
 
sta $0400,x
inc looptemp
inx
 
sta $0400,x
inc looptemp
inc color
inx
 
lda looptemp
cmp #$1e
bne loop_3wide
 
lda color ;loop overhead
and #$01
sta $0400,x ;can't fit all of this stripe.
;two columns will have to do.
inx
lda color
and #$01
sta $0400,x
inx
 
lda #1
sta color
lda #0
sta looptemp ;reset color and looptemp
iny
cpy #$08 ;check secondary loop counter
bne loop_3wide
 
lda #1
sta color
lda #0
tax
tay
sta looptemp
 
loop_4wide:
lda color
and #$01
sta $0500,x
inx
inc looptemp
 
sta $0500,x
inx
inc looptemp
 
sta $0500,x
inx
inc looptemp
 
sta $0500,x
inc color
inc looptemp
inx
 
lda looptemp
cmp #$20
bne loop_4wide
lda #0
sta looptemp
lda #1
sta color
 
iny
cpy #$8
bcc loop_4wide
 
brk ;program end</syntaxhighlight>
 
=={{header|8086 Assembly}}==
<langsyntaxhighlight lang="asm"> ;;; Display pinstripes on a PC, using 8086 assembly.
;;; The 640x200 CGA video mode is used. If you are on an MDA, the
;;; program does not run.
Line 89 ⟶ 208:
section .bss
oldmod: resb 1 ; place to keep old video mode, in order to
; restore it. </langsyntaxhighlight>
 
 
=={{header|Action!}}==
<syntaxhighlight lang="action!">PROC Main()
BYTE
CH=$02FC, ;Internal hardware value for last key pressed
COLOR0=$02C4,COLOR1=$02C5,COLOR2=$02C6,COLOR4=$02C8
CARD i
Graphics(8+16)
COLOR4=$04 ;gray
COLOR1=$00 ;black
COLOR2=$0F ;white
 
FOR i=0 TO 319
DO
Color=i MOD 2
Plot(i,0) DrawTo(i,47)
 
Color=i/2 MOD 2
Plot(i,48) DrawTo(i,95)
 
Color=i/3 MOD 2
Plot(i,96) DrawTo(i,143)
 
Color=i/4 MOD 2
Plot(i,144) DrawTo(i,191)
OD
 
DO UNTIL CH#$FF OD
CH=$FF
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Pinstripe_display.png Screenshot from Atari 8-bit computer]
 
=={{header|ActionScript}}==
<syntaxhighlight lang="actionscript3">
<lang ActionScript3>
package {
Line 146 ⟶ 298:
 
}
</syntaxhighlight>
</lang>
 
=={{header|Ada}}==
{{libheader|SDLAda}}
<langsyntaxhighlight Adalang="ada">with SDL.Video.Windows.Makers;
with SDL.Video.Renderers.Makers;
with SDL.Events.Events;
Line 217 ⟶ 369:
Window.Finalize;
SDL.Finalise;
end Pinstripe_Display;</langsyntaxhighlight>
 
=={{header|AutoHotkey}}==
Requires the GDI+ standard library: http://www.autohotkey.com/forum/viewtopic.php?t=32238<br/>
It is worth noting that this fills the whole screen; press Esc to exit.
<langsyntaxhighlight AHKlang="ahk">h := A_ScreenHeight
w := A_ScreenWidth
pToken := Gdip_Startup()
Line 261 ⟶ 413:
Exit:
Gdip_Shutdown(pToken)
ExitApp</langsyntaxhighlight>
 
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<langsyntaxhighlight lang="bbcbasic"> GWL_STYLE = -16
HWND_TOPMOST = -1
WS_VISIBLE = &10000000
Line 289 ⟶ 441:
FOR X% = 0 TO xscreen%*4-16 STEP 16
RECTANGLE FILL X%,yscreen%*0/2,8,yscreen%/2
NEXT</langsyntaxhighlight>
 
=={{header|Befunge}}==
Line 297 ⟶ 449:
The dimensions of the image are specified by the first two values on the stack: 1366 (<tt>"%":*3-</tt>) by 768 (<tt>"`"8*</tt>).
 
<langsyntaxhighlight lang="befunge">"%":*3-"`"8*>4/::8%00p8/10p4*\55+"1P",,v
,:.\.5vv-g025:\-1_$$55+,\:v1+*8g01g00_@>
024,+5<>/2%.1+\:>^<:\0:\-1_$20g1-:20p^1p</langsyntaxhighlight>
 
=={{header|C}}==
This code is only a slight variation of my [http://rosettacode.org/wiki/Colour_pinstripe/Display#C Colour Pinstripe C code]. It also uses Borland's Turbo C graphics library.
 
<syntaxhighlight lang="c">
<lang C>
#include<graphics.h>
#include<conio.h>
Line 332 ⟶ 484:
return 0;
}
</syntaxhighlight>
</lang>
 
=={{header|C sharp}}==
Line 338 ⟶ 490:
Using System.Drawing, and writing the output to a file.
 
<langsyntaxhighlight lang="csharp">
using System.Drawing;
 
Line 368 ⟶ 520:
}
}
</syntaxhighlight>
</lang>
 
=={{header|C++}}==
[[File:bw_pinstripe_cpp.png|300px]]
<langsyntaxhighlight lang="cpp">
#include <windows.h>
 
Line 490 ⟶ 642:
}
//--------------------------------------------------------------------------------------------------
</syntaxhighlight>
</lang>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
 
<syntaxhighlight lang="Delphi">
 
procedure DrawVerticalStripes(Image: TImage; PenWidth,Top,Bottom: integer);
{Draw vertical stripes across full width of image}
{Top/Bottom Control the position of the band of stripes}
{PenWidth controls width of the line drawn}
var X,X2,Y: integer;
begin
Image.Canvas.Pen.Width:=PenWidth;
for X:=0 to (Image.Width div PenWidth)-1 do
begin
if (X mod 2)=0 then Image.Canvas.Pen.Color:=clWhite
else Image.Canvas.Pen.Color:=clBlack;
X2:=X * PenWidth;
Image.Canvas.MoveTo(X2,Top);
Image.Canvas.LineTo(X2,Bottom);
end;
end;
 
procedure ShowVerticalStripes(Image: TImage);
{Draw all four bands of stripes}
var SHeight: integer;
var I: integer;
begin
SHeight:=Image.Height div 4;
for I:=0 to 4-1 do
begin
DrawVerticalStripes(Image,I+1,SHeight*I,SHeight*(I+1));
end;
end;
 
 
</syntaxhighlight>
{{out}}
[[File:DelphiPinstripes.png|thumb|none]]
<pre>
Elapsed Time: 26.113 ms.
</pre>
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">' version 14-03-2017
' compile with: fbc -s console
' or compile with: fbc -s gui
Line 519 ⟶ 715:
'Print : Print "hit any key to end program"
Sleep
End</langsyntaxhighlight>
 
=={{header|Gambas}}==
<langsyntaxhighlight lang="gambas">'WARNING this takes a time to display
'Use the 'gb.qt4' component
 
Line 549 ⟶ 745:
Next
End</langsyntaxhighlight>
 
'''[http://www.cogier.com/gambas/Pinstripe.png Click here for an image of the output]'''
Line 556 ⟶ 752:
{{libheader|Go Graphics}}
The code here is the same as that for the [https://rosettacode.org/wiki/Colour_pinstripe/Display#Go Color pinstripe task] except that the palette is limited to the two colors, white and black.
<langsyntaxhighlight lang="go">package main
 
import "github.com/fogleman/gg"
Line 582 ⟶ 778:
pinstripe(dc)
dc.SavePNG("w_pinstripe.png")
}</langsyntaxhighlight>
 
{{out}}
Line 591 ⟶ 787:
=={{header|Icon}} and {{header|Unicon}}==
Icon and Unicon can't access the screen directly, so this pinstripe is produced in a maximal sized window. The maximal dimensions have been empirically reduced to keep the boundary on the screen.
<langsyntaxhighlight Iconlang="icon">link graphics
procedure main() # pinstripe
Line 613 ⟶ 809:
}
WDone(W) # q to exit
end</langsyntaxhighlight>
 
{{libheader|Icon Programming Library}}
Line 620 ⟶ 816:
=={{header|J}}==
 
<langsyntaxhighlight lang="j"> load'viewmat'
NB. size=. 2{.".wd'qm' NB. J6
NB. size=. getscreenwh_jgtk_ '' NB. J7
size=. 3{".wd'qscreen' NB. J8
'rgb'viewmat- (4<.@%~{:size)# ({.size) $&> 1 2 3 4#&.> <0 1</langsyntaxhighlight>
 
=={{header|Java}}==
<langsyntaxhighlight lang="java">import java.awt.*;
import javax.swing.*;
 
Line 664 ⟶ 860:
});
}
}</langsyntaxhighlight>
 
=={{header|Julia}}==
In the Luxor module, the setline() function sets the line width in pixels, which is convenient for pinstriping.
<langsyntaxhighlight lang="julia">
using Luxor
 
Line 689 ⟶ 885:
finish()
preview()
</syntaxhighlight>
</lang>
 
=={{header|Kotlin}}==
{{trans|Java}}
<langsyntaxhighlight lang="scala">// version 1.1.0
 
import java.awt.*
Line 733 ⟶ 929:
f.setVisible(true)
}
}</langsyntaxhighlight>
 
=={{header|Lambdatalk}}==
Using HTML+CSS
<syntaxhighlight lang="scheme">
{def window
{lambda {:w :h}
div
{@ style="position:relative;
top:0; left:0;
width::wpx; height::hpx;
background:#eee;"}}}
-> window
 
{def rec
{lambda {:x :y :w :h :c}
{div
{@ style="position:absolute;
top::ypx; left::xpx;
width::wpx; height::hpx;
background::c;"}}}}
-> rec
 
{def row
{lambda {:w :h :k}
{S.map {{lambda {:dx :dy :h :i}
{rec :i :dy :dx :h #000}
{rec {+ :i :dx} :dy :dx :h #fff}
} {pow 2 :k} {* :k {/ :w 8}} {/ :h 4}}
{S.serie 0 {- :w 1} {pow 2 {+ :k 1}}}}}}
-> row
 
{def WIDTH 512}
-> WIDTH
{def HEIGHT 256}
-> HEIGHT
 
{{window {WIDTH} {WIDTH}}
{S.map {row {WIDTH} {HEIGHT}}
0 1 2 3}}
</syntaxhighlight>
Output visible in http://lambdaway.free.fr/lambdawalks/?view=color_bar_display
 
=={{header|Liberty BASIC}}==
Fills whole screen; use Alt-F4 to close program.
<syntaxhighlight lang="lb">
<lang lb>
nomainwin
 
Line 764 ⟶ 1,001:
close #gr
end
</syntaxhighlight>
</lang>
 
=={{header|Locomotive Basic}}==
 
<langsyntaxhighlight lang="locobasic">10 MODE 2 ' finest resolution
20 sh=400 ' screen height
30 sw=640 ' screen width
Line 787 ⟶ 1,024:
180 IF dc>1 THEN dc=0
190 NEXT l
200 NEXT sn</langsyntaxhighlight>
 
=={{header|Lua}}==
{{libheader|LÖVE}}
{{works with|LÖVE|11.3}}
<langsyntaxhighlight lang="lua">
function love.load()
WIDTH = love.graphics.getWidth()
Line 811 ⟶ 1,048:
end
end
</syntaxhighlight>
</lang>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">color[y_] := {White, Black}[[Mod[y, 2] + 1]];
Graphics[Join[{Thickness[1/408]},
Flatten[{color[#], Line[{{# - 1/2, 408}, {# - 1/2, 307}}]} & /@
Line 823 ⟶ 1,060:
Range[136]], {Thickness[1/102]},
Flatten[{color[#], Line[{{4 # - 2, 102}, {4 # - 2, 1}}]} & /@
Range[102]]], ImageSize -> {408, 408}]</langsyntaxhighlight>
{{out}}
See [https://www.dropbox.com/s/2ukd07ja3ubyjma/Mathematica_Pinstripes.png?dl=0 here].
 
=={{header|Nim}}==
{{libheader|gintro}}
The code is almost the same as for [[https://rosettacode.org/wiki/Colour_pinstripe/Display#Nim Color pinstripe task]].
<syntaxhighlight lang="nim">import gintro/[glib, gobject, gtk, gio, cairo]
 
const
Width = 420
Height = 420
 
const Colors = [[255.0, 255.0, 255.0], [0.0, 0.0, 0.0]]
 
#---------------------------------------------------------------------------------------------------
 
proc draw(area: DrawingArea; context: Context) =
## Draw the bars.
 
const lineHeight = Height div 4
 
var y = 0.0
for lineWidth in [1.0, 2.0, 3.0, 4.0]:
context.setLineWidth(lineWidth)
var x = 0.0
var colorIndex = 0
while x < Width:
context.setSource(Colors[colorIndex])
context.moveTo(x, y)
context.lineTo(x, y + lineHeight)
context.stroke()
colorIndex = 1 - colorIndex
x += lineWidth
y += lineHeight
 
#---------------------------------------------------------------------------------------------------
 
proc onDraw(area: DrawingArea; context: Context; data: pointer): bool =
## Callback to draw/redraw the drawing area contents.
 
area.draw(context)
result = true
 
#---------------------------------------------------------------------------------------------------
 
proc activate(app: Application) =
## Activate the application.
 
let window = app.newApplicationWindow()
window.setSizeRequest(Width, Height)
window.setTitle("Color pinstripe")
 
# Create the drawing area.
let area = newDrawingArea()
window.add(area)
 
# Connect the "draw" event to the callback to draw the bars.
discard area.connect("draw", ondraw, pointer(nil))
 
window.showAll()
 
#———————————————————————————————————————————————————————————————————————————————————————————————————
 
let app = newApplication(Application, "Rosetta.Pinstripe")
discard app.connect("activate", activate)
discard app.run()</syntaxhighlight>
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">use Imager;
 
my($xsize,$ysize) = (640,400);
Line 846 ⟶ 1,147:
}
 
$img->write(file => 'pinstripes-bw.png');</langsyntaxhighlight>
[https://github.com/SqrtNegInf/Rosettacode-Perl5-Smoke/blob/master/ref/pinstripes-bw.png Pinstripes] (offsite image)
 
=={{header|Phix}}==
<!--(phixonline)-->
Just change [http://rosettacode.org/wiki/Colour_pinstripe/Display#Phix Colour Pinstripe] such that colours = {CD_BLACK, CD_WHITE}
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(let Pbm # Create PBM of 384 x 288 pixels
(make
(for N 4
Line 866 ⟶ 1,168:
(prinl "P1")
(prinl (length (car Pbm)) " " (length Pbm))
(mapc prinl Pbm) ) )</langsyntaxhighlight>
 
=={{header|PureBasic}}==
<langsyntaxhighlight PureBasiclang="purebasic">#White = $FFFFFF ;color
 
;Create a Pinstripe image
Line 898 ⟶ 1,200:
While WaitWindowEvent() <> #PB_Event_CloseWindow
Wend
EndIf</langsyntaxhighlight>
 
=={{header|Python}}==
<syntaxhighlight lang="python">
<lang Python>
#Python task for Pinstripe/Display
#Tested for Python2.7 by Benjamin Curutchet
Line 958 ⟶ 1,260:
im.save('PictureResult.jpg')
 
</syntaxhighlight>
</lang>
 
=={{header|Quackery}}==
 
Adapted from [[Colour pinstripe/Display#Quackery]].
 
<syntaxhighlight lang="Quackery"> [ $ "turtleduck.qky" loadfile ] now!
 
[ 1280 ] is width ( --> n )
[ 720 ] is height ( --> n )
 
[ 0 0 0 ] is black ( --> n n n )
[ 255 255 255 ] is white ( --> n n n )
 
[ [] swap
' [ black white ]
witheach
[ over times
[ dip swap tuck
nested join
unrot ]
drop ]
drop ] is colours ( n --> [ )
 
[ behead
dup dip
[ nested join ] ] is nextcolour ( [ --> [ [ )
 
[ nextcolour colour
-1 4 turn
height n->v
4 n->v v/ 2dup walk
-v fly
1 4 turn
1 n->v fly ] is stripe ( [ --> [ )
 
[ turtle
50 frames
width n->v 2 1 v/ fly
-1 4 turn
height n->v 2 1 v/ fly
-1 4 turn
4 times
[ i^ 1+ colours
width times stripe
drop
width n->v -v fly
-1 4 turn
height n->v
4 n->v v/ fly
1 4 turn ]
1 frames ] is pinstripes ( --> )</syntaxhighlight>
 
{{out}}
 
[[File:Quackery pinstripes.png|thumb|center]]
 
=={{header|Racket}}==
(As usual with Racket, this code works on all platforms.)
<syntaxhighlight lang="racket">
<lang Racket>
#lang racket/gui
 
Line 990 ⟶ 1,347:
 
(void (new full-frame%))
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
{{Works with|rakudo|2018.10}}
<syntaxhighlight lang="raku" perl6line>my ($x,$y) = 1280,720;
my @colors = 0, 1;
 
Line 1,014 ⟶ 1,371:
}
 
$img.close;</langsyntaxhighlight>
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project : Pinstripe/Display
 
Line 1,079 ⟶ 1,436:
label1 { setpicture(p1) show() }
return
</syntaxhighlight>
</lang>
Output:
 
Line 1,086 ⟶ 1,443:
=={{header|Scala}}==
===Java Swing Interoperability===
<langsyntaxhighlight Scalalang="scala">import java.awt._
 
import javax.swing._
Line 1,122 ⟶ 1,479:
})
 
}</langsyntaxhighlight>
 
=={{header|Sinclair ZX81 BASIC}}==
Line 1,128 ⟶ 1,485:
 
The ZX81's graphics resolution is only 64x44, so this is quite a blocky pinstripe. It would be 64x48, in fact; but a strip along the bottom of the screen is reserved for system messages and user input and cannot be made available for other purposes (at least not from BASIC).
<langsyntaxhighlight lang="basic">10 FOR W=1 TO 4
20 FOR I=0 TO 63 STEP 2*W
30 FOR J=1 TO W
Line 1,136 ⟶ 1,493:
70 NEXT J
80 NEXT I
90 NEXT W</langsyntaxhighlight>
{{out}}
Screenshot [http://www.edmundgriffiths.com/zx81pinstripe.jpg here].
Line 1,142 ⟶ 1,499:
=={{header|Tcl}}==
{{libheader|Tk}}
<langsyntaxhighlight lang="tcl">package require Tcl 8.5
package require Tk 8.5
Line 1,158 ⟶ 1,515:
}
incr y $dy
}</langsyntaxhighlight>
 
=={{header|Wren}}==
{{trans|Go}}
{{libheader|DOME}}
<langsyntaxhighlight ecmascriptlang="wren">import "graphics" for Canvas, Color
import "dome" for Window
 
Line 1,198 ⟶ 1,555:
 
static draw(dt) {}
}</langsyntaxhighlight>
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">include c:\cxpl\codes; \include 'code' declarations
int X, Y, W, C;
[SetVid($13); \320x200x8 graphics
Line 1,214 ⟶ 1,571:
X:= ChIn(1); \wait for keystroke
SetVid(3); \restore normal text display
]</langsyntaxhighlight>
 
Output: [[File:PinsXPL0.png]]
Line 1,225 ⟶ 1,582:
it and fills the whole screen with twice as many lines.
 
<langsyntaxhighlight lang="z80"> ;;; Display pinstripes on an MSX, using Z80 assembly.
;;; We'll use the monochrome 'text' mode to do it, by changing
;;; a few characters in the VDP font. This program will use
Line 1,379 ⟶ 1,736:
;;; Patterns to replace the first characters with
pats: db onep,twop1,twop2,threep
db fourp1,fourp2,fourp3,fourp4</langsyntaxhighlight>
 
{{omit from|Blast}}
9,476

edits