Skip to Content
Game Programming Using Qt Beginner's Guide
book

Game Programming Using Qt Beginner's Guide

by Witold Wysota, Lorenz Haas
January 2016
Beginner
512 pages
12h 35m
English
Packt Publishing
Content preview from Game Programming Using Qt Beginner's Guide

Time for action – drawing a heartbeat

We will extend our component now and implement its main functionality–drawing a heartbeat-like diagram.

Add the following property declarations to canvas:

property int lineWidth: 2
property var points: []
property real arg: -Math.PI

Below, add a declaration for a timer that will drive the whole component:

Timer {
  interval: 10
  repeat: true
  running: true
  onTriggered: {
    arg += Math.PI/180
    while(arg >= Math.PI) arg -= 2*Math.PI
  }
}

Then, define the handler for when the value of arg is modified:

onArgChanged: {
  points.push(func(arg))
  points = points.slice(-canvas.width)
  canvas.requestPaint()
}

Then, implement func:

function func(argument) { var a=(2*Math.PI/10); var b=4*Math.PI/5 return Math.sin(20*argument) * ( Math.exp(-Math.pow(argument/a, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Game Programming using Qt 5 Beginner's Guide - Second Edition

Game Programming using Qt 5 Beginner's Guide - Second Edition

Pavel Strakhov, Witold Wysota, Lorenz Haas
Programming with Qt, 2nd Edition

Programming with Qt, 2nd Edition

Matthias Kalle Dalheimer

Publisher Resources

ISBN: 9781782168874Supplemental Content