Skip to content

Instantly share code, notes, and snippets.

@jaymcgavren
Created May 15, 2019 07:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaymcgavren/12d07800869806c9a16c172a2fa4af2c to your computer and use it in GitHub Desktop.
Save jaymcgavren/12d07800869806c9a16c172a2fa4af2c to your computer and use it in GitHub Desktop.
"quadraticvertex" sample from ruby-processing, ported to Visor.
# sketch by Jan Vantomme
# Part of a series of articles on Processing 2.
# Blog post here:
# http://vormplus.be/blog/article/drawing-shapes-with-quadratic-vertices
# translated for ruby-processing by Martin Prout
# translated for Visor by Jay McGavren
attr_reader :debug, :step_angle, :cr, :detail
@debug = false
@detail = 7
smooth 8
@x ||= 100
def draw
background 0
translate width / 2, height / 2
@step_angle = TAU / (detail.to_i - 1)
fill 255
no_stroke
@cr = map(@x, 0, width, 20, 200)
begin_shape
detail.to_i.times do |i|
if (i == 0)
vertex cos_x(i), sin_y(i)
else
quadratic_vertex cos_cx(i), sin_cy(i), cos_x(i), sin_y(i)
end
end
end_shape(CLOSE)
if debug
# draw lines between points
stroke_weight(1)
no_fill
stroke(0)
begin_shape
detail.to_i.times do |i|
vertex cos_cx(i), sin_cy(i) unless i == 0
vertex cos_x(i), sin_y(i)
end
end_shape CLOSE
# draw points
stroke_weight 8
detail.to_i.times do |i|
stroke 0
point cos_x(i), sin_y(i)
stroke 255, 0, 0
point cos_cx(i), sin_cy(i)
end
end
end
def cos_x(n)
cos(step_angle * n) * 100
end
def sin_y(n)
sin(step_angle * n) * 100
end
def cos_cx(n)
cos(step_angle * n - (step_angle / 2)) * cr
end
def sin_cy(n)
sin(step_angle * n - (step_angle / 2)) * cr
end
def toggle_debug
@debug = !debug
end
# The MIT License (MIT)
#
# Copyright (c) 2019 Jay McGavren
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment