June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
17
Task/Munching-squares/AWK/munching-squares.awk
Normal file
17
Task/Munching-squares/AWK/munching-squares.awk
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
BEGIN {
|
||||
# square size
|
||||
s = 256
|
||||
# the PPM image header needs 3 lines:
|
||||
# P3
|
||||
# width height
|
||||
# max colors number (per channel)
|
||||
print("P3\n", s, s, "\n", s - 1)
|
||||
# and now we generate pixels as a RGB pair in a relaxed
|
||||
# form "R G B\n"
|
||||
for (x = 0; x < s; x++) {
|
||||
for (y = 0; y < s; y++) {
|
||||
p = xor(x, y)
|
||||
print(0, p, p)
|
||||
}
|
||||
}
|
||||
}
|
||||
21
Task/Munching-squares/Factor/munching-squares.factor
Normal file
21
Task/Munching-squares/Factor/munching-squares.factor
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
USING: accessors images images.loader kernel math sequences ;
|
||||
IN: rosetta-code.munching-squares
|
||||
|
||||
: img-data ( -- seq ) 256 sq [ B{ 0 0 0 255 } ] replicate ;
|
||||
|
||||
: (munching) ( elt index -- elt' )
|
||||
256 /mod bitxor [ rest ] dip prefix ;
|
||||
|
||||
: munching ( -- seq )
|
||||
img-data [ (munching) ] map-index B{ } concat-as ;
|
||||
|
||||
: <munching-img> ( -- img )
|
||||
<image>
|
||||
{ 256 256 } >>dim
|
||||
BGRA >>component-order
|
||||
ubyte-components >>component-type
|
||||
munching >>bitmap ;
|
||||
|
||||
: main ( -- ) <munching-img> "munching.png" save-graphic-image ;
|
||||
|
||||
MAIN: main
|
||||
47
Task/Munching-squares/Kotlin/munching-squares.kotlin
Normal file
47
Task/Munching-squares/Kotlin/munching-squares.kotlin
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
// version 1.1.4-3
|
||||
|
||||
import javax.swing.JFrame
|
||||
import javax.swing.JPanel
|
||||
import java.awt.Graphics
|
||||
import java.awt.Graphics2D
|
||||
import java.awt.Color
|
||||
import java.awt.Dimension
|
||||
import java.awt.BorderLayout
|
||||
import java.awt.RenderingHints
|
||||
import javax.swing.SwingUtilities
|
||||
|
||||
class XorPattern : JPanel() {
|
||||
|
||||
init {
|
||||
preferredSize = Dimension(256, 256)
|
||||
background = Color.white
|
||||
}
|
||||
|
||||
override fun paint(gg: Graphics) {
|
||||
super.paintComponent(gg)
|
||||
val g = gg as Graphics2D
|
||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON)
|
||||
for (y in 0 until width) {
|
||||
for (x in 0 until height) {
|
||||
g.color = Color(0, (x xor y) % 256, 255)
|
||||
g.drawLine(x, y, x, y)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
SwingUtilities.invokeLater {
|
||||
val f = JFrame()
|
||||
with (f) {
|
||||
defaultCloseOperation = JFrame.EXIT_ON_CLOSE
|
||||
title = "Munching squares"
|
||||
isResizable = false
|
||||
add(XorPattern(), BorderLayout.CENTER)
|
||||
pack()
|
||||
setLocationRelativeTo(null)
|
||||
isVisible = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
my $ppm = open("munching.ppm", :w) or
|
||||
my $ppm = open("munching0.ppm", :w) or
|
||||
die "Can't create munching.ppm: $!";
|
||||
|
||||
$ppm.print(q :to 'EOT');
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ my @colors = map -> $r, $g, $b { Buf.new: $r, $g, $b },
|
|||
flat (0,2...254),(254,252...0));
|
||||
|
||||
|
||||
my $PPM = open "munching.ppm", :w or die "Can't create munching.ppm: $!";
|
||||
my $PPM = open "munching1.ppm", :w or die "Can't create munching.ppm: $!";
|
||||
|
||||
$PPM.print: qq:to/EOH/;
|
||||
P6
|
||||
|
|
|
|||
20
Task/Munching-squares/REXX/munching-squares.rexx
Normal file
20
Task/Munching-squares/REXX/munching-squares.rexx
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/*REXX program renders a graphical pattern by coloring each pixel with x XOR y */
|
||||
/*───────────────────────────────────────── from an arbitrary constructed color table. */
|
||||
rows=25 /*the number of rows in the color table*/
|
||||
cols=50 /* " " " cols " " " " */
|
||||
|
||||
do row =0 for rows*3 /*construct a color table, size 25x50.*/
|
||||
do col=0 for cols*3
|
||||
$= (row+col) // 255
|
||||
@.row.col= x2b( d2x($+0, 2) ) ||, /*ensure $ is converted──►2 hex nibbles*/
|
||||
x2b( d2x($+1, 2) ) ||,
|
||||
x2b( d2x($+2, 2) )
|
||||
end /*col*/ /* [↑] construct a three-byte pixel. */
|
||||
end /*row*/
|
||||
|
||||
do x=0 for cols /*create a graphical pattern with XORs.*/
|
||||
do y=0 for rows
|
||||
@.x.y=bitxor(@.x, @.y) /*renders 3 bytes (a pixel) at a time. */
|
||||
end /*y*/
|
||||
end /*x*/
|
||||
/*stick a fork in it, we're all done. */
|
||||
57
Task/Munching-squares/Ring/munching-squares.ring
Normal file
57
Task/Munching-squares/Ring/munching-squares.ring
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
# Project : Munching squares
|
||||
# Date : 2018/01/13
|
||||
# Author : Gal Zsolt (~ CalmoSoft ~)
|
||||
# Email : <calmosoft@gmail.com>
|
||||
|
||||
load "guilib.ring"
|
||||
|
||||
paint = null
|
||||
|
||||
new qapp
|
||||
{
|
||||
win1 = new qwidget() {
|
||||
setwindowtitle("Archimedean spiral")
|
||||
setgeometry(100,100,500,600)
|
||||
label1 = new qlabel(win1) {
|
||||
setgeometry(10,10,400,400)
|
||||
settext("")
|
||||
}
|
||||
new qpushbutton(win1) {
|
||||
setgeometry(150,500,100,30)
|
||||
settext("draw")
|
||||
setclickevent("draw()")
|
||||
}
|
||||
show()
|
||||
}
|
||||
exec()
|
||||
}
|
||||
|
||||
func draw
|
||||
p1 = new qpicture()
|
||||
color = new qcolor() {
|
||||
setrgb(0,0,255,255)
|
||||
}
|
||||
pen = new qpen() {
|
||||
setcolor(color)
|
||||
setwidth(1)
|
||||
}
|
||||
paint = new qpainter() {
|
||||
begin(p1)
|
||||
setpen(pen)
|
||||
|
||||
w = 100
|
||||
for x = 0 to w
|
||||
for y = 0 to w
|
||||
b = (x ^ y)
|
||||
color = new qcolor()
|
||||
color.setrgb(255 -b,b /2,b,255)
|
||||
pen.setcolor(color)
|
||||
setpen(pen)
|
||||
drawpoint(x,w -y -1)
|
||||
next
|
||||
next
|
||||
|
||||
endpaint()
|
||||
}
|
||||
label1 { setpicture(p1) show() }
|
||||
return
|
||||
Loading…
Add table
Add a link
Reference in a new issue