Last active
October 5, 2021 00:31
-
-
Save nanjizal/418d98e98f5e286468ae9cf17971d09d to your computer and use it in GitHub Desktop.
Broken Fixel test of cornerContour
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package; | |
import cornerContour.io.Float32Array; | |
// contour code | |
import cornerContour.Sketcher; | |
import cornerContour.SketcherGrad; | |
import cornerContour.Pen2D; | |
import cornerContour.Pen2DGrad; | |
import cornerContour.StyleSketch; | |
import cornerContour.StyleEndLine; | |
// SVG path parser | |
import justPath.*; | |
import justPath.transform.ScaleContext; | |
import justPath.transform.ScaleTranslateContext; | |
import justPath.transform.TranslationContext; | |
import flixel.FlxSprite; | |
import flixel.FlxState; | |
import openfl.Vector; | |
import flixel.FlxStrip; | |
import flixel.util.FlxColor; | |
// @credit: starry-abyss for setting up | |
class PlayState extends FlxState { | |
var pen2D: Pen2DGrad; | |
var g: FlxStrip; | |
var len: Int; | |
var totalTriangles: Int; | |
var bufferLength: Int; | |
var width = 1024; | |
var height = 768; | |
override public function create(){ | |
super.create(); | |
g = new FlxStrip(); | |
g.makeGraphic( 0, 0, FlxColor.WHITE ); | |
drawContours(); | |
rearrageDrawData(); | |
add(g); | |
} | |
public | |
function drawContours(){ | |
trace( 'drawContours' ); | |
pen2D = new Pen2DGrad( 0xFF0000FF ); | |
pen2D.currentColor = 0xff0000FF; | |
pen2D.colorB = 0xFF00FF00; | |
pen2D.colorC = 0xFF0000FF; | |
pentagram(); | |
//heptagram(); | |
//enneagram(); | |
} | |
var indices = new Array<Int>(); | |
var vertices = new Array<Float>(); | |
var uvs = new Array<Float>(); | |
var colors = new Array<Int>(); | |
public | |
function rearrageDrawData(){ | |
trace( 'rearrangeDrawData' ); | |
var pen = pen2D; | |
var data = pen.arr; | |
var colorA: Int = 0; | |
var colorB: Int = 0; | |
var colorC: Int = 0; | |
totalTriangles = Std.int( data.size/9 );//7 | |
var v = 0; | |
var c = 0; | |
var i = 0; | |
for( j in 0...totalTriangles ){ | |
pen.pos = j; | |
colors[ c ] = FlxColor.WHITE;//Std.int( data.colorA ); | |
c++; | |
colors[ c ] = FlxColor.WHITE;//Std.int( data.colorB ); | |
c++; | |
colors[ c ] = FlxColor.WHITE;//Std.int( data.colorC ); | |
c++; | |
vertices[ v ] = data.ax; | |
uvs[ v ] = gx( data.ax ); | |
v++; | |
vertices[ v ] = data.ay; | |
uvs[ v ] = gy( data.ay ); | |
v++; | |
vertices[ v ] = data.bx; | |
uvs[ v ] = gx( data.bx ); | |
v++; | |
vertices[ v ] = data.by; | |
uvs[ v ] = gy( data.by ); | |
v++; | |
vertices[ v ] = data.cx; | |
uvs[ v ] = gx( data.cx ); | |
v++; | |
vertices[ v ] = data.cy; | |
uvs[ v ] = gy( data.cy ); | |
v++; | |
indices[ i ] = j*3; | |
i++; | |
indices[ i ] = j*3+1; | |
i++; | |
indices[ i ] = j*3+2; | |
i++; | |
} | |
g.indices = new Vector( indices.length, true, indices ); | |
g.colors = new Vector( colors.length, true, colors ); | |
g.uvtData = new Vector( uvs.length, true, uvs ); | |
g.vertices = new Vector( vertices.length, true, vertices ); | |
} | |
override public function update(elapsed:Float){ | |
super.update( elapsed ); | |
} | |
/* -1 to 1 used in WebGL | |
public inline | |
function gx( v: Float ): Float { | |
return -( 1 - 2*v/width ); | |
} | |
public inline | |
function gy( v: Float ): Float { | |
return ( 1 - 2*v/height ); | |
} | |
*/ | |
// 0 to 1 | |
public inline | |
function gx( v: Float ): Float { | |
return v/width; | |
} | |
public inline | |
function gy( v: Float ): Float { | |
return v/height; | |
} | |
public | |
function enneagram(){ | |
var sketcher = new SketcherGrad( pen2D, StyleSketch.Fine, StyleEndLine.no ); | |
var sides = 9; | |
var angle: Float = turtleGram( 9 ); | |
sketcher.setPosition( 100, 100 )//700, 180 ) | |
.penSize( 10 ) | |
.yellow() | |
.penColorChange( -0.09, 0.01, 0.09 ) | |
.west() | |
.fillOff() | |
.beginRepeat( sides+1 ) // to make corners nice, do extra turn. | |
.archBezier( 300, 150, -10 ) | |
.right( angle ) | |
.penColorChange( -0.09, 0.01, 0.09 ) | |
.endRepeat() | |
.blue(); | |
} | |
inline | |
function turtleGram( sides: Int ){ | |
return 4.*(90.-360./sides); | |
} | |
public | |
function heptagram(){ | |
var sketcher = new SketcherGrad( pen2D, StyleSketch.Fine, StyleEndLine.no ); | |
sketcher.setPosition(700, 400 ) | |
.penSize( 10 ) | |
.plum() | |
.west() | |
.fillOff() | |
.beginRepeat( 7+1 ) // to make corners nice, do extra turn. | |
.archBezier( 300, 150, 30 ) | |
.right( 4*(90-360/7) ) | |
.penColorChange( 0.09, 0.1, -0.09 ) | |
.endRepeat() | |
.blue(); | |
} | |
public | |
function pentagram(){ | |
var sketcher = new SketcherGrad( pen2D, StyleSketch.Fine, StyleEndLine.no ); | |
// ( repeat 6 times so the star has last corner round. ) | |
sketcher.setPosition( 50, 150 ) | |
.penSize( 10 ) | |
.blue() | |
.west() | |
.fillOff() | |
.beginRepeat( 6 ) | |
.archBezier( 300, 150, 30 ) | |
.right( 144 ) | |
.penColorChange( 0.09, 0.1, -0.09 ) | |
.endRepeat() | |
.blue(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment