One 、 Preface
While browsing some image websites , I often see a lot of beautiful star maps , such as , The picture below . In fact, the effect of this star image , It can also be done through html+css Style and js The way to achieve . Today, I’ll show you how to achieve the effect of star map .
Two 、 Project preparation
Software :Dreamweaver
3、 … and 、 Goals achieved
Each refresh produces a random number of stars . Display on canvas .
Four 、 Project implementation
1. establish canvas canvas
<body>
<canvas id='canvas'></canvas>
</body>
2. add to css style .
to canva Canvas with borders , Convenient observation .
<style type="text/css">
canvas{
border:2px solid #f00;
}
</style>
3. add to js style
3.1 Set up canvas Canvas size , Definition requires variables .
<script type="text/javascript">
var _canvas=document.getElementById("canvas")
_canvas.width=500;
_canvas.height=500;
var r,g ,b,a;
</script>
3.2 Generate random circles .
for (var j = 0; j < 150; j++) {
arc.x=Math.floor(Math.random()*_canvas.width);
arc.y=Math.floor(Math.random()*_canvas.height);
arc.r=Math.floor(Math.random()*31+10);
r=Math.ceil(Math.random()*256);
g=Math.ceil(Math.random()*256);
b=Math.ceil(Math.random()*256);
a=Math.random();
darw();
}
3.3 Definition draw() Method , By drawing the star formula , Turn a circle into a star for The cycle produces stars with random positions .
How to draw stars ?( Formula analysis )( Picture source: Baidu )
Stars have inscribed circles and circumscribed circles , The angle between each two points is fixed , So you can get the coordinates of each point of the star , Draw the stars .
/* Random stars */
for (var i = 0; i < 5; i++) {
_ctx.lineTo(Math.cos((18+72*i)/180*Math.PI)*arc.r+arc.x, -Math.sin((18+72*i)/180*Math.PI)*arc.r+arc.y);
_ctx.lineTo(Math.cos((54+72*i)/180*Math.PI)*arc.r/2+arc.x, -Math.sin((54+72*i)/180*Math.PI)*arc.r/2+arc.y);
}
3.4 Randomly generate color .
Math Functions are generated randomly 0-225 Of RGB value .
/* Random color */
_ctx.fillStyle="rgba(" + r + "," + g + "," + b + "," + a + ")";
_ctx.fill();
_ctx.strokeStyle="rgba(" + r + "," + g + "," + b + "," + a + ")";
_ctx.stroke();
}
3.5. call draw() Method implementation function .
darw();
5、 … and 、 Effect display
1、 Click on f12 Run to browser
2、 Every time you refresh the page , Randomly produce different stars and random colors .
6、 … and 、 summary
-
This project uses canvas canvas , Achieve the effect of star map , And in the use of javascript When you have a star effect , Some difficulties encountered are analyzed and solutions are provided .
-
Welcome to try , Sometimes it’s easy to see someone else do it , But when it comes to doing it yourself , There will always be all kinds of problems , Don’t hold your eyes high or your hands low , Do it frequently , Can understand more deeply .
-
The code is simple , Hope to inspire you .
Want to learn more about the front end 、Python Reptiles 、 Big data and other computer knowledge , Please go to :http://pdcfighting.com/ Want to learn more Python Web crawler and data mining knowledge , Go to a professional website :http://pdcfighting.com/
sildenafil generic price viagra from canada generic viagra mexico
cephalexin 250mg dosage how long does it take for cephalexin to work on a toothache does cephalexin show up on a drug test
cephalexin eat with food cephalexin what’s it used for cephalexin (keflex)
is cephalexin for dogs the same as for humans keflex nursing mother preseptal cellulitis keflex
keflex ingrown toenail keflex dose cellulitis is clindamycin and cephalexin the same
amoxicillin and birth control pills is penicillin stronger than amoxicillin how often to take amoxicillin 500
augmentin per placche alla gola bambini augmentin left out overnight co-amoxiclav augmentin ds
dose antibiotico augmentin augmentin pies diarrhea caused by augmentin
can amoxicillin cause swelling in legs can amoxicillin treat uti does amoxicillin cause yeast infections
human amoxicillin for cats dosage chart how long for amoxicillin to work amoxicillin and acetaminophen
doxycycline dosage acne 200mg doxycycline and weed does doxycycline need to be taken with food
can you overdose on doxycycline does doxycycline treat staph can i take azithromycin and doxycycline together for chlamydia
can i take prednisone at night prednisone 060 topical prednisone
can you get vaccines while on prednisone does prednisone cause diabetes prednisone at night
ciprofloxacin and myasthenia gravis ciprofloxacin and bactrim together ciprofloxacin 500mg dosage for diverticulitis
augmentin while breastfeeding what are the side effects of augmentin can you drink on augmentin
where can i buy viagra over the counter in usa how to buy viagra online in india viagra otc in canada
sildenafil 50 mg online uk price of viagra generic canadian viagra no prescription
tadalafil walgreens tadalafil citrate dosage max dosage of cialis
female viagra india price sildenafil otc nz generic viagra online canadian
top essay writers academic essay writing service legitimate essay writing service
essay for high school interview essay college application essay writers
what is a rhetorical analysis essay how many paragraphs are in an essay essay outline help
essay writing services usa best custom essay website professional grad school essay writers
how to write an outline for an essay best article writing service the help essay questions
polish pharmacy online usa which online pharmacy is the best klonopin online pharmacy
cialis generic pharmacy online pill pharmacy nexium indian pharmacy
peoples rx pharmacy austin metronidazole cream online pharmacy publix pharmacy lisinopril
tadalafil every day how much tadalafil to take how to take tadalafil 20 mg
tadalafil jelly is tadalafil covered by medicare tadalafil nose bleed
tadalafil 20mg how long does it last how to get tadalafil out of your system generic for cialis tadalafil
tadalafil 100 mg alcohol with tadalafil best time to take tadalafil 20 mg
coupon for tadalafil how to take tadalafil 20 mg tadalafil 20 mg para que sirve precio
tadalafil 5mg tablets when does tadalafil go generic wellbutrin and tadalafil
reddit tadalafil difference between tadalafil and viagra tadalafil adcirca info
tadalafil powder ziphealth tadalafil taking tadalafil and sildenafil together
tadalafil (cialis) price tadalafil 25mg can you take 40 mg of tadalafil
can you take tadalafil with alcohol tadalafil chewable cost of 5 mg tadalafil pills