p5.js star example

The star() function created for this example is capable of drawing a wide range of different forms. Try placing different numbers into the star() function calls within draw() to explore.

by sam galison

HTML

<script src="//cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.9/p5.min.js"></script>

JavaScript

var life, pg, img

function preload() {
  img = loadImage("/img/logo.png");
}

function setup() {
	life = 255
  createCanvas(640, 360)
  pg = createGraphics(200,200)
  pg.fill(255)
  pg.ellipse(25,25,50,50)
  
}

function draw() {
  background(200)
  life = (life >= 0) ? life -= 1 : 255
  fill(life)
  rect(20,20,40,40)
  tint(255, life)
  image(pg, 100, 100) // no alpha change
  image(img, 100, 200) // ...but it works here?
}