{"id":1175,"date":"2010-11-12T19:08:35","date_gmt":"2010-11-12T19:08:35","guid":{"rendered":"http:\/\/www.benoitfreslon.com\/?p=1175"},"modified":"2024-07-19T09:34:48","modified_gmt":"2024-07-19T07:34:48","slug":"actionscript-red-blood-cells-behavior","status":"publish","type":"post","link":"https:\/\/benoitfreslon.com\/fr\/news\/actionscript-red-blood-cells-behavior\/","title":{"rendered":"ActionScript: Red Blood Cells behavior"},"content":{"rendered":"<p>[swf:\/wp-content\/uploads\/2010\/11\/Blood1.swf 550 400]<\/p>\n<p>T\u00e9l\u00e9charger la source : <a href=\"https:\/\/benoitfreslon.com\/wp-content\/uploads\/2010\/11\/Blood.zip\">Blood.fla<\/a><\/p>\n<pre class=\"brush:as3\">import flash.geom.ColorTransform;\r\n\r\nvar arrBlood:Array = [];\r\n\r\nfunction createVers():void {\r\n\tvar b = new Blood();\r\n\tb.speedX = 0;\r\n\tb.speedY = 0;\r\n\tb.coefCollision = 50;\r\n\tb.coefRotation = 30;\r\n\tvar size:Number = Math.random();\r\n\r\n\tb.scaleX = size * .5 + .5;\r\n\tb.scaleY = size * .5 + .5;\r\n\tb.scale = b.scaleX;\r\n\tb.ray = b.width \/ 2.5;\r\n\tb.acc = true;\r\n\tb.acceleration = 1 + size * 1;\r\n\tb.coefDecceleration = 0.92 + size * 0.03;\r\n\tb.velocityMax = 4 + size * 4;\r\n\tb.velocity = 0;\r\n\tb.x = 400 * Math.random();\r\n\tb.y = 550 * Math.random();\r\n\tb.angle = 0;\r\n\tvar tint:Number = Math.random() * .7 + .3;\r\n\tb.transform.colorTransform = new ColorTransform(tint,tint,tint);\r\n\tcont.addChild(b);\r\n\tb.addEventListener(Event.ENTER_FRAME, versEnterFrame);\r\n\tarrBlood.push(b);\r\n}\r\n\r\nfunction getResAngleRad(angle1:Number,angle2:Number):Number {\r\n\tvar a:Number = angle1 - angle2;\r\n\tif (a &gt; Math.PI) {\r\n\t\ta = a - Math.PI * 2;\r\n\t} else if (a&lt;(-Math.PI)) { \t\ta = a + Math.PI * 2; \t} \treturn a; } function versEnterFrame(pEvt:Event):void { \tvar b:MovieClip = pEvt.currentTarget as MovieClip; \tvar angle:Number; \tif (b.acc) {\/\/trace(\"acc\") b.velocity += b.acceleration; \/\/trace(b.velocity) if (b.velocity &gt; b.velocityMax) {\r\n\t\tb.acc = false;\r\n\t} else {\r\n\t\tb.velocity *=  b.coefDecceleration;\r\n\t\tif (b.velocity &lt; 0.5) { \t\t\tb.acc = true; \t\t\tif (stage.mouseX &gt; 550 || stage.mouseY &gt; 400 || stage.mouseX &lt; 0 || stage.mouseY &lt; 0) {\r\n\t\t\t\tb.angle = Math.atan2(400\/2-b.y,550\/2-b.x);\r\n\t\t\t} else {\r\n\t\t\t\tb.angle = Math.atan2(stage.mouseY - b.y,stage.mouseX - b.x);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tb.scaleX = b.scale + (b.scale * 0.4) * b.velocity\/b.velocityMax;\r\n\tb.scaleY = b.scale - (b.scale * 0.4) * b.velocity\/b.velocityMax;\r\n\tvar angleSpeed:Number = Math.atan2(b.speedY,b.speedX);\r\n\tvar angleRes:Number = getResAngleRad(angleSpeed,b.angle);\r\n\t\/\/trace(angleRes)\r\n\tif (Math.abs(angleRes) &lt; 0.1) {\/\/trace(\"=\") } else if (angleRes &gt;0) {\r\n\t\tangleSpeed -=  Math.PI \/ b.coefRotation * b.velocity \/ b.velocityMax;\r\n\t\t\/\/trace(\"+\")\r\n\t} else if (angleRes &lt;0) {\r\n\t\tangleSpeed +=  Math.PI \/ b.coefRotation * b.velocity \/ b.velocityMax;\r\n\t}\/\/trace(\"-\")\r\n\r\n\tb.speedX = Math.cos(angleSpeed) * b.velocity;\r\n\tb.speedY = Math.sin(angleSpeed) * b.velocity;\r\n\r\n\tb.rotation = angleSpeed * 180 \/ Math.PI;\r\n\r\n\tb.x +=  b.speedX;\r\n\tb.y +=  b.speedY;\r\n\r\n\tfor (var i:String in arrBlood) {\r\n\t\tvar mc:MovieClip = arrBlood[i];\r\n\t\tvar dist:Number = getDistance(b,mc);\r\n\t\tif (dist &lt; b.ray+mc.ray) {\r\n\t\t\t\/\/trace(\"col\")\r\n\t\t\tvar a:Number = Math.atan2(b.y - mc.y,b.x - mc.x);\r\n\t\t\tb.x +=  Math.cos(a) * dist \/ b.coefCollision;\r\n\t\t\tb.y +=  Math.sin(a) * dist \/ b.coefCollision;\r\n\t\t\tmc.x -=  Math.cos(a) * dist \/ b.coefCollision;\r\n\t\t\tmc.y -=  Math.sin(a) * dist \/ b.coefCollision;\r\n\t\t}\r\n\t}\r\n}\r\n\r\nfunction getDistance(a:MovieClip,b:MovieClip):Number {\r\n\treturn Math.sqrt(Math.pow(a.x - b.x,2) + Math.pow(a.y - b.y,2));\r\n}\r\nfor (var i:int = 0; i&lt;100; i++) {\r\n\tcreateVers();\r\n}<\/pre>\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>[swf:\/wp-content\/uploads\/2010\/11\/Blood1.swf 550 400] T\u00e9l\u00e9charger la source : Blood.fla import flash.geom.ColorTransform; var arrBlood:Array = []; function createVers():void { var b =&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1],"tags":[],"class_list":["post-1175","post","type-post","status-publish","format-standard","hentry","category-news","wpcat-1-id"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>ActionScript: Red Blood Cells behavior - Beno\u00eet Freslon<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/benoitfreslon.com\/fr\/news\/actionscript-red-blood-cells-behavior\/\" \/>\n<meta name=\"twitter:label1\" content=\"\u00c9crit par\" \/>\n\t<meta name=\"twitter:data1\" content=\"Benoit Freslon\" \/>\n\t<meta name=\"twitter:label2\" content=\"Dur\u00e9e de lecture estim\u00e9e\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/benoitfreslon.com\\\/news\\\/actionscript-red-blood-cells-behavior\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/benoitfreslon.com\\\/news\\\/actionscript-red-blood-cells-behavior\\\/\"},\"author\":{\"name\":\"Benoit Freslon\",\"@id\":\"https:\\\/\\\/benoitfreslon.com\\\/#\\\/schema\\\/person\\\/fe9fe28a6b6c2b56648448b977fd6b78\"},\"headline\":\"ActionScript: Red Blood Cells behavior\",\"datePublished\":\"2010-11-12T19:08:35+00:00\",\"dateModified\":\"2024-07-19T07:34:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/benoitfreslon.com\\\/news\\\/actionscript-red-blood-cells-behavior\\\/\"},\"wordCount\":27,\"articleSection\":[\"Actualit\u00e9s\"],\"inLanguage\":\"fr-FR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/benoitfreslon.com\\\/fr\\\/news\\\/actionscript-red-blood-cells-behavior\\\/\",\"url\":\"https:\\\/\\\/benoitfreslon.com\\\/fr\\\/news\\\/actionscript-red-blood-cells-behavior\\\/\",\"name\":\"ActionScript: Red Blood Cells behavior - Beno\u00eet Freslon\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/benoitfreslon.com\\\/fr\\\/#website\"},\"datePublished\":\"2010-11-12T19:08:35+00:00\",\"dateModified\":\"2024-07-19T07:34:48+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/benoitfreslon.com\\\/#\\\/schema\\\/person\\\/fe9fe28a6b6c2b56648448b977fd6b78\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/benoitfreslon.com\\\/fr\\\/news\\\/actionscript-red-blood-cells-behavior\\\/#breadcrumb\"},\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[[\"https:\\\/\\\/benoitfreslon.com\\\/fr\\\/news\\\/actionscript-red-blood-cells-behavior\\\/\"]]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/benoitfreslon.com\\\/fr\\\/news\\\/actionscript-red-blood-cells-behavior\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/benoitfreslon.com\\\/fr\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"ActionScript: Red Blood Cells behavior\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/benoitfreslon.com\\\/fr\\\/#website\",\"url\":\"https:\\\/\\\/benoitfreslon.com\\\/fr\\\/\",\"name\":\"Beno\u00eet Freslon\",\"description\":\"[:en]Game designer | D\u00e9veloppeur de jeux ind\u00e9pendant | Freelance | Enseignant | Blogueur[:fr]Game designer | Independent game developer | Freelance | Teacher | Blogger[:]\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/benoitfreslon.com\\\/fr\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"fr-FR\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/benoitfreslon.com\\\/#\\\/schema\\\/person\\\/fe9fe28a6b6c2b56648448b977fd6b78\",\"name\":\"Benoit Freslon\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0b828da2527f91fb7c86dab67050492f4303279afa245d6e718ea1c6e6f00bb2?s=96&d=identicon&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0b828da2527f91fb7c86dab67050492f4303279afa245d6e718ea1c6e6f00bb2?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0b828da2527f91fb7c86dab67050492f4303279afa245d6e718ea1c6e6f00bb2?s=96&d=identicon&r=g\",\"caption\":\"Benoit Freslon\"},\"sameAs\":[\"https:\\\/\\\/benoitfreslon.com\",\"https:\\\/\\\/www.instagram.com\\\/benoitfreslon\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/benoitfreslon\",\"https:\\\/\\\/x.com\\\/BenoitFreslon\",\"https:\\\/\\\/www.youtube.com\\\/benoitfreslon\"],\"url\":\"https:\\\/\\\/benoitfreslon.com\\\/fr\\\/author\\\/admin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"ActionScript: Red Blood Cells behavior - Beno\u00eet Freslon","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/benoitfreslon.com\/fr\/news\/actionscript-red-blood-cells-behavior\/","twitter_misc":{"\u00c9crit par":"Benoit Freslon","Dur\u00e9e de lecture estim\u00e9e":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/benoitfreslon.com\/news\/actionscript-red-blood-cells-behavior\/#article","isPartOf":{"@id":"https:\/\/benoitfreslon.com\/news\/actionscript-red-blood-cells-behavior\/"},"author":{"name":"Benoit Freslon","@id":"https:\/\/benoitfreslon.com\/#\/schema\/person\/fe9fe28a6b6c2b56648448b977fd6b78"},"headline":"ActionScript: Red Blood Cells behavior","datePublished":"2010-11-12T19:08:35+00:00","dateModified":"2024-07-19T07:34:48+00:00","mainEntityOfPage":{"@id":"https:\/\/benoitfreslon.com\/news\/actionscript-red-blood-cells-behavior\/"},"wordCount":27,"articleSection":["Actualit\u00e9s"],"inLanguage":"fr-FR"},{"@type":"WebPage","@id":"https:\/\/benoitfreslon.com\/fr\/news\/actionscript-red-blood-cells-behavior\/","url":"https:\/\/benoitfreslon.com\/fr\/news\/actionscript-red-blood-cells-behavior\/","name":"ActionScript: Red Blood Cells behavior - Beno\u00eet Freslon","isPartOf":{"@id":"https:\/\/benoitfreslon.com\/fr\/#website"},"datePublished":"2010-11-12T19:08:35+00:00","dateModified":"2024-07-19T07:34:48+00:00","author":{"@id":"https:\/\/benoitfreslon.com\/#\/schema\/person\/fe9fe28a6b6c2b56648448b977fd6b78"},"breadcrumb":{"@id":"https:\/\/benoitfreslon.com\/fr\/news\/actionscript-red-blood-cells-behavior\/#breadcrumb"},"inLanguage":"fr-FR","potentialAction":[{"@type":"ReadAction","target":[["https:\/\/benoitfreslon.com\/fr\/news\/actionscript-red-blood-cells-behavior\/"]]}]},{"@type":"BreadcrumbList","@id":"https:\/\/benoitfreslon.com\/fr\/news\/actionscript-red-blood-cells-behavior\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/benoitfreslon.com\/fr\/"},{"@type":"ListItem","position":2,"name":"ActionScript: Red Blood Cells behavior"}]},{"@type":"WebSite","@id":"https:\/\/benoitfreslon.com\/fr\/#website","url":"https:\/\/benoitfreslon.com\/fr\/","name":"Beno\u00eet Freslon","description":"[:en]Game designer | D\u00e9veloppeur de jeux ind\u00e9pendant | Freelance | Enseignant | Blogueur[:fr]Game designer | Independent game developer | Freelance | Teacher | Blogger[:]","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/benoitfreslon.com\/fr\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"fr-FR"},{"@type":"Person","@id":"https:\/\/benoitfreslon.com\/#\/schema\/person\/fe9fe28a6b6c2b56648448b977fd6b78","name":"Benoit Freslon","image":{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/secure.gravatar.com\/avatar\/0b828da2527f91fb7c86dab67050492f4303279afa245d6e718ea1c6e6f00bb2?s=96&d=identicon&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/0b828da2527f91fb7c86dab67050492f4303279afa245d6e718ea1c6e6f00bb2?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0b828da2527f91fb7c86dab67050492f4303279afa245d6e718ea1c6e6f00bb2?s=96&d=identicon&r=g","caption":"Benoit Freslon"},"sameAs":["https:\/\/benoitfreslon.com","https:\/\/www.instagram.com\/benoitfreslon","https:\/\/www.linkedin.com\/in\/benoitfreslon","https:\/\/x.com\/BenoitFreslon","https:\/\/www.youtube.com\/benoitfreslon"],"url":"https:\/\/benoitfreslon.com\/fr\/author\/admin\/"}]}},"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/pLAe3-iX","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/benoitfreslon.com\/fr\/wp-json\/wp\/v2\/posts\/1175","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/benoitfreslon.com\/fr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/benoitfreslon.com\/fr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/benoitfreslon.com\/fr\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/benoitfreslon.com\/fr\/wp-json\/wp\/v2\/comments?post=1175"}],"version-history":[{"count":37,"href":"https:\/\/benoitfreslon.com\/fr\/wp-json\/wp\/v2\/posts\/1175\/revisions"}],"predecessor-version":[{"id":39133,"href":"https:\/\/benoitfreslon.com\/fr\/wp-json\/wp\/v2\/posts\/1175\/revisions\/39133"}],"wp:attachment":[{"href":"https:\/\/benoitfreslon.com\/fr\/wp-json\/wp\/v2\/media?parent=1175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/benoitfreslon.com\/fr\/wp-json\/wp\/v2\/categories?post=1175"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/benoitfreslon.com\/fr\/wp-json\/wp\/v2\/tags?post=1175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}