특수 기간 이미지 생성


10

다음 형식으로 입력을받는 프로그램 또는 함수를 구성하십시오.

<width>, <height>, <color1>, <color2>

제 1 행이 컬러의 픽셀들 사이에서 <color1>및 <color2>주기로 교번하도록 출력을 생성한다 <height>. 다음에 오는 각 행에 대해 기간은 <height> - <row number>입니다. 참고 <color1>항상 행을 시작합니다.

샘플 출력

입력 120, 6, #000000, #FFFF00:

샘플 출력

입력 80, 50, #000000, #FFFF00:

샘플 출력 2

(샘플 출력은 명확성을 위해 조정되었습니다)

이것은 이므로 바이트 단위의 가장 짧은 유효한 항목이 이깁니다.


프랙탈인가요? 프랙탈 차원이 있습니까?
— PyRulez

답변:


6

자바 스크립트 (ES6), 177 바이트

g=
(w,h,f,b)=>`<svg${s=` width=${w} height=`+h}><rect${s} fill=${b} />`+[...Array(h)].map((_,i)=>`<line stroke=${f} stroke-dasharray=${h-i} x1=0 y1=${i} x2=${w} y2=${i} />`).join``
Width: <input id=w value=80 type=number min=1><br>Height: <input id=h value=50 type=number min=1><br>Foreground: <input id=f value=#000000><br>Background: <input id=b value=#FFFF00><br><input type=button value=Go! onclick=o.innerHTML=g(+w.value,+h.value,f.value,b.value)><div id=o>

HTML5 호환 SVG 이미지를 출력합니다.


4

Excel VBA, 129 바이트

범위에서 입력을 받고 범위 [A1:D1]로 출력하는 익명의 VBE 즉시 창 기능[A2].Resize([B1],[A1])

Cells.RowHeight=48:For Each r in[A2].Resize([B1],[A1]):r.Interior.Color=IIf(int((r.Column-1)/([B1]-R.Row+2))Mod 2,[D1],[C1]):Next

산출

입력 출력 160, 90, 0xBDD7EE, 0xDDEBF7: 산출


4

Tcl / Tk, 143

147 150 151

proc P {w h b c} {set p [image c photo -w $w -h $h]
time {incr y
set x 0
time {$p p -t $x $y [expr {[incr x]/($h-$y+1)%2?$c:$b}]} $w} $h
set p}

테스트 할 수있는 이미지를 canvas위젯에 배치하고 파일에 쓰거나 클립 보드에있을 수 있습니다.

테스트 코드

set w 960
set h 540
pack [canvas .c -w $w -he $h -highlightt 0]
.c cr image 0 0 -image [P $w $h #00ffff #ffbf32] -anchor nw

여기에 이미지 설명을 입력하십시오


3

매스 매 티카, 52 바이트

Image@Table[If[Mod[j,2i]>i,#4,#3],{i,-#2,-1},{j,#}]&

샘플 입력 :

Image@Table[If[Mod[j,2i]>i,#4,#3],{i,-#2,-1},{j,#}]&[120,6,Black,Yellow]

3

C (GCC) , 155 (143) 바이트

휴대용 PixMap (.ppm)을 표준 출력으로 인쇄합니다.

x,y,z;f(w,h,r,g,b,R,G,B){for(y=~0,printf("P3 %d %d 255",w,h);y++<~-h;)for(x=~0;x++<~-w;)z=(x/(h-y)%2),printf("\n%d %d %d ",z?R:r,z?G:g,z?B:b);}

온라인으로 사용해보십시오!

산출

  • 입력: 80, 50, #ad00df, #f17e18

여기에 이미지 설명을 입력하십시오 (이미지 변환 및 크기 조정)


~0대신 글쓰기의 장점은 무엇입니까 -1?
— sergiol

@sergiol 더 시원해 보인다. 그리고 - 이론적으로 - 당신 만이 포함 된 변수를 필요로하는 경우 1에요, ~0보다 더 많은 휴대용 될 것이다 -1.
— Jonathan Frech

2
이 이미지는 내가 스크롤을 할 때 눈을 죽였다. +1
— HyperNeutrino


1

자바 8, 321 + 42 = 363 바이트

import java.awt.*;import java.awt.image.*;
(w,h,a,b)->{BufferedImage i=new BufferedImage(w,h,1);Graphics2D g=(Graphics2D)i.getGraphics();g.setColor(new Color(a));g.fillRect(0,0,w,h);g.setColor(new Color(b));for(int j=h;j>0;g.drawLine(0,h-j,w,h-j--))g.setStroke(new BasicStroke(1,0,0,1,new float[]{j},j));javax.imageio.ImageIO.write(i,"png",new java.io.File("a"));}

a(확장자 없음) 이라는 PNG 파일로 출력합니다 .

람다를 실행하는 데 사용되는 주변 코드 : 온라인으로 사용해보십시오!

언 골프

(w,h,a,b)->{
    BufferedImage i=new BufferedImage(w,h,1);
    Graphics2D g=(Graphics2D)i.getGraphics();
    g.setColor(new Color(a));
    g.fillRect(0,0,w,h);
    g.setColor(new Color(b));
    for(int j=h;j>0;g.drawLine(0,h-j,w,h-j--))
        g.setStroke(new BasicStroke(1,0,0,1,new float[]{j},j));
    javax.imageio.ImageIO.write(i,"png",new java.io.File("a"));
}

결과

입력 : 80, 50, 0xFF00FF, 0xFFFF00.

예제 출력


1

SOGL V0.12 , 83 바이트

..¹Cbe¹"εģνļ▲I-℮eīÆoHι⅛ļJd⁾)⁶f°┌²‘→e∫Ab∫Ƨ01a∙H∑bmWrcwιFHea-¹"S⁸▒Μ¬NrηA¤Y_⅓ļpPboā⁵‘→

여기 사용해보십시오!

SOGL은 Processing에서 만들어졌습니다. 그래서 저는 →JavaScript로 execute 를 사용하여 이점을 활용했습니다 . SOGL 에 그래픽 용으로 제작 된 것이 있으면 바이트 수가 30 바이트 이상 줄어들 수 있습니다 .

압축되지 않은 문자열 :

..¹Cbe¹"__processing0.hidden=0;cp.size(ŗ,ŗ)”→e∫Ab∫Ƨ01a∙H∑bmWrcwιFHea-¹"cp.stroke(ŗ);cp.point(ŗ,ŗ)”→

설명:

..¹C       save the first 2 inputs as an array on variable C
be¹        save next input - width - on B, next input - height - on E, and wrap both in an array
"__processing0.hidden=0;cp.size(ŗ,ŗ)”→   
           execute "__processing0.hidden=0;cp.size(ŗ,ŗ)" as JavaScript - show the canvas and set the size to the corresponding items in the array

e∫A        repeat height times, saving 1-indexed counter on A
  b∫       repeat width times, pushing 1-indexed counter
    Ƨ01    push "01"
    a∙     multiply vertically A times             - ["01", "01", "01",...]
    H      rotate anticlockwise                    - ["000...","111..."]
    ∑      join together                           - "000..111.."
    bm     mold to the length of width             - "00011100011100"
    W      get the counterth letter of that string - "1"
    r      convert to number                       - 1
    cw     get that item from the variable C
    ι      remove the array from the stack
    FH     push current loops counter minus 1
    ea-    push e-a - height-outerLoopsCounter
    ¹      wrap the 3 items in an array - [itemInC (color), counter-1 (x position), height-outerLoopsCounter (y position)]

    "cp.stroke(ŗ);cp.point(ŗ,ŗ)”→ 
           execute "cp.stroke(ŗ);cp.point(ŗ,ŗ)" as JavaScript, replacing ŗ with the corresponding item from the array

1

SmileBASIC, 84 바이트

DEF C W,H,C,D
FOR J=1TO H
FOR I=0TO W-1N=1AND I/J
GPSET I,H-J,C*!N+D*N
NEXT
NEXT
END

픽셀의 색상 (x,height-y)은[color1,color2][x/y & 1]


0

파이썬 2 , 123 101 바이트

w,h,c,C=input()
print'P3',w,h,255
for i in range(h):
 for j in range(w):print`[c,C][j/(h-i)%2]`[1:-1]

온라인으로 사용해보십시오!

Jonathan의 답변 에서처럼 .ppm을 출력하여 출력 합니다.


내 C 답변과 비슷하게 보입니다. 색상 입력 형식을 변경하면 105 바이트 가됩니다 (질문이 색상 형식을 엄격하게 정의하지 않기 때문에).
— Jonathan Frech

@JonathanFrech Thanks :) 그래, 나는 이미지를 출력하는 방법을 찾을 때 당신의 대답에서 영감을 얻었습니다.
— TFeld

그냥 호기심; .ppm 파일을 여는 데 사용하는 프로그램은 무엇입니까?
— Jonathan Frech

'%d '*3%보다 짧습니다 '%d %d %d'%.
— Jonathan Frech

@JonathanFrech 이 작품을, 아니면 김프 사용했습니다
— TFeld

0

자바 스크립트 (ES6) + HTML5, 138 바이트

(w,h,a,b)=>{with(c.width=w,c.getContext`2d`)for(c.height=y=h;~--y;)for(x=w;~--x;)fillStyle=x/(h-y)%2<1?a:b,fillRect(x,y,1,1)}
<canvas id=c>

f=
(w,h,a,b)=>{with(c.width=w,c.getContext`2d`)for(c.height=y=h;~--y;)for(x=w;~--x;)fillStyle=x/(h-y)%2<1?a:b,fillRect(x,y,1,1)}
#c{display:block
<input id=w value=80>
<input id=h value=50>
<input id=a value=#000>
<input id=b value=#FF0>
<input value=go type=button onclick=f(w.value,h.value,a.value,b.value)>
<canvas id=c>

기능은에서 ​​작동하여 출력합니다 <canvas id=c>.

캔버스의 오른쪽 아래에서 시작하여 중첩 for루프가 왼쪽에서 위로 반복되고 x/(h-y)%2<1의 픽셀 상태 를 확인합니다 x,y. 조건이 true이면 해당 픽셀에 color1, 그렇지 않은 경우 색상이 지정 color2됩니다.

당사 사이트를 사용함과 동시에 당사의 쿠키 정책과 개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.