Notebook - Welcome to Notebook

Contact/Report Bugs
You can contact me at: bkenwright@xbdev.net












Retro Game Programming Kenwright Description Resizeable rotatable and draggable div element Dynamically added on the fly click button to add more elements to the screen html head head body script const maxobjs 100 var numobjs2 0 var objs function cleardraw2 numobjs2 0 for let i 0 i objs length i objs i style left 1000px function setupdraw numobjs2 0 for let i 0 i maxobjs i let div document createElement div document body appendChild div objs push div setupdraw helper function for drawing lines using div elements use a bit of trigonometry to set the size and orientation to create a line function drawLine s0 s1 col blue let ax s0 x let ay s0 y let bx s1 x let by s1 y console log numobjs2 console assert numobjs2 maxobjs let div objs numobjs2 numobjs2 if div 0 div document createElement div document body appendChild div div style position absolute if ay by bx ax bx ax bx ax bx bx ax by ay by ay by ay by by ay let calc Math atan ax bx by ay calc calc 180 0 Math PI let length Math sqrt ax bx ax bx ay by ay by div style height length px div style width 2 px div style left ax px div style top ay px div style transform rotate calc deg div style transformOrigin 0 0 div style backgroundColor col blue div style z index 999 function drawCross v0 s 20 col green drawLine x v0 x s y v0 y x v0 x s y v0 y col drawLine x v0 x y v0 y s x v0 x y v0 y s col function vec2 x y this x x this y y this set function x y this x x this y y vec2 add function v0 v1 return new vec2 v0 x v1 x v0 y v1 y vec2 sub function v0 v1 return new vec2 v0 x v1 x v0 y v1 y vec2 scale function v0 s return new vec2 v0 x s v0 y s vec2 cross function v0 v1 return v0 x v1 y v0 y v1 x vec2 dot function v0 v1 return v0 x v1 x v0 y v1 y note you can t use length word vec2 length function v0 return Math sqrt v0 x v0 x v0 y v0 y vec2 dist function v0 return Math sqrt v0 x v0 x v0 y v0 y vec2 norm function v0 let ln Math sqrt v0 x v0 x v0 y v0 y return vec2 scale v0 1 0 ln vec2 perp function n return new vec2 n y n x vec2 rot function v ang let ca Math cos ang radians let sa Math sin ang return new vec2 ca v x sa v y sa v x ca v y script style resizable background orange width 100px height 100px position absolute top 100px left 100px transform rotate 0rad cursor move z index 10 resizers width 100 height 100 border 3px solid 4286f4 box sizing border box resizer width 10px height 10px border radius 50 background white border 3px solid 4286f4 position absolute resizable resizers resizer width 10px height 10px border radius 50 background white border 3px solid 4286f4 position absolute resizable resizers resizer top middle left 50 top 5px cursor pointer transform translateX 50 resizable resizers resizer top left left 5px top 5px cursor crosshair resizable resizers resizer top right right 5px top 5px cursor crosshair resizable resizers resizer bottom left left 5px bottom 5px cursor crosshair resizable resizers resizer bottom right right 5px bottom 5px cursor crosshair style div style border 2px solid black width 90 height 20 text align center cursor pointer onclick addResizer Add Resizer div div id bob class resizable style left 550px top 200px div class resizers div id ss class resizer top middle div div id r1 class resizer top left div div id r2 class resizer top right div div id r3 class resizer bottom left div div id r4 class resizer bottom right div div div div id bob2 class resizable style left 250px top 200px background green div class resizers div id ss class resizer top middle div div id r1 class resizer top left div div id r2 class resizer top right div div id r3 class resizer bottom left div div id r4 class resizer bottom right div div div script function addResizer let p document getElementById bob let bob3 p cloneNode true bob3 style left 10 100 Math random px bob3 style top 10 100 Math random px bob3 style transform rotate 0 rad bob3 style transform origin left top bob3 ang 0 bob3 style width 100px bob3 style height 100px var randomColor Math floor Math random 16777215 toString 16 bob3 style background randomColor document body appendChild bob3 setupResize bob3 function setupResize bobdiv let els bobdiv getElementsByTagName div for let k 0 k els length k if els k className resizer top middle bobdiv r0 els k if els k className resizer top left bobdiv r1 els k if els k className resizer top right bobdiv r2 els k if els k className resizer bottom right bobdiv r3 els k if els k className resizer bottom left bobdiv r4 els k bobdiv ang 0 bobdiv onmousedown mouseDownDrag bobdiv r0 onmousedown mouseDownRotate bobdiv r1 onmousedown mouseDownResize bobdiv r2 onmousedown mouseDownResize bobdiv r3 onmousedown mouseDownResize bobdiv r4 onmousedown mouseDownResize bobdiv style transform origin left top let divResizers document getElementsByClassName resizable for let rr 0 rr divResizers length rr var bobdiv document getElementById bob let div divResizers rr setupResize div let center x 0 y 0 let offset x 0 y 0 let pos x 0 y 0 let size w 0 h 0 let seldrag 0 let selrot 0 let selres 0 window onmousemove mouseMoveRotate window onmousemove mouseMoveResize window onmousemove mouseMoveDrag window addEventListener mousemove mouseMoveRotate window addEventListener mousemove mouseMoveResize window addEventListener mousemove mouseMoveDrag window onmouseup function e seldrag 0 selrot 0 selres 0 function mouseDownResize event event preventDefault event stopImmediatePropagation selres event target let div selres parentNode parentNode if div style transform origin left top div style transform origin left top let w div offsetWidth let h div offsetHeight console log w w h h let p new vec2 w 0 5 h 0 5 let d new vec2 w 0 5 h 0 5 p_ vec2 rot d div ang let poff vec2 sub p p_ let topleft x 0 y 0 topleft x parseFloat div style left topleft y parseFloat div style top div style left topleft x poff x px div style top topleft y poff y px pos x selres offsetParent offsetLeft pos y selres offsetParent offsetTop size w selres offsetParent offsetWidth size h selres offsetParent offsetHeight let mid x pos x size w 0 5 y pos y size h 0 5 offset x event pageX offset y event pageY function mouseMoveResize event if selres 0 return let div selres parentNode parentNode console assert div style transform origin left top if selres className resizer top right let dxx event pageX offset x let dyy event pageY offset y let mp new vec2 event pageX event pageY let up vec2 rot new vec2 0 1 div ang let right vec2 rot new vec2 1 0 div ang let tr div r1 let dx vec2 dot right new vec2 event pageX offset x event pageY offset y let dy vec2 dot up new vec2 event pageX offset x event pageY offset y let width size w dx let height size h dy if width 30 div style width width px if height 30 div style left pos x up x dy px div style top pos y up y dy px div style height height px if selres className resizer bottom right let up vec2 rot new vec2 0 1 div ang let right vec2 rot new vec2 1 0 div ang let dx vec2 dot right new vec2 event pageX offset x event pageY offset y let dy vec2 dot up new vec2 event pageX offset x event pageY offset y let width size w dx let height size h dy if width 30 div style width width px console log height if height 30 div style height height px return if selres className resizer bottom left let up vec2 rot new vec2 0 1 div ang let right vec2 rot new vec2 1 0 div ang let dx vec2 dot right new vec2 event pageX offset x event pageY offset y let dy vec2 dot up new vec2 event pageX offset x event pageY offset y let width size w dx let height size h dy if height 30 div style height height px if width 30 div style left pos x right x dx px div style top pos y right y dx px div style width width px return if selres className resizer top left let up vec2 rot new vec2 0 1 div ang let right vec2 rot new vec2 1 0 div ang let dx vec2 dot right new vec2 event pageX offset x event pageY offset y let dy vec2 dot up new vec2 event pageX offset x event pageY offset y let width size w dx let height size h dy let left pos x let top pos y if width 30 width 30 dx width size w if height 30 height 30 dy height size h left left right x dx top top right y dx left left up x dy top top up y dy div style width width px div style height height px div style left left px div style top top px return function mouseDownRotate event event preventDefault event stopImmediatePropagation selrot event target let div selrot parentNode parentNode if div style transform origin center center div style transform origin center center let w div offsetWidth let h div offsetHeight let p new vec2 w 0 5 h 0 5 console log w w h h let d new vec2 w 0 5 h 0 5 p_ vec2 rot d div ang let poff vec2 sub p p_ let topleft x 0 y 0 topleft x parseFloat div style left topleft y parseFloat div style top div style left topleft x poff x px div style top topleft y poff y px pos x selrot offsetParent offsetLeft pos y selrot offsetParent offsetTop center x div offsetLeft div offsetWidth 0 5 center y div offsetTop div offsetHeight 0 5 offset x event pageX offset y event pageY drawCross offset 40 drawCross pos 30 function mouseMoveRotate event if selrot 0 return let div selrot parentNode parentNode console assert div style transform origin center center let vref x 0 y 1 let v1 x center x event pageX y center y event pageY v1 vec2 norm v1 v2 vref let ang Math atan2 v1 y v1 x Math atan2 v2 y v2 x div style transform rotate ang rad div ang ang function mouseDownDrag event event preventDefault event stopImmediatePropagation seldrag event target let div seldrag parentNode let px div offsetLeft let py div offsetTop let shiftX event pageX px let shiftY event pageY py offset x shiftX offset y shiftY function mouseMoveDrag event if seldrag 0 return let div seldrag parentNode div style left event pageX offset x px div style top event pageY offset y px script body html

ndow onmousemove mouseMoveDrag window addEventListener mousemove mouseMoveRotate window addEventListener mousemove mouseMoveResize window addEventListener mousemove mouseMoveDrag window onmouseup function e seldrag 0 selrot 0 selres 0 function mouseDownResize event event preventDefault event stopImmediatePropagation selres event target let div selres parentNode parentNode if div style transform origin left top div style transform origin left top let w div offsetWidth let h div offsetHeight console log w w h h let p new vec2 w 0 5 h 0 5 let d new vec2 w 0 5 h 0 5 p_ vec2 rot d div ang let poff vec2 sub p p_ let topleft x 0 y 0 topleft x parseFloat div style left topleft y parseFloat div style top div style left topleft x poff x px div style top topleft y poff y px pos x selres offsetParent offsetLeft pos y selres offsetParent offsetTop size w selres offsetParent offsetWidth size h selres offsetParent offsetHeight let mid x pos x size w 0 5 y pos y size h 0 5 offset x event pageX offset y event pageY function mouseMoveResize event if selres 0 return let div selres parentNode parentNode console assert div style transform origin left top if selres className resizer top right let dxx event pageX offset x let dyy event pageY offset y let mp new vec2 event pageX event pageY let up vec2 rot new vec2 0 1 div ang let right vec2 rot new vec2 1 0 div ang let tr div r1 let dx vec2 dot right new vec2 event pageX offset x event pageY offset y let dy vec2 dot up new vec2 event pageX offset x event pageY offset y let width size w dx let height size h dy if width 30 div style width width px if height 30 div style left pos x up x dy px div style top pos y up y dy px div style height height px if selres className resizer bottom right let up vec2 rot new vec2 0 1 div ang let right vec2 rot new vec2 1 0 div ang let dx vec2 dot right new vec2 event pageX offset x event pageY offset y let dy vec2 dot up new vec2 event pageX offset x event pageY offset y let width size w dx let height size h dy if width 30 div style width width px console log height if height 30 div style height height px return if selres className resizer bottom left let up vec2 rot new vec2 0 1 div ang let right vec2 rot new vec2 1 0 div ang let dx vec2 dot right new vec2 event pageX offset x event pageY offset y let dy vec2 dot up new vec2 event pageX offset x event pageY offset y let width size w dx let height size h dy if height 30 div style height height px if width 30 div style left pos x right x dx px div style top pos y right y dx px div style width width px return if selres className resizer top left let up vec2 rot new vec2 0 1 div ang let right vec2 rot new vec2 1 0 div ang let dx vec2 dot right new vec2 event pageX offset x event pageY offset y let dy vec2 dot up new vec2 event pageX offset x event pageY offset y let width size w dx let height size h dy let left pos x let top pos y if width 30 width 30 dx width size w if height 30 height 30 dy height size h left left right x dx top top right y dx left left up x dy top top up y dy div style width width px div style height height px div style left left px div style top top px return function mouseDownRotate event event preventDefault event stopImmediatePropagation selrot event target let div selrot parentNode parentNode if div style transform origin center center div style transform origin center center let w div offsetWidth let h div offsetHeight let p new vec2 w 0 5 h 0 5 console log w w h h let d new vec2 w 0 5 h 0 5 p_ vec2 rot d div ang let poff vec2 sub p p_ let topleft x 0 y 0 topleft x parseFloat div style left topleft y parseFloat div style top div style left topleft x poff x px div style top topleft y poff y px pos x selrot offsetParent offsetLeft pos y selrot offsetParent offsetTop center x div offsetLeft div offsetWidth 0 5 center y div offsetTop div offsetHeight 0 5 offset x event pageX offset y event pageY drawCross offset 40 drawCross pos 30 function mouseMoveRotate event if selrot 0 return let div selrot parentNode parentNode console assert div style transform origin center center let vref x 0 y 1 let v1 x center x event pageX y center y event pageY v1 vec2 norm v1 v2 vref let ang Math atan2 v1 y v1 x Math atan2 v2 y v2 x div style transform rotate ang rad div ang ang function mouseDownDrag event event preventDefault event stopImmediatePropagation seldrag event target let div seldrag parentNode let px div offsetLeft let py div offsetTop let shiftX event pageX px let shiftY event pageY py offset x shiftX offset y shiftY function mouseMoveDrag event if seldrag 0 return let div seldrag parentNode div style left event pageX offset x px div style top event pageY offset y px script body html

2dracecargame
3dplot
a4print
about
acejs
acejs2
acejs3
aessecurity
angularjs
animbackgroundimage
aseformat
assert
asteroidsjs
backgrounds01
backgrounds02
backgrounds03
barnsleyfern
base26
base64
bib
binary
bodypix
bouncy
box2dweb
breakoutjs
browserversion
buslanes
busybutton
bvhreader
calendar
candycrush
candycrush2
canvas
canvas2
canvas3
canvasmandelbrot
canvasmandelbrot2
canvasnumbers
canvaszoom
capsule
changingimages
chaosgame
chaosrandom
chaosrandomhisto
chaosrandomhisto2
chatgptusingopenai
chatgptusingopenai2
chatgptusingopenai3
checkboxtoggle
chinesetiles
classes
classfeatures
clipboardbutton
clonenode
codedropdown
codemirror
codemirror2
collada
colorpick
columnresizer
contextmenu
convnet
cookiebanner
countdown
countdown2
countdown3
crop
css3dbarchart
css3dbarchart2
css3dbook
css3dscene
csscube
csscube2
csscube3
csscubevideos
cssfilelist
csshas
csspulse
cssresizeaspect
cssspin
csszooming
csvtoarray
curleffect
customcheckbox
d3datamap
d3js
d3js10
d3js11
d3js2
d3js3
d3js4
d3js5
d3js6
d3js7
d3js8
d3js9
d3jsanimatedgrid
d3jsarctransition
d3jsarctransition2
d3jsaxis
d3jsaxischanging
d3jsbars
d3jsbrushing
d3jsbuslanes
d3jsbuslanes2
d3jscalendar
d3jscheat
d3jsclock
d3jscloudmap
d3jscogs
d3jscolors
d3jscovid
d3jscovid2
d3jscovid3
d3jsdashboard
d3jsdashboard2
d3jsdashboard3
d3jsdatakeyfunction
d3jsdensity
d3jsdragresizing
d3jsdragresizing2
d3jseach
d3jsease
d3jsevents
d3jsflower
d3jsforcegroups
d3jsforces
d3jsforces2
d3jsfractaltree
d3jsgeo
d3jsgroupbars
d3jsgroups
d3jsheatmap
d3jshex
d3jshierarchies
d3jshierarchies2
d3jshistogram
d3jshistogram2
d3jshistogram3
d3jshistogram4
d3jsinterpolate
d3jsjoin
d3jskmean
d3jskmean2
d3jsline
d3jsline2
d3jsline3
d3jsline4
d3jslinetransition
d3jslinetransition0
d3jslinetransition2
d3jsmaplocations
d3jsmaps
d3jsmaps2
d3jsmaps3
d3jsmisc
d3jsmisc2
d3jsmodule
d3jsmodulecolor
d3jsmultistyles
d3jsnobel
d3jsoverlappinggraphs
d3jspanel
d3jspie
d3jspieinterpolate
d3jssankey
d3jssankey2
d3jsscatter
d3jsshapes
d3jsslider
d3jsspending
d3jsspending2
d3jsspiralplot
d3jsspirograph
d3jssquare
d3jsstack
d3jsstackedbar
d3jsstackedbar2
d3jssunburst
d3jssunmoon
d3jssvglines
d3jssymbols
d3jstimelines
d3jsuk
d3jsvoronoi
d3scatterplot
d3timeline
d3timeline2
datalist
datamuse
date
dblclickhighlight
deviceorientation
dictionaryapi
dockermenu
doodlepad
downloadgif
dragdroplistitems
dragrotateresizediv
dragrotateresizediv2
dragrotateresizediv3
dragrotateresizediv4
dragrotateresizefontsize
dragselectbrush
drawlinesdiv
dropdown
dualquaternionimages
dynamicgrid
easefunctions
easeinterpolate3dplots
echart
echart2
echart3
encapsulation
epubviewer
errorstack
excalidraw
excalidraw2
excalidraw3
excalidraw5
expandable
faker
fetchplus
fileupload
fixedtopbar
fluiddynamics
fluiddynamics2
fluiddynamics3
fluidsmokedynamics
fluidsmokedynamics2
fonts
fonts2
footerbar
fractalmaze
fractalmaze2
fractalnoiseimage
fractals
fractals2
fractaltree
freesvg
fresnel
froggerjs
gantt
gifgiphyapi
gifhex
gltffromscratch
gradients
griditems
griditems2
griditems3
griditems4
gridworms
heat
hexview
hexview2
highlight
icons
icons2
iframes
ik
imagetracertosvg
imgur
inputfile
invadersjs
ipynb
ipynb2
ipynb3
ipynb4
isbn13
isbn2
jpghex
jquery
jquery2
jqueryui
jqueryui2
jsdraganddrop
jsfire
jslint
jsobfuscate
jsraytracer
jstree
jstree2
jszip
jszipimages
jszipread
keyframes
l2dwidget
lda
leftmenu
less
less2
lineargradientimage
linenumbers
loadimagefromfile
makepdf
maps
markdown
markdown2
markdownalerts
markdownalerts2
markdownbookmarks
markovimage
markovpixelblocks
mathjax
matrices
matsandvects
mazegamejs
md2tex
metrotiles
metrowindows
milestones
minkowski2dboxes
misc
misc2
modules
myipdetails
neataptic
networkstructures
networkstructures2
neural_network_drawshape
neural_network_plot_in_vs_out
neuralnetworkarrays
neuralnetworkblocks
neuralnetworksinewave
neuralnetworksnolibs
neuralnetworkvisualization
number
obj
objtojson
openaiimages
opencv
opencv2
opencv3
opencv4
opencv5
outline
p2
p5fractalleaf
p5fractalshape
p5js
p5js2
p5js3
p5jsanimatedcover
p5mengercube
p5snowflakes
palindrome
panel
parallax
paste
paste2
pasteimgfromurl
pdfjs
pdfjs2
pdfkit
pdfkit2
pdfkit3
pdfkit4
pdfkit5
pdfkit6
pdfmake
pdfmake2
pdfmake3
pdfmake4
pdfmake5
pdfmake6
perlin
perlin2
perlin3
perspective
pexels
pixelgridpattern
playground
plotly
plotlynoise
plotlyranddist
plyloader
plyloader2
pngtxtencoder
pongjs
pptxgenjs
prettycode
prism
prn
problems
progress
pseudorandom
px2svg
python
quotes
racergame
random
randomcalcpie
randomgenerator
randomprofilepatterns
randomsinhistogram
randomstring
rating
rayambient
raymonte
raymonteprogressive
raymonteprogressive2
raymontewarmstart
reexpcross
reexpcross2
regex
regexbib
regexpfixbib
regexpmultiline
repeatwordsregexp
resizabletable
resizabletable2
revealjs
revealjs2
revealjsmulti
ritalanguage
ritalanguage2
ritalanguage3
rotateimg
rough
rsapublicprivatekeys
rss
rss2
sankey
scrappingsvg
scrolltext
scrolltext2
scrollwidth
sdf2dcanvas
sdfboxinboxtwist
sdfchessbishop
sdfchessking
sdfchessknight
sdfchesspawn
sdfchessqueen
sdfchessrook
sdfhollowbox
setintervalexception
shareurl
shuffle
sidecomment
similarity
simplehighlighter
simpleplatformgamejs
sinecanvas
sliderpopout
slides
smileys
snowfall
snowman
sound
soundsignal
sphererayintersection
springs
sqljs
steganography
stereogram
stringmatching
svg
svgchaos
svgdragresize
svgdragresize2
svgdragresize3
svgdragrotate
svgdrawing
svglines
svglines2
svglines3
svglines4
svglines5
svglinesmandelbrot
svgpathsdragrotate
svgpathsdragrotateresize
svgpie
svgpie2
svgpie3
svgpiepath
svgpiepath2
svgrandomfaces
symbols
synaptic
synaptic2
synonyms
tablerotatecells
tablerotatecells2
tablerotatecells3
tablerotatecells3b
tablerotatecells4
tables
tablezebra
tabularjs
tabularjs2
tabulatordownload
tagcanvas
tensorflowgan
tensorflowjs
tensorflowjsbasic
tensorflowjscnn
tensorflowjssinewave
tensorflowjssound
tensorflowmobilenet
tetrahedronfractal
tetrahedronfractalfolding
tetris
textarea
textareaauto
textareadiv
textareadiv2
textmaskimage
theirorthere
thesaurus
threejs
threejs2
threejs3
threejs4
threejsgltf
threejstokyo
tiles
toaster
tooltip
transition
transitionexpandabledropdown
treeview
treeview2
tricks
tshirt
tshirt2
tshirt3
turningpages
unsplash
urlblob
urlblob2
userdefinepoints
vector
videos
videos2
visualsort
vue
w2ui
w2uientertextdialog
webcam
webgl
webgl2
webgl3
webgl4
webgl5
webglbasic1
webglbasic2
webglcube
webglfov
webglfrustum
webgljson
webglleaves
webgllighting
webglorthographic
webglpoints1
webglpoints2
webglpoints3
webglsquare
webgltexture1
webgltexture2
webgltexture3
webgltransforms
webgltriangle
webgpu
webgpu10
webgpu11
webgpu12
webgpu13
webgpu14
webgpu15
webgpu16
webgpu17
webgpu2
webgpu3
webgpu4
webgpu5
webgpu6
webgpu7
webgpu8
webgpu9
webgpubars
webgpubuffers
webgpubuffers2
webgpucellnoise
webgpuclouds
webgpuclydescope
webgpucompute
webgpucubemap
webgpucubemap2
webgpudeferred
webgpudepth
webgpudof
webgpudrops
webgpuetha
webgpufire
webgpufractalcubes
webgpuglassrain
webgpugltf
webgpugltf2
webgpugrass
webgpugrid
webgpukernel
webgpukleinian
webgpulabupdates
webgpulighting
webgpumandelbrot
webgpumeta3d
webgpumetaballs
webgpumouse
webgpunoise
webgpunormalmapping
webgpuobj
webgpuparallax
webgpuparallax2
webgpuparallax3
webgpuparallaxshadow
webgpuparallaxshadow2
webgpupixel
webgpuquad
webgpuray1
webgpuraytracing
webgpuraytracing2
webgpushadowmaps
webgpushadowmaps2
webgpusierpinski2d
webgpusierpinski3d
webgpusinusoid
webgpussao
webgpustadiumobj
webgpuswirl
webgputestpipe3
webgputoon
webgputopology
webgputt
webgpuvolcloud
webgpuwater
webgpuwireframe
webgpuwireframe2
webpcanvas
webworkers
webxr
webxr2
wiggly
wikipedia