| Bytes | Lang | Time | Link |
|---|---|---|---|
| 154 | Uiua SBCS | 250618T151823Z | lolad |
| 241 | JavaScript + HTML | 200906T235328Z | Matthew |
| 714 | 161012T214624Z | Neil | |
| 306 | Haskell with JuicyPixels package | 180511T191150Z | colossus |
| 141 | CJam | 170121T151857Z | aditsu q |
| 169 | Mathematica | 161012T053450Z | JungHwan |
| 251 | JavaScript ES7 | 161012T162053Z | Arnauld |
| 001 | Processing.py 244 bytes + | 170208T122716Z | PidgeyUs |
| 359 | Ruby 2.3.1 | 161013T200834Z | metropol |
Uiua (SBCS), 154 bytes
Uses experimental ◠.
B←66_133_244
÷₂₅₆↥≡₀⌞×B××≥0⤙𝄐⌞≤𝄐⌞≤∩⌟×0.1÷₅₂√650⤙⊙⊙⊙◌⌵°ℂ:×∨⊓⌟≥≤÷₄π∠1 5¯:×⊙(≡₀⌞˜⊡[234_67_53B52_168_83 251_188_5]◿4⌈÷η+÷₂η.∠⊸°ℂ)×⊓⌞≥≤◌◠𝄐×0.6⌵⊙:.⊞ℂ.⤚-÷₂⟜⇡.
Approximate: 142 141 bytes
Visually looks correct but uses approximated values, especially for the colours, using the domain colouring system instead of RGB values.
B←-4.7¯3.6i
+𝄐⌞׬⤙≡₀⌞×B××≥0⤙𝄐⌞≤𝄐⌞≤∩⌟×0.1 0.49⤙⊙⊙⊙◌⌵°ℂ:×∨⊓⌟≥≤÷₄π0.2¯:×⊙(≡₀⌞˜⊡[+0.4i5B×0.3-1 i+i1]◿4⌈÷η+÷₂η.∠⊸°ℂ)×⊓⌞≥≤◌◠𝄐×0.6⌵⊙:.⊞ℂ.⤚-÷₂⟜⇡.
Explanation
Colours here are either uiua's default complex coloring or the 3-channel RGB colouring used in the final logo. Since I only divide by 256 at the end, that has been done for visualisation.
⌵⊙:.⊞ℂ.⤚-÷₂⟜⇡.
First, we create an \$N\times N\$ complex grid, and calculate magnitudes (also calculating \$\frac{N}2\$ along the way).
◌◠𝄐×0.6
Next, shuffle the stack and calculate \$0.6\cdot\frac{N}2=0.3N=0.5N-0.2N\$, the inner radius.
×⊓⌞≥≤
Bounds check magnitudes so we only have points in the annulus.
⊙(...◿4⌈÷η+÷₂η.∠⊸°ℂ)
Calculate diagonal groups: take \$\left\lceil\frac1\eta\left(arg z+\frac\eta2\right)\right\rceil\bmod 4\$ for every point. Note that uiua uses \$\eta=\frac\pi2\$. The \$+\frac\eta2\$ term shifts arguments so the initial line is a diagonal; the \$\frac1\eta\$ term renormalises arguments to be in \$[-1,3)\$; then taking ceiling and \$\bmod4\$ gives us integers in \$[0, 4)\$, convenient for array lookup.
B←66_133_244
⊙(
[234_67_53B52_168_83 251_188_5]
≡₀⌞˜⊡
...)
We then push each color in an array and lookup, pixel by pixel, creating coloured diagonal sections. Note that B, the RGB value for blue, is saved (this happens on a line before the main program) as we need it later.
×
Multiplying these (point-wise) with the annulus gives us a coloured ring.
×∨⊓⌟≥≤÷₄π∠1 5¯:
Next, we want to remove the wedge connecting the blue and red sections. This applies to any points with \$\theta=\tan^{-1} \frac15 \le \arg z \le \frac\pi4\$, with \$\theta\$ is derived from a triangle with base length \$0.5N\$ and height \$0.1N\$), while \$\frac\pi4\$ being the diagonal separating blue and red. Testing for the negative of this range and multiplying removes the wedge.
∩⌟×0.1÷₅₂√650⤙⊙⊙⊙◌⌵°ℂ:
Finally, we need to add a blue rectangle to complete the logo. This line creates the base and height constants needed: the width is \$0.5N\cos\theta=\frac12N\cos\tan^{-1}\frac15 =\frac{\sqrt{650}}{52}N\$, while the height is \$0.2N\$.
××≥0⤙𝄐⌞≤𝄐⌞≤
Since the rectangle is centered vertically left-aligned to the origin, we want points where \$0\le\Re(z)\le\frac{\sqrt{650}}{52}, \left|\Im(z)\right|\le0.1N\$. We filter for these ranges, and combine, giving us a rectangle.
≡₀⌞×B
We can then colour this rectangle using B from earlier.
÷₂₅₆↥
Finally, union the rectangle and cut ring with ↥ (maximum), then divide values by 256 since uiua takes colours in \$[0, 1]\$.
JavaScript + HTML, 241 bytes
228 bytes for JavaScript + 13 bytes for HTML
(
// code start
n=>{with(c.getContext`2d`)['#4285f4','#34a853','#fbbc05','#ea4335'].map((c,i)=>{beginPath(fillStyle=strokeStyle=c,lineWidth=n/5,a=Math.PI/2);arc(h=n/2,h,r=n*.4,j=i*a-a/2,j+a);stroke();i||clearRect(0,0,n,r)+fillRect(h,r,r,n/5)})}
// code end
)(100);
<canvas id=c>
JS/CSS/HTML(+JS), 40 0 + 701 644 617 593 + 173 90 97 121 = 914 774 754 730 714 bytes
*{position:absolute}a,h{height:100%;background:#4285F4}a,g{width:100%;border-radius:100%}h{width:30%;height:20%;top:40%}b,c,d,e,f{width:50%;height:50%}b,d,f,h{left:50%}e,f{top:50%}c{border-radius:100% 0 0;background:linear-gradient(45deg,#FBBC05 50%,#EA4335 50%)}d{border-radius:0 100% 0 0;background:linear-gradient(-45deg,transparent 50%,#EA4335 50%)}e{border-radius:0 0 0 100%;background:linear-gradient(-45deg,#34A853 50%,#FBBC05 50%)}f{border-radius:0 0 100%;background:linear-gradient(45deg,#34A853 50%,#4285F4 50%)}b,g{height:40%;background:#FFF}g{width:60%;height:60%;top:20%;left:20%}
<input oninput=with(o.style)height=width=value+"px"><o id=o><a></a><b></b><c></c><d></d><e></e><f></f><g></g><h></h></o>
Uses linear gradients rather than transforms. Edit: Saved 140 bytes thanks to @darrylyeo. Saved 20 bytes by using an extra element instead of a gradient. Saved 24 bytes thanks to @DBS. Saved 16 bytes thanks to @Hedi. From back to front, the various layers are:
aThe blue circlebA white rectangle to obscure the part above the barcThe red/yellow top left quarterdThe red octant top righteThe yellow/green bottom left quarterfThe green/blue bottom right quartergThe inner white circlehThe horizontal blue bar
JavaScript (ES6) (+SVG), 293 bytes, invalid
document.write(`<svg id=o width=${prompt()} viewbox=0,0,50,50>`);m=`39,11`;`#EA433511,11
#FBBC0511,39
#34A85339,39
#4285F445,25L25,25`.replace(/(.{7})(.{5})(.*)/g,(_,s,t,u)=>m=document.write(`<path stroke=${s} d=M${m}A20,20,0,0,0,${t+u} fill=none stroke-width=10 stroke-linejoin=round />`)||t)
Sadly the round line join isn't quite the requested effect, but it's pretty close.
Haskell with JuicyPixels package, 306 bytes
import Codec.Picture
p=PixelRGB8
c=fromIntegral
b=p 66 133 244
w=p 255 255 255
(n%x)y|y<=x,x+y<=n=p 234 67 53|y>x,x+y<=n=p 251 188 5|y>x,x+y>n=p 52 168 83|y>=0.4*n=b|1>0=w
(n#x)y|d<=h,d>=0.3*n=n%x$y|x>=h,d<=h,abs(y-h)<=n/10=b|1>0=w where h=n/2;d=sqrt$(x-h)^2+(y-h)^2
f n=generateImage(\x y->c n#c x$c y)n n
Usage example:
main = writePng "google.png" $ f 1001
This could probably be improved. The idea is to pass a function to generateImage that selects the pixel (color really) that should go at position x, y. For that we use a lambda that adds n as a parameter and converts them all to floats at the same time. The # function basically checks if we're in the ring, the bar, or neither. If it's the ring we pass the baton to %, if the bar we just return blue, otherwise white. % checks which quadrant we're in and returns the appropriate color if it isn't blue. Blue is a special case since we need to make sure it doesn't wrap around to the red, so we only return blue if y is below the "bar line" otherwise we return white. That's the general overview.
CJam, 141
ri:M.5*:K5/:T;'P3NMSMN255NM2m*[K.5-_]f.-{:X:mh:IK>0{X~0<\zT>|{IT3*<0{X~>X~W*>:Z2+{Z{X0=TW*>}4?}?}?}1?}?}%"^^G_8:nEhB%P9IW@zA"102b256b3/f=:+N*
Outputs the image in ASCII ppm format.
For an ASCII-art version that's nicer to look at in the browser, try this code. It helps visualize the algorithm too.
Explanation:
ri:M read input, convert to int and store in M
.5*:K multiply by 0.5 and store in K (M/2)
5/:T; divide by 5 and store in T (M/10) and pop
'P3NMSMN255N ppm header (N=newline, S=space)
M2m* generate all pixel coordinates - pairs of numbers 0..M-1
[K.5-_] push the center (coordinates K-0.5, K-0.5)
f.- subtract the center from every pixel
{…}% map (transform) the array of coordinate pairs
:X store the current pair in X
:mh:I calculate the hypotenuse of X (distance from the center)
and store in I
K>0 if I>K (outside the big circle), push 0
{…} else…
X~ dump X's coordinates (row, column)
0< check if the column is <0
\zT>| or the absolute value of the row is >T
{…} if true (outside the G bar)…
IT3*<0 if I<T*3 (inside the small circle) push 0
{…} else (between the circles)…
X~> dump X and check if row>column (diagonal split)
X~W*>:Z also check if row>-column (other diagonal) and store in Z
(W=-1)
2+ if in lower-left half, push Z+2 (2 for left, 3 for bottom)
{…} else (upper-right half)…
Z{…} if it's in the right quadrant
X0= get the row coordinate of X
TW*> compare with -T, resulting in 0 (above the bar) or 1
4 else (top quadrant) push 4
? end if
? end if
? end if
1 else (inside the G bar) push 1
? end if
? end if
"^^G … @zA" push a string containing the 5 colors encoded
102b convert from base 102 to a big number
(ASCII values of chars are treated as base-102 digits)
256b convert to base 256, splitting into 15 bytes
3/ split into triplets (RGB)
f= replace each generated number (0..4)
with the corresponding color triplet
:+N* join all the triplets, and join everything with newlines
Mathematica, 229 226 225 224 221 206 169 bytes
Thanks @MartinEnder for 1 byte, @ChipHurst for 37 bytes!
Graphics[{RGBColor@{"#EA4335","#FBBC05","#34A853","#4285F4"}[[#]],{0,-1}~Cuboid~{√24,1},Annulus[0{,},{3,5},{(2#-9)Pi/4,ArcCsc@5}]}&~Array~4,ImageSize->#,PlotRange->5]&
What a fun challenge!
Explanation
...&~Array~4
Iterate from 1 to 4...
RGBColor@{"#EA4335","#FBBC05","#34A853","#4285F4"}[[#]]
Convert the color hex codes to RGBColor objects, so that they can be applied to the Google logo graphic. Change the color palette to the <input>th color.
{0,-1}~Cuboid~{√24,1}
Create a filled rectangle (2D cuboid), whose diagonal corners are (0, -1) and (sqrt(24), 1).
Annulus[0{,},{3,5},{(2#-9)Pi/4,ArcCsc@5}]}
Generate four filled quarter-Annuluss, centered at the origin, with inner radius 3 and outer radius 5. Do not draw past ArcCsc@5 (where the blue segment ends).
Graphics[ ... , ImageSize->#,PlotRange->5]
Create a graphic with size N x N, from x = -5 to x = 5 (removes the padding).
Outputs
N = 10
N = 100
N = 200
N = 10000 (click image for full resolution)
JavaScript (ES7), 285 258 254 252 251 bytes
Prompts for the width of the logo (up to 999) and draws it in a canvas, pixel per pixel.
Edit: The initial version was converting Cartesian coordinates (x,y) to Polar coordinates (r,a), but we don't really need the angle. It's simpler (and significantly shorter) to just do comparisons between x and y to find out in which quarter we are.
Edit: Saved 1 byte thanks to ETHproductions.
JS, 251 224 220 218 217 bytes
for(w=x=y=prompt(c=c.getContext`2d`)/2;r=(x*x+y*y)**.5,q=(x<y)+2*(x<-y),c.fillStyle='#'+'4285F434A853EA4335FBBC05FFF'.substr(x>0&r<w&y*y<w*w/25?0:r<w*.6|r>w|!q&y<0?24:q*6,6),x-->-w||y-->-(x=w);)c.fillRect(x+w,y+w,1,1)
HTML, 34 bytes
<canvas id=c width=999 height=999>
ES6 version: 258 231 227 225 224 + 34 = 258 bytes
Recommended maximum width for the snippet: 190.
for(w=x=y=prompt(c=c.getContext`2d`)/2;r=Math.pow(x*x+y*y,.5),q=(x<y)+2*(x<-y),c.fillStyle='#'+'4285F434A853EA4335FBBC05FFF'.substr(x>0&r<w&y*y<w*w/25?0:r<w*.6|r>w|!q&y<0?24:q*6,6),x-->-w||y-->-(x=w);)c.fillRect(x+w,y+w,1,1)
<canvas id=c width=999 height=999>
Processing.py - 244 bytes + 1 byte for number of digits in N
Let's start with the code. This can be pasted in the Processing environment and ran (changing N for different sizes).
N=400
n=N/2
f=fill
a=['#34A853','#FBBC05','#EA4335','#4285F4']
def setup():
size(N,N);noStroke()
def draw():
for i in 1,3,5,7: f(a[i/2]);arc(n,n,N,N,i*PI/4+[0,.59][i>6],(i+2)*PI/4)
f(205);ellipse(n,n,.6*N,.6*N);f(a[3]);rect(n,n-.1*N,.98*n,.2*N)
Small cheat: the circle that cut's out a part from the logo is drawn in Processing's grayscale shade 205, which is the default background color. Exporting this to an image wouldn't look the same. This saves a call to background(255).
Explanation
N=400 # set size
n=N/2 # precompute center point
f=fill # 3 usages, saves 3 bytes
a=['#34A853','#FBBC05','#EA4335','#4285F4']
# list of colors
def setup(): # called when starting sketch
size(N,N) # set size
noStroke() # disable stroking
def draw(): # drawing loop
for i in 1,3,5,7: # loop over increments of PI/4
f(a[i/2]) # set fill color using integer
# division
arc(n,n,N,N,i*PI/4+[0,.59][i>6],(i+2)*PI/4)
# draw a pizza slice between
# two coordinates. The
# [0,.59][i>6]
# accounts for the white part
f(205) # set fill color to Processing's
# default background
ellipse(n,n,.6*N,.6*N)
# cut out center
f(a[3]) # set fill to blue
rect(n,n-.1*N,.98*n,.2*N)
# draw the straight part
Examples
N = 400
N = 13 (Processing's minimum size is 100x100)
Note
If we allow us to manually edit in multiple values for N the explicit calls to setup and draw are not needed and it is down to 213 bytes + 3 bytes per digit in N.
N=200
size(200,200)
n=N/2
f=fill
a=['#34A853','#FBBC05','#EA4335','#4285F4']
noStroke()
for i in 1,3,5,7:f(a[i/2]);arc(n,n,N,N,i*PI/4+[0,.59][i>6],(i+2)*PI/4)
f(205);ellipse(n,n,.6*N,.6*N);f(a[3]);rect(n,n-.1*N,.98*n,.2*N)
Ruby 2.3.1, 376 359 bytes
Using the RMagick gem.
d,f=$*[0].to_i,2.5;g,h,e,c=d-1,d/2,Magick::ImageList.new,Magick::Draw.new;e.new_image(d,d);c.stroke('#EA4335').fill_opacity(0).stroke_width(d*0.2).ellipse(h,h,g/f,g/f,225,315).stroke('#FBBC05').ellipse(h,h,g/f,g/f,135,225).stroke('#34A853').ellipse(h,h,g/f,g/f,45,135).stroke('#4285F4').ellipse(h,h,g/f,g/f,348.5,45).line(h,h,d*0.989,h).draw(e);e.write($*[1])
Examples
50x50
250x250
500x500
1000x1000
File takes two parameters- the first being the dimension and the second being the filename to save the output as.
Ungolfed
require "RMagick"
# Take the user's input for dimension
d = $*[0].to_i
e = Magick::ImageList.new
e.new_image(d, d)
c = Magick::Draw.new
# Start by setting the color to red
c.stroke('#EA4335')
# set opacity to nothing so that we don't get extra color.
.fill_opacity(0)
# set thickness of line.
.stroke_width(d*0.2)
# #ellipse creates an ellipse taking
# x, y of center
# width, height,
# arc start, arc end
.ellipse(d / 2, d / 2, (d - 1) / 2.5, (d - 1) / 2.5, 225, 315)
# change to yellow and draw its portion
.stroke('#FBBC05')
.ellipse(d / 2, d / 2, (d - 1) / 2.5, (d - 1) / 2.5, 135, 225)
# change to green and draw its portion
.stroke('#34A853')
.ellipse(d / 2, d / 2, (d - 1) / 2.5, (d - 1) / 2.5, 45, 135)
# change to blue and draw its portion
.stroke('#4285F4')
.ellipse(d / 2, d / 2, (d-1)/2.5, (d - 1)/2.5, 348.5, 45)
# creates the chin for the G
.line(d/2, d/2, d*0.99, d/2)
# draws to the created canvas
.draw(e)
# save out the file
# taking the filename as a variable saves a byte over
# "a.png"
e.write($*[1])
I had initially started solving this using oily_png/chunky_png but that would likely end up far too complicated compared to RMagick. RMagick's .ellipse function made this a breeze and the main work was around tuning the shapes/sizes of everything.
This is my first Code Golf submission(first SE answer also) and I only consider myself somewhat intermediate with Ruby. If you have any input on improvement/tips, please feel free to share!


















