Skip to content

Instantly share code, notes, and snippets.

@lihaochen910
Created April 28, 2021 07:15
Show Gist options
  • Save lihaochen910/4256f88f561e860859f4fc1ca31371b0 to your computer and use it in GitHub Desktop.
Save lihaochen910/4256f88f561e860859f4fc1ca31371b0 to your computer and use it in GitHub Desktop.
使用这个脚本来快速生成随机的V大的复制单根线条练习(4x5)
# 使用这个脚本来快速生成随机的V大的复制单根线条练习(4x5)
require 'RMagick'
DEBUG = false
FONT_PATH = '/Users/Kanbaru/Downloads/FOT-NewRodinPro-L.otf'
FONT_SIZE = 25
def gen_line_sketch( input, output )
img = Magick::Image.read( input ).first
columns = 4 # 4
rows = 5 # 5
r = 200
canvas_width = 800
canvas_height = 800
line_width = 10
columns.times do |column|
rows.times do |row|
x, y = 500 + (column * r + column * 690) * 2, 500 + row * r + row * 735
minX, maxX = x - canvas_width / 2, x + canvas_width / 2
minY, maxY = y - canvas_height / 2, y + canvas_height / 2
gc = Magick::Draw.new
gc.stroke 'red'
gc.stroke_width line_width
gc.fill_opacity 0
if rand >= 0.5
# if true
x1 = rand( minX..maxX )
y1 = rand( minY..maxY )
cx1 = rand( minX..maxX )
cy1 = rand( minY..maxY )
x2 = rand( minX..maxX )
y2 = rand( minY..maxY )
cx2 = rand( minX..maxX )
cy2 = rand( minY..maxY )
gc.bezier( x1, y1, cx1, cy1, cx2, cy2, x2, y2 )
if DEBUG
# Draw circles around endpoints
gc.fill_opacity(0)
gc.stroke('gray50').stroke_width(1)
gc.circle( x1 - 3, y1 - 3, x1 + 3, y1 + 3 )
gc.circle( x2 - 3, y2 - 3, x2 + 3, y2 + 3 )
# Draw filled circles around control points
gc.line( x1, y1, cx1, cy1 )
gc.line( x2, y2, cx2, cy2 )
gc.fill_opacity(1)
gc.fill('gray50')
gc.circle( cx1 - 3, cy1 - 3, cx1 + 3, cy1 + 3 )
gc.circle( cx2 - 3, cy2 - 3, cx2 + 3, cy2 + 3 )
# Annotate
gc.font(FONT_PATH)
gc.pointsize(FONT_SIZE)
gc.font_weight(Magick::NormalWeight)
gc.font_style(Magick::NormalStyle)
gc.fill('red')
gc.stroke('transparent')
gc.text(x1, y1, "'#{x1.to_i},#{y1.to_i}'")
gc.text(cx1, cy1, "'#{cx1.to_i},#{cy1.to_i}'")
gc.text(x2, y2, "'#{x2.to_i},#{y2.to_i}'")
gc.text(cx2, cy2, "'#{cx2.to_i},#{cy2.to_i}'")
# range
gc.font(FONT_PATH)
gc.pointsize(FONT_SIZE)
gc.font_weight(Magick::NormalWeight)
gc.font_style(Magick::NormalStyle)
gc.fill('green')
gc.stroke('transparent')
gc.text(x, y, "'#{x.to_i},#{y.to_i}'")
gc.text(minX, minY, "'#{minX.to_i},#{minY.to_i}'")
gc.text(maxX, maxY, "'#{maxX.to_i},#{maxY.to_i}'")
end
else
x1 = rand( minX..maxX )
y1 = rand( minY..maxY )
cx1 = rand( minX..maxX )
cy1 = rand( minY..maxY )
x2 = rand( minX..maxX )
y2 = rand( minY..maxY )
cx2 = rand( minX..maxX )
cy2 = rand( minY..maxY )
mx =
x3 = rand( minX..maxX )
y3 = rand( minY..maxY )
cx3 = rand( minX..maxX )
cy3 = rand( minY..maxY )
gc.bezier( x1, y1, cx1, cy1, cx2, cy2, x2, y2, x2 + (x2 - cx2).abs, y2 + (y2 - cy2).abs, cx3, cy3, x3, y3 )
end
gc.draw img
end
end
img.write( output ) {
self.quality = 50 # 1~100
}
puts img.inspect
end
3.times do |n|
gen_line_sketch "/Users/Kanbaru/Downloads/第1周/第1天/4.临摹单个颜色的副本.jpg", "/Users/Kanbaru/Downloads/第1周/第1天/1.复制单根线条_gen_#{n + 1}.jpg"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment