2D Graphics with Crystal Programming language.

require "chitra/global_context"

size 600, 200

rect_s = 10
gap = 0
x = gap
y = gap
loop do
  if x > width
    x = gap
    y += rect_s + gap
  end

  break if y > height

  fill 0, 0, Random.new.rand(0.0...1.0)

  rect x, y, rect_s, rect_s
  x += rect_s + gap
end

save "blue_rects.png"
require "chitra/global_context"

background 1
gap = 100
x = y = gap
loop do
  break if y > height

  if x > width
    x = gap
    y += gap
  end

  no_stroke
  oval x, y
  x += gap
end

save "./docs/content/images/dots.png"
require "chitra/global_context"

size 600, 600
background 255/256, 88/256, 0

def pattern
  no_stroke

  x = 0
  y = 50
  (1..20).each do
    fill 255/256, 132/256, 0
    rect x, y, 150, 100
    rect x+50, y+100, 100, 150

    fill 255/256, 48/256, 0
    rect x, y+50, 150, 50
    rect x+100, y+100, 50, 150

    x += 150
    y += 150
  end
end

ty = -600.0
(0..4).each do
  translate 0, ty
  pattern
  translate 0, -ty
  ty += 300
end

save "./output/pattern.png"
require "chitra/global_context"

size 600

# Square
#    x   y   w    h
rect 10, 10, 100, 100

# Rectangle
#    x   y    w    h
rect 10, 120, 100, 50

# Circle
#    x   y    w    h
oval 10, 180, 100, 100

# Oval
#    x   y    w    h
oval 10, 290, 100, 50

# Polygon
#       x1  y1   x2  y2   x3  y3   close
polygon 10, 400, 50, 500, 10, 600, close: true

save "shapes.png"
require "chitra/global_context"

# Set Fill color Red
fill 1, 0, 0
saved_state do
  # Change the fill color to Blue
  fill 0, 0, 1
  rect 100, 100, 200, 200
end

# Draw rect with the fill color set previously
rect 200, 200, 200, 200

save "saved_state.png"
size 200, 200
background 1

no_stroke
font "Quicksand", 160

# Text and Circle in Red
fill 1, 0, 0
text "8", 40, 20
oval 80, 40, 200, 200

# Create intersecting area of the
# text and Circle in White color.
fill 1
grouped do
  text "8", 40, 20
  composite "in"
  oval 80, 40, 200, 200
end

save "composite.png"
Pattern
Dots
Random Blues
Saved State
Shapes
Composite
Read the docs Github
© 2022 Aravinda Vishwanathapura. Created using Nanoc.