Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graphics new method 'drawPolygon' #1058

Open
hsk-kr opened this issue Jan 22, 2021 · 7 comments
Open

Graphics new method 'drawPolygon' #1058

hsk-kr opened this issue Jan 22, 2021 · 7 comments
Assignees

Comments

@hsk-kr
Copy link

hsk-kr commented Jan 22, 2021

/**
 * Draw Polygon
 * @param {[x, y][]} posList Position List
 */
createjs.Graphics.prototype.drawPolygon = function (...posList) {
  const copyPosList = [...posList];
  if (copyPosList.length === 0) return this;
  const firstPos = copyPosList.splice(0, 1)[0];
  let chain = this.moveTo(firstPos[0], firstPos[1]);
  for (const pos of copyPosList) chain = chain.lineTo(pos[0], pos[1]);
  return chain.lineTo(firstPos[0], firstPos[1]);
};

This is a method that I defined in my project.
I searched for that how to draw polygon using EaselJS.
There were no methods of that. people have their own method for drawing a polygon.
It's not that hard to make your own method for it.
But I think It would be better that EaselJS provides us the method.

@danzen
Copy link
Contributor

danzen commented Jan 22, 2021

Very nice. There is a drawPolyStar for regular polygons with a tiny API of dp(). I guess something like pg() might work - anyone else have a thought? I know most draws start with d but not drawRoundRectComplex. Another option might be dg(). We could double up in the chart below with dp/pg.

Another thing that I have found that even if you cp() a the end - which may be done automatically under the hood, that the line corner does not take the same corner point setting. So I think on our version of createjs drawPolyStar for ZIM, we keep going for one more turn - we will check that out as we consider the addition.

image

@danzen danzen self-assigned this Feb 7, 2021
@danzen
Copy link
Contributor

danzen commented Mar 27, 2021

@hsk-kr - would you like to try a pull request? Also, note that the version 1 of CreateJS is ES5. If that is too much to ask, we can recode it. Also, when you do, I would suggest wrapping around beyond the end point to the second point again so that the bevel or miter on the polygon is consistent. Otherwise, even with cp() it is just straight line across. See #1046

@hsk-kr
Copy link
Author

hsk-kr commented Mar 27, 2021

I haven't used CreateJS for a while because of my works. when I have some time, I'll try it.
Thanks for your suggestion.

@danzen
Copy link
Contributor

danzen commented Apr 2, 2021

@hsk-kr I coded this in es5. In ZIM we offer options for parameters like pass in [{x,y},}{x,y}] or [[x,y],[x,y]] or [x,y,x,y,x,y] or x,y,x,y,xy - it takes a few lines to test this and accommodate this. For createjs do we think it is best to offer one way for minimal size? It seems that way, so we will probably use one way. The question is... which way is consistent with the others. Graphics.BezierCurveTo ( cp1x, cp1y, cp2x, cp2y, x, y ) uses individual parameters. This I think is a little harder to use for a series of points - not so bad with the ES6 spread operator but annoying in ES5. I think the array of arrays is probably the most organized and basic way. That is the way that you chose and that seems based on other library implementations I presume.

I have yet to work out how to change the docs - but will add the code to the Graphics class and post here.

@danzen
Copy link
Contributor

danzen commented Apr 2, 2021

This has been committed - thanks @hsk-kr for the suggestion!
5366838

Not in the docs yet... so will leave this open until that happens.

@danzen danzen pinned this issue Apr 2, 2021
@danzen danzen unpinned this issue Apr 2, 2021
@danzen
Copy link
Contributor

danzen commented Apr 2, 2021

Here is an example of it working on the ZIM version of CreateJS - with same code as added to the repo here.
https://zimjs.com/explore/molnar.html
image

@hsk-kr
Copy link
Author

hsk-kr commented Apr 3, 2021

I'm sorry. I couldn't give you a good advice.
Thanks for taking my opinion.

danzen added a commit to danzen/zimjs that referenced this issue Apr 18, 2021
CAT 04 - Codename Diamond

ZIM EASE
https://zimjs.com/ease
Customize the easing equation with sliders
and pass results into ZIM animate()
Looks like this ease:zimEase([1.746,0.4,-0.91,0.8])
Added "snap", "ballistic" and "slowmo" eases with In, Out and InOut settings
These act like the existing eases "elasticIn", "backInOut", etc.
See https://zimjs.com/cat/easeexamples.html

ZAPPS TOOL -- PWA 82.4
https://zimjs.com/zapps.html
Made a tool to create and zip the files for a PWA (Progressive Web App)
This looks like Distill, Wonder and AssetTool (which have been slightly modernized).
This was quite a large undertaking and we hope it turned out well.
The system takes the place of 70 steps to make mobile apps using GitHub, PhoneGapBuild, signing keys, etc.
Added a PWA() class in ZIM that the tool will insert (or can be done manually)
This is used to make a custom message when on mobile browser to add to mobile home screen (A2HS)
The rest of the system creates the following files:
    manifest.json
    serviceworker.js
    libraries/ directory with local zim and createjs files
    icons/ directory with icons
    zapp.html with file calls and meta tags (and PWA call)
    readme.txt - with instructions to replace index with zapp.html code
The code page has been updated to feature the tool (see Code Page updates)

ZAPPS vs ZAP
We know that we already have a ZIM Zap tool down in the gold bars
this is for sharing files and will remain as is.
We will refer to the new Zapps tool in the plural.
Zapps is how we would like to refer to the projects we make with ZIM
You are welcome to call your projects Zapps too - or a Zapp (singular)
It is Z for ZIM and apps for apps - but Zapps also sound really fast!
And that is a great thing about ZIM - we can make apps fast!  Zapps!

SVG ASSETS
https://zimjs.com/cat/svg.html
SVG is now automatically converted to a Bitmap - thanks carddealer for the prompting
when passed into the Frame assets parameter or frame.loadAssets() assets parameter.
This can be used directly as a bitmap with asset("pic.svg").center(); etc;
The original SVG is available as an svg property on the bitmap.
The original SVG can be used in SVGContainer() to make it editable with Blob, Squiggle and transform.
The SVGContainer is still considered experimental and may not accept all SVG
But a while back, it was improved to handle arcs properly.
Added width and height parameters to svgToBitmap()
Added params parameter to svgToBitmap to pass object through to callback after bitmap param
used internally by Frame to handle SVG images

TIMECHECK
now defaults to false.  You can turn it to true to make sure that your times are good.

MOBILE FPS
Default FPS for mobile has been changed from 30fps to 60fps now that most devices are more powerful
this can be set back with Ticker.setFPS(30,60); for 30 on mobile and 60 on desktop.

KIDS
https://zimjs.com/slate
Added Phone and Portrait CheckBoxes to ZIM Kids - thanks Karel Rosseel for the idea

KEYBOARD LAYOUTS
https://zimjs.com/cat/keyboard.html
Added layout parameter (at end) with "arabic", "hebrew", "turkish" and "azerty" settings (or "querty" default).
These change the data to show different keyboards.
Thanks Hussein Ghaly (arabic), Racheli Golan (hebrew), Ferudun Vural (turkish) and Karel Roseel (azerty).
Also added an override mapping for lower to upper and upper to lower case letters to the data parameter data.
Adjusted data to handle any number of rows (min 10) for custom layouts
And added a "back" special key that is like "backspace" but only takes up one key size
The "spacebar" now takes up whatever space is left so the bottom row is always at the max number of columns

GRID
Added allowToggle, cache and numbers parameters before style parameter
Added numbersX and numbersY properties to individually set visible false if desired
These changes make the Grid ready to be used for charts

GENERAL
Added dragPaused property to objects with drag() to pause or unpause dragging
this keeps setting like boundary where noDrag() does not
BREAK Added a corner parameter and property to Triangle after borderWidth and before center parameter
new Triangle(500,500,500,red,black,5,[20,20,100]).center()
A negative wait time can be provided to animations in the animate() series
this will start an animation before the previous animation ends - thanks Ami Hanya for the excellent idea
Added a toggle() method and toggled property to List when accordion is set
this will toggle the outermost (first) accordion - good for opening and closing a pulldown - thanks Ofweird Top for the suggestion!
Removed a test for touch to scroll page in tag mode if swiping on stage on allowDefault true
It was causing double mouse events - will see if we can figure out a way to do the page scroll.
updated the code page Organization to latest ZIM
Made Dial accept currentValue style - left it out previously
Made Slider and Dial accept VEE for min, max, step and currentValue
also set these so delayPick works for instance, when tiling
List animateTo() has its timePerItem fixed = was switched the wrong way for s/ms
Adjusted List to capture selectedIndex, selected when tabs are used
Adjusted List to animateTo() an item if tabbing and the item is not in view (top left reg assumed)
Tabs - added keyLoop parameter at end before style which defaults to true to wrap tabs when tab key reaches end or start
made List set keyLoop to false so List does not go past its ends when the tab key is used.
Made Layout accept DisplayObjects as region objects - for default values
eg. new Layout(stage, [header, content, footer]) gets converted to
new Layout(stage, [{object:header}, {object:content}, {object:footer}])
Made it so an object passed into Layout as a region will update its outline() if there is one
Made debug() chainable in physics (and updateDebug(), removeDebug())
Made ColorPicker have a selectedColor parameter along with the existing selectedIndex parameter
BREAK for the List accordion tree object, changed the arrow property to expander
with three types: "plus", "arrow" or "none" - thanks Ofweird Top for the suggestion.
Also adjusted list to not apply backgroundColor style for label (not item, but actual label) that messes up rollover and shade colors
Fixed ZIM ISO example https://zimjs.com/iso/ to not have scaling problem with older game module.

CODE PAGE
Updated Code template to include less comments.
Updated Meta Tags examples https://zimjs.com/templates/meta.html
Added FONT to ZIM Tips
Reorganized the Code Page as follows:
    removed the last sections: organization, treats, createjs, principles, programming
    and added them to a darkpaper page - linked to in the Code Help section.
    Converted these to ES6 as well.
    Shortened the template and removed the "minimal" template.
    Linked to more to get to the rest of the templates so removed the second template section.
    Added a FEATURES section with Mobile (Zapps), SHIM for Animate and Accessibility.
    This leaves the following sections:
    START, FEATURES, CDN, HELP, TOOLS and LIBRARIES
    Inserted a link bar to these in between each of the sections for easy navigation
    Took Badges out of HELP and added Medium and DevTO site in HELP.

CREATEJS GITHUB
updated ZIM CreateJS to 1.3.3 (Codename Diamond - 10 years!)
but also made the following legacy changes to the CreateJS GitHub repository:
Fixed Polystar last bevel or miter
CreateJS/EaselJS#1046
Added drawPolygon() and pg() graphics methods
CreateJS/EaselJS#1058
Adjusted MovieClip to not avoid extra processing if one frame
CreateJS/EaselJS#1048
Adjusted SoundJS XHR test locally as was giving errors for local sounds
It still gives a warning for needing to interact before playing sounds
We are not playing the sound but just testing
So we respond with a warning that says sounds are ready to play.
CreateJS/SoundJS@5213ac5
Adjusted TweenJS to add a hook for change tween properties dynamically
CreateJS/TweenJS@6df2b9c

NOT yet added to CreateJS repository - will test - but is in the ZIM 1.3.3 createjs:
Fixed selecting on touch screen on Chrome issue with allowDefault false
Thanks Ferudun for testing and thoughts.
CreateJS/EaselJS#997
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants