This commit is contained in:
Ingy döt Net 2013-04-10 21:29:02 -07:00
parent 764da6cbbb
commit db842d013d
19005 changed files with 197040 additions and 7 deletions

View file

@ -0,0 +1,7 @@
The task is to display a series of vertical greyscale bars (contrast bars) with a sufficient number of bars to span the entire width of the display.
For the top quarter of the display, the left hand bar should be black, and we then incrementally step through six shades of grey until we have a white bar on the right hand side of the display. (This gives a total of 8 bars)
For the second quarter down, we start with white and step down through 14 shades of gray, getting darker until we have black on the right hand side of the display. (This gives a total of 16 bars).
Halfway down the display, we start with black, and produce 32 bars, ending in white, and for the last quarter, we start with white and step through 62 shades of grey, before finally arriving at black in the bottom right hand corner, producing a total of 64 bars for the bottom quarter.

View file

@ -0,0 +1,3 @@
---
category:
- Test card

View file

@ -0,0 +1,26 @@
package
{
import flash.display.Sprite;
[SWF(width="640", height="480")]
public class GreyscaleBars extends Sprite
{
public function GreyscaleBars()
{
_drawRow(8, 0);
_drawRow(16, stage.stageHeight/4, true);
_drawRow(32, stage.stageHeight/2);
_drawRow(64, stage.stageHeight/4 * 3, true);
}
private function _drawRow(nbSteps : uint, startingY : uint, reverse : Boolean = false) : void {
for (var i : int = 0; i < nbSteps; i++) {
graphics.beginFill(0x00, reverse ? 1 - (i/nbSteps) : (i/nbSteps));
graphics.drawRect(i * stage.stageWidth / nbSteps, startingY, stage.stageWidth/nbSteps, stage.stageHeight/4);
graphics.endFill();
}
}
}
}

View file

@ -0,0 +1,85 @@
with Gtk.Window; use Gtk.Window;
with Gtk.Enums;
with Gtk.Handlers;
with Gtk.Main;
with Gdk;
with Gdk.Event;
with Glib; use Glib;
with Cairo; use Cairo;
with Gdk.Cairo;
pragma Elaborate_All (Gtk.Handlers);
procedure Greyscale is
Win : Gtk_Window;
Width : constant := 640;
Height : constant := 512;
package Handlers is new Gtk.Handlers.Callback (Gtk_Window_Record);
package Event_Cb is new Gtk.Handlers.Return_Callback (
Widget_Type => Gtk_Window_Record,
Return_Type => Boolean);
procedure Quit (Win : access Gtk_Window_Record'Class) is
pragma Warnings (Off, Win);
begin
Gtk.Main.Main_Quit;
end Quit;
function Expose
(Drawing : access Gtk_Window_Record'Class;
Event : Gdk.Event.Gdk_Event)
return Boolean
is
subtype Dub is Glib.Gdouble;
Cr : Cairo_Context;
Revert : Boolean;
Grey : Dub;
DH : constant Dub := Dub (Height) / 4.0;
X, Y, DW : Dub;
N : Natural;
begin
Cr := Gdk.Cairo.Create (Get_Window (Drawing));
for Row in 1 .. 4 loop
N := 2 ** (Row + 2);
Revert := (Row mod 2) = 0;
DW := Dub (Width) / Dub (N);
X := 0.0;
Y := DH * Dub (Row - 1);
for B in 0 .. (N - 1) loop
Grey := Dub (B) / Dub (N - 1);
if Revert then
Grey := 1.0 - Grey;
end if;
Cairo.Set_Source_Rgb (Cr, Grey, Grey, Grey);
Cairo.Rectangle (Cr, X, Y, DW, DH);
Cairo.Fill (Cr);
X := X + DW;
end loop;
end loop;
Cairo.Destroy (Cr);
return False;
end Expose;
begin
Gtk.Main.Set_Locale;
Gtk.Main.Init;
Gtk_New (Win);
Gtk.Window.Initialize (Win, Gtk.Enums.Window_Toplevel);
Set_Title (Win, "Greyscale with GTKAda");
Set_Default_Size (Win, Width, Height);
Set_App_Paintable (Win, True);
-- Attach handlers
Handlers.Connect (Win, "destroy", Handlers.To_Marshaller (Quit'Access));
Event_Cb.Connect
(Win,
"expose_event",
Event_Cb.To_Marshaller (Expose'Access));
Show_All (Win);
Gtk.Main.Main;
end Greyscale;

View file

@ -0,0 +1,56 @@
h := A_ScreenHeight
w := A_ScreenWidth
pToken := gdip_Startup()
hdc := CreateCompatibleDC()
hbm := CreateDIBSection(w, h)
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)
OnExit, Exit
Gui +E0x80000 +LastFound +OwnDialogs +Owner +AlwaysOnTop
hwnd := WinExist()
Gui Show, NA
columnHeight := h/4
Loop 4
{
columnY := (A_Index-1) * columnHeight
columnCount := 2**(A_Index+2)
colorgap := 255 / (columnCount-1)
columnWidth := w/ColumnCount
If (A_Index & 1)
colorComp := 0
else
colorComp := 255
,colorgap *= -1
MsgBox % colorGap * columnCount
Loop % columnCount
{
columnX := (A_Index-1) * columnWidth
pBrush := Gdip_BrushCreateSolid(QColor(colorComp, colorComp, colorComp))
Gdip_FillRectangle(G, pBrush, columnX, columnY, columnWidth, columnHeight)
Gdip_DeleteBrush(pBrush)
colorComp += colorgap
}
SetFormat, IntegerFast, hex
SetFormat, IntegerFast, D
}
UpdateLayeredWindow(hwnd, hdc, 0, 0, W, H)
SelectObject(hdc, obm)
DeleteObject(hbm)
DeleteDC(hdc)
Gdip_DeleteGraphics(G)
Return
Esc::
Exit:
Gdip_Shutdown(pToken)
ExitApp
QColor(r, g, b){
return 0xFF000000 | (r << 16) | (g << 8) | (b)
}

View file

@ -0,0 +1,10 @@
h=ceil(graphheight/4)
for row=1 to 4
w=ceil(graphwidth/(8*row))
c=255/(8*row-1)
for n = 0 to (8*row-1)
color 255-c*n,255-c*n,255-c*n
if row/2 = int(row/2) then color c*n,c*n,c*n
rect n*w,h*(row-1),w,h
next n
next row

View file

@ -0,0 +1,14 @@
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
GCOL 1 :REM Select colour one for drawing
FOR row%=1 TO 4
n%=2^(row%+2)
w%=1280/n%
py%=256*(4-row%)
FOR b%=0 TO n%-1
g%=255*b%/(n%-1)
IF n%=16 OR n%=64 THEN g%=255-g%
COLOUR 1,g%,g%,g% : REM Reprogram colour 1 to the grey we want
RECTANGLE FILL w%*b%,py%,w%,256
NEXT b%
NEXT row%

View file

@ -0,0 +1,14 @@
#ifndef MYWIDGET_H
#define MYWIDGET_H
#include <QWidget>
class QPaintEvent ;
class MyWidget : public QWidget {
public :
MyWidget( ) ;
protected :
void paintEvent( QPaintEvent * ) ;
} ;
#endif

View file

@ -0,0 +1,34 @@
#include <QtGui>
#include "greytones.h"
MyWidget::MyWidget( ) {
setGeometry( 0, 0 , 640 , 480 ) ;
}
void MyWidget::paintEvent ( QPaintEvent * ) {
QBrush myBrush( Qt::SolidPattern ) ;
QPainter myPaint( this ) ;
int run = 0 ; //how often have we run through the loop ?
int colorcomp = 0 ;
for ( int columncount = 8 ; columncount < 128 ; columncount *= 2 ) {
int colorgap = 255 / columncount ;
int columnwidth = 640 / columncount ; // 640 being the window width
int columnheight = 480 / 4 ; //we're looking at quarters
if ( run % 2 == 0 ) { //we start with black columns
colorcomp = 0 ;
}
else { //we start with white columns
colorcomp = 255 ;
colorgap *= -1 ; //we keep subtracting color values
}
int ystart = 0 + columnheight * run ; //determines the y coordinate of the first column per row
int xstart = 0 ;
for ( int i = 0 ; i < columncount ; i++ ) {
myBrush.setColor( QColor( colorcomp, colorcomp , colorcomp ) ) ;
myPaint.fillRect( xstart , ystart , columnwidth , columnheight , myBrush ) ;
xstart += columnwidth ;
colorcomp += colorgap ; //we choose the next color
}
run++ ;
}
}

View file

@ -0,0 +1,10 @@
#include <QApplication>
#include "greytones.h"
int main( int argc, char * argv[ ] ) {
QApplication app( argc , argv ) ;
MyWidget window ;
window.setWindowTitle( QApplication::translate( "greyScales" , "grey scales demonstration" ) ) ;
window.show( ) ;
return app.exec( ) ;
}

View file

@ -0,0 +1,35 @@
#include <gtk/gtk.h>
/* do some greyscale plotting */
void gsplot (cairo_t *cr,int x,int y,double s) {
cairo_set_source_rgb (cr,s,s,s);
cairo_move_to (cr,x+0.5,y);
cairo_rel_line_to (cr,0,1);
cairo_stroke (cr);
}
/* make a shaded widget */
gboolean expose_event (GtkWidget *widget,GdkEventExpose *event,gpointer data) {
int r,c,x=0;
cairo_t *cr;
cr = gdk_cairo_create (widget->window);
cairo_scale (cr,5,50);
cairo_set_line_width (cr,1);
for (r=0;r<4;r++) {
c = (r&1)*64-(r%2);
do gsplot (cr,x++%64,r,c/(1<<(3-r))/(8*(1<<r)-1.0));
while ((c+=2*!(r%2)-1)!=(!(r%2))*64-(r%2));
} cairo_destroy (cr);
return FALSE;
}
/* main */
int main (int argc, char *argv[]) {
GtkWidget *window;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (window, "expose-event",G_CALLBACK (expose_event), NULL);
g_signal_connect (window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
gtk_window_set_default_size (GTK_WINDOW(window), 320, 200);
gtk_widget_set_app_paintable (window, TRUE);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}

View file

@ -0,0 +1,20 @@
>function grayscale(y1,y2,n,direction=1) ...
$ loop 0 to n-1;
$ s=#/(n-1); barcolor(rgb(s,s,s));
$ if direction==1 then plotbar(#/n,y1,1/n,y2-y1);
$ else plotbar(1-(#+1)/n,y1,1/n,y2-y1);
$ endif;
$ end;
$endfunction
>function grayscales () ...
$ aspect(2); barstyle("#");
$ window(0,0,1023,1023); margin(0); setplot(0,1,0,1);
$ clg;
$ hold on;
$ grayscale(3/4,1,8,1);
$ grayscale(1/2,3/4,14,-1);
$ grayscale(1/4,1/2,32,1);
$ grayscale(0,1/4,64,-1);
$ hold off;
$endfunction
>grayscales:

View file

@ -0,0 +1,58 @@
import Graphics.UI.Gtk
import Graphics.UI.Gtk.Gdk.GC
import Control.Monad.Trans (liftIO)
-- click on the window to exit.
main = do
initGUI
window <- windowNew
buf <- pixbufNewFromXPMData bars
widgetAddEvents window [ButtonPressMask]
on window objectDestroy mainQuit
on window exposeEvent (paint buf)
on window buttonPressEvent $
liftIO $ do { widgetDestroy window; return True }
windowFullscreen window
widgetShowAll window
mainGUI
paint :: Pixbuf -> EventM EExpose Bool
paint buf = do
pix <- eventWindow
liftIO $ do
(sx, sy) <- drawableGetSize pix
newBuf <- pixbufScaleSimple buf sx sy InterpNearest
gc <- gcNewWithValues pix newGCValues
drawPixbuf pix gc newBuf 0 0 0 0 (-1) (-1) RgbDitherNone 0 0
return True
bars :: [String]
bars = [
"64 4 65 1 1 1"," c None","A c #000000",
"C c #080808","D c #0C0C0C","E c #101010","F c #141414",
"G c #181818","H c #1C1C1C","I c #202020","J c #242424",
"K c #282828","L c #2C2C2C","M c #303030","N c #343434",
"O c #383838","P c #3C3C3C","Q c #404040","R c #444444",
"S c #484848","T c #4C4C4C","U c #505050","V c #545454",
"W c #585858","X c #5C5C5C","Y c #606060","Z c #646464",
"a c #686868","b c #6C6C6C","c c #707070","d c #747474",
"e c #787878","f c #7C7C7C","g c #808080","h c #848484",
"i c #888888","j c #8C8C8C","k c #909090","l c #949494",
"m c #989898","n c #9C9C9C","o c #A0A0A0","p c #A4A4A4",
"q c #A8A8A8","r c #ACACAC","s c #B0B0B0","t c #B4B4B4",
"u c #B8B8B8","v c #BCBCBC","w c #C0C0C0","x c #C4C4C4",
"y c #C8C8C8","z c #CCCCCC","0 c #D0D0D0","1 c #D4D4D4",
"2 c #D8D8D8","3 c #DCDCDC","4 c #E0E0E0","5 c #E4E4E4",
"6 c #E8E8E8","7 c #ECECEC","8 c #F0F0F0","9 c #F4F4F4",
". c #F8F8F8","+ c #FCFCFC","* c #FFFFFF",
"AAAAAAAAJJJJJJJJRRRRRRRRZZZZZZZZhhhhhhhhppppppppxxxxxxxx********",
"****88881111xxxxttttppppllllhhhhddddZZZZVVVVRRRRNNNNJJJJFFFFAAAA",
"AADDFFHHJJLLNNPPRRTTVVXXZZbbddffhhjjllnnpprrttvvxxzz11336688..**",
"*+.9876543210zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCA"
]

View file

@ -0,0 +1,31 @@
link graphics,printf,numbers
procedure main()
DrawTestCard(GreyScale_TestCard())
WDone()
end
procedure greyscale(l,h,s) #: generate s greys over range l:h
every i := round(l to h+1 by ((h-l)/(s-1.))) do
suspend sprintf("%d,%d,%d",i,i,i) # return rgb black-grey-white
end
procedure GreyScale_TestCard() #: return greyscale testcard
TC := testcard(,"GreyScale Test Card",
width := 800, height := 600,
list(numbands := 4) )
maxv := 2^16-1 # largest colour value
every (iv := [], i := 1 to numbands) do { # for each band
every put(v := [], greyscale(0,maxv,2^(2+i))) # compute greyscale
put(iv, if i%2 = 0 then v else reverse(v)) # switch directions
}
every r := height/numbands * ((i := 1 to numbands)-1) + 1 do {
TC.bands[i] := band(r,[])
every c := width/(*iv[i]) * ((j := 1 to *iv[i])-1) + 1 do
put(TC.bands[i].bars, bar( c, iv[i,j]))
put((TC.bands[i]).bars, bar(width)) # right sentinal
}
put(TC.bands,band(height)) # bottom sentinal
return TC
end

View file

@ -0,0 +1,7 @@
load 'viewmat'
size=. 2{.".wd'qm' NB. J6
size=. getscreenwh_jgtk_ '' NB. J7
rows=. (2^3+i.4),._1^i.4
bars=. ((64%{.)#[:(<:@|%~i.)*/)"1 rows
togreyscale=. (256#. [:<.255 255 255&*)"0
'rgb' viewmat (4<.@%~{:size)# (64<.@%~{.size)#"1 togreyscale bars

View file

@ -0,0 +1,46 @@
import javax.swing.* ;
import java.awt.* ;
public class Greybars extends JFrame {
private int width ;
private int height ;
public Greybars( ) {
super( "grey bars example!" ) ;
width = 640 ;
height = 320 ;
setSize( width , height ) ;
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ) ;
setVisible( true ) ;
}
public void paint ( Graphics g ) {
int run = 0 ;
int colorcomp = 0 ; //component of the color
for ( int columncount = 8 ; columncount < 128 ; columncount *= 2 ) {
int colorgap = 255 / columncount ; //by this gap we change the background color
int columnwidth = width / columncount ;
int columnheight = height / 4 ;
if ( run % 2 == 0 ) //switches color directions with every for loop
colorcomp = 0 ;
else {
colorcomp = 255 ;
colorgap *= -1 ;
}
int ystart = 0 + columnheight * run ;
int xstart = 0 ;
for ( int i = 0 ; i < columncount ; i++ ) {
Color nextColor = new Color( colorcomp, colorcomp, colorcomp ) ;
g.setColor( nextColor ) ;
g.fillRect( xstart , ystart , columnwidth , columnheight ) ;
xstart += columnwidth ;
colorcomp += colorgap ;
}
run++ ;
}
}
public static void main( String[ ] args ) {
Greybars gb = new Greybars( ) ;
}
}

View file

@ -0,0 +1,29 @@
<html><body>
<script type="text/javascript">
var width = 640; var height = 400;
var c = document.createElement("canvas");
c.setAttribute('id', 'myCanvas');
c.setAttribute('style', 'border:1px solid black;');
c.setAttribute('width', width);
c.setAttribute('height', height);
document.body.appendChild(c);
var ctx = document.getElementById('myCanvas').getContext("2d");
var columnCount = 8; // number of columns
var rowCount = 4; // number of rows
var direction = 1; // 1 = from left to right, 0 = from right to left
var blackLeft = 1; // black is left: 1 = true, 0 = false
for(var j = 0; j < rowCount; j++){
for(var i = 0; i < columnCount; i++){
ctx.fillStyle = 'rgba(0,0,0,'+ (blackLeft-(1/(columnCount-1)*i))*direction +')';
ctx.fillRect(
(width/columnCount)*i,(height/rowCount)*j,
(width/columnCount),(height/rowCount)
);
}
columnCount *= 2;
direction *= -1;
blackLeft = blackLeft ? 0 : 1;
}
</script>
</body></html>

View file

@ -0,0 +1,31 @@
nomainwin
WindowWidth =DisplayWidth
WindowHeight =DisplayHeight
open "Grey bars" for graphics_fs_nsb as #w
#w "trapclose [quit]"
#w "down"
bars =4 ' alter for more, finer bars.
for group =0 to bars -1
for i = 0 to 2^( 3 +group) -1
#w "place "; WindowWidth *i /( 2^( 3 +group)); " "; WindowHeight *group /bars
if ( group =0) or ( group =2) then
g$ =str$( int( 255 *i /(2^( 3 +group)-1)))
else
g$ =str$( 255 -int( 255 *i /(2^( 3 +group)-1)))
end if
grey$ =g$ +" " +g$ +" " +g$
#w "backcolor "; grey$
'#w "color "; grey$ 'rem out for outlined areas..
#w "boxfilled "; WindowWidth *( i +1) /8 ; " "; WindowHeight *( group +1) /bars
next i
next group
wait
[quit]
close #w
end

View file

@ -0,0 +1,5 @@
CreateDocument[ Graphics[ Flatten@Table[
{ If[EvenQ[#3], GrayLevel[ 1. - j/#1 ], GrayLevel[ j/#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} }
,ImageSize -> Full], WindowFrame -> "Frameless", WindowSize -> Full]

View file

@ -0,0 +1,16 @@
(let Pgm # Create PGM of 384 x 288 pixels
(make
(for N 4
(let L
(make
(for I (* N 8)
(let C (*/ (dec I) 255 (dec (* N 8)))
(unless (bit? 1 N)
(setq C (- 255 C)) )
(do (/ 48 N) (link C)) ) ) )
(do 72 (link L)) ) ) )
(out '(display) # Pipe to ImageMagick
(prinl "P5") # NetPBM format
(prinl (length (car Pgm)) " " (length Pgm))
(prinl 255)
(for Y Pgm (apply wr Y)) ) )

View file

@ -0,0 +1,25 @@
#!/usr/bin/env python
#four gray scaled stripes 8:16:32:64 in Python 2.7.1
from livewires import *
horiz=640; vert=480; pruh=vert/4; dpp=255.0
begin_graphics(width=horiz,height=vert,title="Gray stripes",background=Colour.black)
def ty_pruhy(each):
hiy=each[0]*pruh; loy=hiy-pruh
krok=horiz/each[1]; piecol=255.0/(each[1]-1)
for x in xrange(0,each[1]):
barva=Colour(piecol*x/dpp,piecol*x/dpp,piecol*x/dpp ); set_colour(barva)
if each[2]:
box(x*krok,hiy,x*krok+krok,loy,filled=1)
else:
box(horiz-x*krok,hiy,horiz-((x+1)*krok),loy,filled=1)
# main
source=[[4,8,True],[3,16,False],[2,32,True],[1,64,False]]
for each in source:
ty_pruhy(each)
while keys_pressed() != [' ']: # press spacebar to close window
pass

View file

@ -0,0 +1,7 @@
mat <- matrix(c(rep(1:8, each = 8) / 8,
rep(16:1, each = 4) / 16,
rep(1:32, each = 2) / 32,
rep(64:1, each = 1) / 64),
nrow = 4, byrow = TRUE)
par(mar = rep(0, 4))
image(t(mat[4:1, ]), col = gray(1:64/64), axes = FALSE)

View file

@ -0,0 +1,11 @@
grayscalesImage <- function(nrow = 4) {
X <- matrix(NA, nrow = nrow, ncol = 2^(nrow + 2))
for (i in 1:nrow) {
X[i, ] <- rep(1:2^(i + 2), each = 2^(nrow - i)) / 2^(i + 2)
if (i %% 2 == 0) X[i, ] <- rev(X[i, ])
}
par(mar = rep(0, 4))
image(t(X[nrow:1, ]), col = gray(1:ncol(X) / ncol(X)), axes = FALSE)
}
## Example ##
grayscalesImage(6) # produces image shown in screenshot to the right

View file

@ -0,0 +1,20 @@
#lang racket/gui
(require slideshow/pict)
(define-values (*width* *height*) (values 400 40))
(define (shades inc)
(for/list ([scale (in-range 0 (+ 1 inc) inc)])
(round (* 255 scale))))
(define (grays increment direction)
(define colors (shades increment))
(apply hc-append
((if (eq? direction 'right) identity reverse)
(for/list ([c colors])
(colorize (filled-rectangle
(/ *width* (length colors)) *height*)
(make-color c c c))))))
(vc-append (grays 1/8 'right) (grays 1/16 'left)
(grays 1/32 'right) (grays 1/64 'left))

View file

@ -0,0 +1,19 @@
import scala.swing._
class GreyscaleBars extends Component {
override def paintComponent(g:Graphics2D)={
val barHeight=size.height>>2
for(run <- 0 to 3; colCount=8<<run){
val deltaX=size.width.toDouble/colCount
val colBase=if (run%2==0) -255 else 0
for(x <- 0 until colCount){
val col=(colBase+(255.0/(colCount-1)*x).toInt).abs
g.setColor(new Color(col,col,col))
val startX=(deltaX*x).toInt
val endX=(deltaX*(x+1)).toInt
g.fillRect(startX, barHeight*run, endX-startX, barHeight)
}
}
}
}

View file

@ -0,0 +1,6 @@
new MainFrame(){
title="Greyscale bars"
visible=true
preferredSize=new Dimension(640, 320)
contents=new GreyscaleBars()
}

View file

@ -0,0 +1,21 @@
package require Tcl 8.5
package require Tk 8.5
wm attributes . -fullscreen 1
pack [canvas .c -highlightthick 0] -fill both -expand 1
# Add more values into this to do more greyscale bar variations
set splits {8 16 32 64}
set dy [expr {[winfo screenheight .c] / [llength $splits]}]
set y 0
foreach s $splits {
set dx [expr {double([winfo screenwidth .c]) / $s}]
set dc [expr {double(0xFF) / ($s-1)}]
for {set i 0} {$i < $s} {incr i} {
set c [expr {int($i * $dc)}]
set x [expr {int($i * $dx)}]
.c create rectangle $x $y [expr {$x+$dx+1}] [expr {$y+$dy+1}] \
-fill [format "#%02x%02x%02x" $c $c $c] -outline {}
}
incr y $dy
}